diff --git a/hive.nix b/hive.nix index b23b83f..0332ca9 100644 --- a/hive.nix +++ b/hive.nix @@ -11,17 +11,9 @@ let sources = import ./sources.nix; - inherit (sources) bootstrapNixpkgs; + lib = sources.fullLib; - lib = bootstrapNixpkgs.lib.extend (_: _: { - extra = import ./lib/nix-lib; - }); - - nix-lib = lib.extra; # TODO: Assess perf penalty of fixed point - # TODO same but using bootstrapnixpkgs for nix-lib instanciation - # original statement: import ./lib/nix-lib; - - inherit (nix-lib) mapSingleFuse; + inherit (lib.extra) mapSingleFuse; ### Let's build meta metadata = (import ./meta) lib; @@ -46,7 +38,6 @@ let }; }; - # Build up the arguments to instantiate a nixpkgs given a system and a version. mkNixpkgsConfig = system: @@ -58,13 +49,12 @@ let .${system} or (throw "Unknown system: ${system} for nixpkgs configuration instantiation"); # Instanciates the required nixpkgs version - mkSystemNixpkgs = system: version: - import sources."nixos-${version}" (mkNixpkgsConfig system version); + mkSystemNixpkgs = + system: version: import sources."nixos-${version}" (mkNixpkgsConfig system version); # All supported nixpkgs versions × systems, instanciated nixpkgs = mapSingleFuse (s: mapSingleFuse (mkSystemNixpkgs s) nixpkgs'.versions) nixpkgs'.systems; - # Get the configured nixos version for the node, # defaulting to the one defined in meta/nixpkgs version = node: metadata.nodes.${node}.nixpkgs.version; @@ -74,12 +64,10 @@ let nodePkgs = node: nixpkgs.${system node}.${version node}; ########## - # Function to create arguments based on the node + # Function to create arguments based on the node # mkArgs = node: rec { - lib = sourcePkgs.lib // { - extra = nix-lib; - }; + lib = sourcePkgs.lib.extend sources.libOverlay; sourcePkgs = nodePkgs node; meta = metadata; diff --git a/keys.nix b/keys.nix index 7945d52..09779b4 100644 --- a/keys.nix +++ b/keys.nix @@ -3,11 +3,11 @@ # SPDX-License-Identifier: EUPL-1.2 let - _sources = import ../npins; + sources = import ./sources.nix; - inherit (import _sources.nixpkgs { }) lib; + lib = sources.fullLib; meta = (import ../meta lib).config; in - import ./lib/keys { inherit meta lib; } +import ./lib/keys { inherit meta lib; } diff --git a/lib/keys/default.nix b/lib/keys/default.nix index 1ecdb23..4d845a8 100644 --- a/lib/keys/default.nix +++ b/lib/keys/default.nix @@ -6,7 +6,7 @@ { meta, lib }: let - inherit (import ../nix-lib) setDefault unique; + inherit (lib.extra) setDefault unique; getAttr = lib.flip builtins.getAttr; in diff --git a/lib/nix-lib/default.nix b/lib/nix-lib/default.nix index be73b69..94f8c18 100644 --- a/lib/nix-lib/default.nix +++ b/lib/nix-lib/default.nix @@ -2,17 +2,13 @@ # SPDX-FileCopyrightText: 2024 Tom Hubrecht # # SPDX-License-Identifier: EUPL-1.2 - -let - # Reimplement optional functions - _optional = - default: b: value: - if b then value else default; -in +{ lib }: rec { - inherit (import ./nixpkgs.nix) + inherit (lib) flip + optionals + optionalString hasPrefix recursiveUpdate splitString @@ -112,11 +108,8 @@ rec { subAttrs = attrs: builtins.map (subAttr attrs); - optionalList = _optional [ ]; + optionalList = optionals; - optionalAttrs = _optional { }; - - optionalString = _optional ""; /* Same as fuseAttrs but using `lib.recursiveUpdate` to merge attribute sets together. diff --git a/meta/verify.nix b/meta/verify.nix index be168d8..20205c0 100644 --- a/meta/verify.nix +++ b/meta/verify.nix @@ -32,9 +32,7 @@ in import ./dns.nix { inherit dns; - lib = pkgs.lib // { - extra = import ../lib/nix-lib; - }; + lib = sources.fullLib; } ) ); diff --git a/sources.nix b/sources.nix index 1ea96f7..82bca84 100644 --- a/sources.nix +++ b/sources.nix @@ -5,19 +5,34 @@ # SPDX-License-Identifier: EUPL-1.2 let - sources' = import ./npins; + rawSources = import ./npins; - bootstrapNixpkgs = import sources'.nixos-unstable { }; + bootstrapNixpkgs = import rawSources.nixos-unstable { }; patch = (import ./lib/nix-patches { patchFile = ./patches; }).base { pkgs = bootstrapNixpkgs; }; - sources = builtins.mapAttrs ( + patchedSources = builtins.mapAttrs ( k: src: patch.applyPatches { inherit src; name = k; } - ) sources'; -in sources // { bootstrapNixpkgs = bootstrapNixpkgs; unpatchedSources = sources; } + ) rawSources; + + libOverlay = final: _: { + extra = import ./lib/nix-lib { lib = final; }; + }; +in +patchedSources +// { + + inherit + bootstrapNixpkgs + libOverlay + rawSources + ; + + fullLib = bootstrapNixpkgs.lib.extend libOverlay; +}