summaryrefslogtreecommitdiffstats
path: root/default.nix
blob: 26e93c363a1c0b07e9ea75685dc0402d80ae3ee8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# nixLib - A library of nix functions for vhack.eu
#
# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
# SPDX-License-Identifier: LGPL-3.0-or-later
#
# This file is part of vhack.eu's nix library.
#
# You should have received a copy of the License along with this program.
# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
{lib}: let
  # string -> string -> string
  colorize = color: string: "[${color}m${string}";
in {
  /**
    Converts a `by-name` structured directory into.
  *
  */
  mkByName = import ./by-name.nix;

  # Warn while merging two attrsets if the RHS shares names with the LHS.
  #
  # # Example:
  # ```nix
  # let
  # attr1 = {atuin = "first"; default = "second";};
  # attr2 = {atuin = "hi"; other = "hi2";};
  # in
  # warnMerge attr1 attr2 "attr1 core value set"
  # ```
  #
  # # Type:
  # {} -> {} -> string -> {}
  warnMerge = lhs: rhs: sourceSet: let
    overridden = builtins.intersectAttrs lhs rhs;
    merged = lhs // rhs;
    mkWarning = overriddenAttrs:
      builtins.concatStringsSep " " (builtins.map (colorize "1;97") (builtins.attrNames overriddenAttrs));
  in
    if overridden != {}
    then
      builtins.warn "Attributes overridden while merging ${sourceSet}: ${mkWarning overridden}"
      merged
    else merged;

  math = import ./math.nix {inherit lib;};
  options = import ./options.nix {inherit lib;};
}