diff options
Diffstat (limited to '')
-rw-r--r-- | flake.lock | 17 | ||||
-rw-r--r-- | flake.nix | 8 | ||||
-rw-r--r-- | flake/default.nix | 5 | ||||
-rw-r--r-- | flake/nixosConfigurations/default.nix | 2 | ||||
-rw-r--r-- | lib/by-name-overlay.nix | 76 | ||||
-rw-r--r-- | lib/default.nix | 42 | ||||
-rw-r--r-- | modules/default.nix | 4 | ||||
-rw-r--r-- | pkgs/default.nix | 4 | ||||
-rw-r--r-- | tests/default.nix | 3 |
9 files changed, 33 insertions, 128 deletions
diff --git a/flake.lock b/flake.lock index d81a2dc4..bac9eb78 100644 --- a/flake.lock +++ b/flake.lock @@ -362,6 +362,22 @@ "type": "github" } }, + "library": { + "locked": { + "lastModified": 1734626644, + "narHash": "sha256-p/RVC4Rp5AGN3qwlVoQJHkbEkvcilSr2lWfRgnlRXlQ=", + "ref": "prime", + "rev": "1021c1ffe1dd8dd75380dac618b93ff2cefd81f4", + "revCount": 1, + "type": "git", + "url": "https://git.vhack.eu/vhack.eu/nix-library" + }, + "original": { + "ref": "prime", + "type": "git", + "url": "https://git.vhack.eu/vhack.eu/nix-library" + } + }, "nix-darwin": { "inputs": { "nixpkgs": [ @@ -733,6 +749,7 @@ "home-manager": "home-manager", "impermanence": "impermanence", "lanzaboote": "lanzaboote", + "library": "library", "nix-darwin": "nix-darwin", "nix-index-database": "nix-index-database", "nixVim": "nixVim", diff --git a/flake.nix b/flake.nix index 80f8bc35..b748e0aa 100644 --- a/flake.nix +++ b/flake.nix @@ -14,6 +14,10 @@ nixpkgs-tfc.url = "github:soispha/nixpkgs/add-termfilechooser"; nixpkgs-onlykey.url = "github:soispha/nixpkgs/fix-onlykey-agent"; + library = { + url = "git+https://git.vhack.eu/vhack.eu/nix-library?ref=prime"; + }; + # inputs for following nix-darwin = { url = "github:lnl7/nix-darwin"; @@ -192,6 +196,7 @@ }; }; lanzaboote = { + # TODO: Subscribe to their update feed. <2024-12-18> url = "github:nix-community/lanzaboote/v0.4.1"; inputs = { nixpkgs.follows = "nixpkgs-stable"; @@ -262,6 +267,7 @@ nixpkgs-stable, nixpkgs-tfc, nixpkgs-onlykey, + library, # modules home-manager, nixos-generators, @@ -285,7 +291,7 @@ system = "x86_64-linux"; sysLib = shell_library.lib.${system}; - nixLib = import ./lib {}; + inherit (library) nixLib; pkgsStable = nixpkgs-stable.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system}; diff --git a/flake/default.nix b/flake/default.nix index 16ae52c6..2c8d6f6b 100644 --- a/flake/default.nix +++ b/flake/default.nix @@ -41,6 +41,7 @@ # my things shell_library sysLib + nixLib templates # modules home-manager @@ -61,7 +62,7 @@ }; tests = import ../tests { - inherit pkgs nixpkgs_as_input myPkgs sysLib; + inherit pkgs nixpkgs_as_input myPkgs sysLib nixLib; inherit (pkgs) lib; extraModules = { termfilechooser = "${nixpkgs_open_prs.nixpkgs-tfc}/nixos/modules/config/xdg/portals/termfilechooser.nix"; @@ -80,7 +81,7 @@ in { inherit nixosConfigurations; checks."${system}" = - nixLib.maybeMerge { + nixLib.warnMerge { inherit (self.packages."${system}") nvim diff --git a/flake/nixosConfigurations/default.nix b/flake/nixosConfigurations/default.nix index d51e57a5..7d98f868 100644 --- a/flake/nixosConfigurations/default.nix +++ b/flake/nixosConfigurations/default.nix @@ -8,6 +8,7 @@ # my things shell_library, sysLib, + nixLib, templates, # modules home-manager, @@ -47,6 +48,7 @@ myPkgs shell_library sysLib + nixLib # extra information system # modules diff --git a/lib/by-name-overlay.nix b/lib/by-name-overlay.nix deleted file mode 100644 index 4d700a8f..00000000 --- a/lib/by-name-overlay.nix +++ /dev/null @@ -1,76 +0,0 @@ -{warn}: -# Adapted from this: https://github.com/NixOS/nixpkgs/blob/1814b56453c91192f6d5a6276079948f9fe96c18/pkgs/top-level/by-name-overlay.nix -# This file should not depend on `pkgs` and thus not use `lib`. -{ - baseDirectory, - fileName, - finalizeFunction, - coImportsNameFunction ? null, - coImportsWarnMessageObject ? null, -}: let - # Takes a list of attrs as input and returns one merged attr set. - flattenAttrs = list: - if builtins.isList list - then - builtins.foldl' (acc: elem: - if builtins.isList elem - # Merging them with `//` is okay here, as we can be sure that the attr names are - # unique (they were separate dictionary after all) - then acc // (flattenAttrs elem) - else acc // elem) {} - list - else list; - - # From nixpkgs/lib {{{ - # These functions are taken straight out of the `nixpkgs/lib`. - # We can't depended on `pkgs` (and thus on `lib`), because the `pkgs` module argument - # is only defined in the `nixpkgs` module (which is imported through this function). - mapAttrsToList = f: attrs: - builtins.map (name: f name attrs.${name}) (builtins.attrNames attrs); - - nameValuePair = name: value: {inherit name value;}; - filterAttrs = pred: set: - builtins.listToAttrs (builtins.concatMap (name: let - v = set.${name}; - in - if pred name v - then [(nameValuePair name v)] - else []) (builtins.attrNames set)); - # }}} - - # Module files for a single shard - # Type: String -> String -> ListOf Path - namesForShard = shard: type: - if type != "directory" - then warn "Ignored non-directory, whilst importing by-name directory (${fileName}): '${shard}'" {} - else let - mkPath = name: _type: let - path = baseDirectory + "/${shard}/${name}" + "/${fileName}"; - coImportPath = - if coImportsNameFunction != null - then - coImportsNameFunction - {inherit shard name;} - else path; - in - if builtins.pathExists path - then - if builtins.pathExists coImportPath - then path - else warn "'${builtins.toString coImportPath}' does not exist. Should include ${coImportsWarnMessageObject} for '${shard}/${name}'" path - else warn "'${builtins.toString path}' does not exist. Skipped" null; - in - filterAttrs (name: value: value != null) - (builtins.mapAttrs - mkPath - (builtins.readDir (baseDirectory + "/${shard}"))); - - # A list of all module paths. - # These can the be simply injected into `import` - files = flattenAttrs (mapAttrsToList namesForShard (builtins.readDir baseDirectory)); - output = - builtins.mapAttrs - finalizeFunction - files; -in - output diff --git a/lib/default.nix b/lib/default.nix deleted file mode 100644 index dfa9fb17..00000000 --- a/lib/default.nix +++ /dev/null @@ -1,42 +0,0 @@ -{}: let - # string -> string -> string - colorize = color: string: "[${color}m${string}[0m"; - - # Taken from `nixpkgs/lib`. - # Is here to avoid a dependency on `lib` (making this file easy to test with `nix eval`) - warn = - # Since Nix 2.23, https://github.com/NixOS/nix/pull/10592 - builtins.warn - or ( - # Do not eta reduce v, so that we have the same strictness as `builtins.warn`. - msg: v: - # `builtins.warn` requires a string message, so we enforce that in our implementation, so that callers aren't accidentally incompatible with newer Nix versions. - assert builtins.isString msg; - builtins.trace "${colorize "1;35" "evaluation warning:"} ${msg}" v - ); -in { - mkByName = import ./by-name-overlay.nix {inherit warn;}; - - # Only merge two attrsets if the RHS does not share names with the LHS. - # # Example: - # ```nix - # let - # attr1 = {atuin = "first"; default = "second";}; - # attr2 = {atuin = "hi"; other = "hi2";}; - # in - # maybeMerge attr1 attr2 "Failed to merge" - # ``` - # # Type: - # {} -> {} -> string -> {} - maybeMerge = 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 - warn "Attributes overridden while merging ${sourceSet}: ${mkWarning overridden}" - merged - else merged; -} diff --git a/modules/default.nix b/modules/default.nix index 17780e63..1df511a1 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,8 +1,6 @@ # NOTE: This file **must** not depend on `pkgs`. This is because `pkgs` is defined in a # module imported by it, and thus would require infinite recursion. <2024-10-18> -{...}: let - nixLib = import ../lib {}; - +{nixLib, ...}: let files = builtins.attrValues (nixLib.mkByName { diff --git a/pkgs/default.nix b/pkgs/default.nix index 3ed326ac..1f0a25cc 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -9,8 +9,8 @@ mMM = maybeMergeMessage; callPackage = lib.callPackageWith - (nixLib.maybeMerge - (nixLib.maybeMerge + (nixLib.warnMerge + (nixLib.warnMerge pkgs myPkgs mMM) diff --git a/tests/default.nix b/tests/default.nix index 24b6fa65..c36a5906 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -1,13 +1,12 @@ { lib, + nixLib, pkgs, myPkgs, nixpkgs_as_input, sysLib, extraModules, }: let - nixLib = import ../lib {}; - mkTest = import ./infrastructure { inherit pkgs |