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;
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;

View file

@ -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; }

View file

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

View file

@ -2,17 +2,13 @@
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
#
# 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.

View file

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

View file

@ -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;
}