chore(lib): Clean instanciation

This commit is contained in:
sinavir 2025-01-09 14:52:51 +01:00 committed by Tom Hubrecht
parent e0759140cc
commit 00c70ce869
Signed by: thubrecht
SSH key fingerprint: SHA256:CYNvFo44Ar9qCNnWNnvJVhs0QXO9AZjOLlPeWcSij3Q
6 changed files with 36 additions and 42 deletions

View file

@ -11,17 +11,9 @@ let
sources = import ./sources.nix; sources = import ./sources.nix;
inherit (sources) bootstrapNixpkgs; lib = sources.fullLib;
lib = bootstrapNixpkgs.lib.extend (_: _: { inherit (lib.extra) mapSingleFuse;
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;
### Let's build meta ### Let's build meta
metadata = (import ./meta) lib; metadata = (import ./meta) lib;
@ -46,7 +38,6 @@ let
}; };
}; };
# Build up the arguments to instantiate a nixpkgs given a system and a version. # Build up the arguments to instantiate a nixpkgs given a system and a version.
mkNixpkgsConfig = mkNixpkgsConfig =
system: system:
@ -58,13 +49,12 @@ let
.${system} or (throw "Unknown system: ${system} for nixpkgs configuration instantiation"); .${system} or (throw "Unknown system: ${system} for nixpkgs configuration instantiation");
# Instanciates the required nixpkgs version # Instanciates the required nixpkgs version
mkSystemNixpkgs = system: version: mkSystemNixpkgs =
import sources."nixos-${version}" (mkNixpkgsConfig system version); system: version: import sources."nixos-${version}" (mkNixpkgsConfig system version);
# All supported nixpkgs versions × systems, instanciated # All supported nixpkgs versions × systems, instanciated
nixpkgs = mapSingleFuse (s: mapSingleFuse (mkSystemNixpkgs s) nixpkgs'.versions) nixpkgs'.systems; nixpkgs = mapSingleFuse (s: mapSingleFuse (mkSystemNixpkgs s) nixpkgs'.versions) nixpkgs'.systems;
# Get the configured nixos version for the node, # Get the configured nixos version for the node,
# defaulting to the one defined in meta/nixpkgs # defaulting to the one defined in meta/nixpkgs
version = node: metadata.nodes.${node}.nixpkgs.version; version = node: metadata.nodes.${node}.nixpkgs.version;
@ -74,12 +64,10 @@ let
nodePkgs = node: nixpkgs.${system node}.${version node}; 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 { mkArgs = node: rec {
lib = sourcePkgs.lib // { lib = sourcePkgs.lib.extend sources.libOverlay;
extra = nix-lib;
};
sourcePkgs = nodePkgs node; sourcePkgs = nodePkgs node;
meta = metadata; meta = metadata;

View file

@ -3,11 +3,11 @@
# SPDX-License-Identifier: EUPL-1.2 # SPDX-License-Identifier: EUPL-1.2
let let
_sources = import ../npins; sources = import ./sources.nix;
inherit (import _sources.nixpkgs { }) lib; lib = sources.fullLib;
meta = (import ../meta lib).config; meta = (import ../meta lib).config;
in in
import ./lib/keys { inherit meta lib; } import ./lib/keys { inherit meta lib; }

View file

@ -6,7 +6,7 @@
{ meta, lib }: { meta, lib }:
let let
inherit (import ../nix-lib) setDefault unique; inherit (lib.extra) setDefault unique;
getAttr = lib.flip builtins.getAttr; getAttr = lib.flip builtins.getAttr;
in in

View file

@ -2,17 +2,13 @@
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu> # SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
# #
# SPDX-License-Identifier: EUPL-1.2 # SPDX-License-Identifier: EUPL-1.2
{ lib }:
let
# Reimplement optional functions
_optional =
default: b: value:
if b then value else default;
in
rec { rec {
inherit (import ./nixpkgs.nix) inherit (lib)
flip flip
optionals
optionalString
hasPrefix hasPrefix
recursiveUpdate recursiveUpdate
splitString splitString
@ -112,11 +108,8 @@ rec {
subAttrs = attrs: builtins.map (subAttr attrs); subAttrs = attrs: builtins.map (subAttr attrs);
optionalList = _optional [ ]; optionalList = optionals;
optionalAttrs = _optional { };
optionalString = _optional "";
/* /*
Same as fuseAttrs but using `lib.recursiveUpdate` to merge attribute Same as fuseAttrs but using `lib.recursiveUpdate` to merge attribute
sets together. sets together.

View file

@ -32,9 +32,7 @@ in
import ./dns.nix { import ./dns.nix {
inherit dns; inherit dns;
lib = pkgs.lib // { lib = sources.fullLib;
extra = import ../lib/nix-lib;
};
} }
) )
); );

View file

@ -5,19 +5,34 @@
# SPDX-License-Identifier: EUPL-1.2 # SPDX-License-Identifier: EUPL-1.2
let 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 { patch = (import ./lib/nix-patches { patchFile = ./patches; }).base {
pkgs = bootstrapNixpkgs; pkgs = bootstrapNixpkgs;
}; };
sources = builtins.mapAttrs ( patchedSources = builtins.mapAttrs (
k: src: k: src:
patch.applyPatches { patch.applyPatches {
inherit src; inherit src;
name = k; name = k;
} }
) sources'; ) rawSources;
in sources // { bootstrapNixpkgs = bootstrapNixpkgs; unpatchedSources = sources; }
libOverlay = final: _: {
extra = import ./lib/nix-lib { lib = final; };
};
in
patchedSources
// {
inherit
bootstrapNixpkgs
libOverlay
rawSources
;
fullLib = bootstrapNixpkgs.lib.extend libOverlay;
}