update to new lib format
This commit is contained in:
parent
496348b8af
commit
197d792946
@ -79,7 +79,7 @@
|
|||||||
"utils": "utils_2"
|
"utils": "utils_2"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"narHash": "sha256-oTiKYoR210VwjomzfSn/pCJ3immdUDRUPbYTDGaPFn8=",
|
"narHash": "sha256-9JsKDtgLSmAkcaKRD4Ycttip1jpO9dVVaRwclWH0V8E=",
|
||||||
"path": "./lib",
|
"path": "./lib",
|
||||||
"type": "path"
|
"type": "path"
|
||||||
},
|
},
|
||||||
|
@ -12,43 +12,8 @@ rec {
|
|||||||
# Generate an attribute set by mapping a function over a list of values.
|
# Generate an attribute set by mapping a function over a list of values.
|
||||||
genAttrs' = values: f: lib.listToAttrs (map f values);
|
genAttrs' = values: f: lib.listToAttrs (map f values);
|
||||||
|
|
||||||
# Convert a list of file paths to attribute set where
|
|
||||||
# the key is the folder or filename stripped of nix
|
|
||||||
# extension and imported content of the file as value.
|
|
||||||
#
|
|
||||||
pathsToImportedAttrs = paths:
|
|
||||||
let
|
|
||||||
paths' = lib.filter
|
|
||||||
(path: lib.hasSuffix ".nix" path
|
|
||||||
|| lib.pathExists "${path}/default.nix")
|
|
||||||
paths;
|
|
||||||
in
|
|
||||||
genAttrs' paths' (path: {
|
|
||||||
name = lib.removeSuffix ".nix"
|
|
||||||
# Safe as long this is just used as a name
|
|
||||||
(builtins.unsafeDiscardStringContext (baseNameOf path));
|
|
||||||
value = import path;
|
|
||||||
});
|
|
||||||
|
|
||||||
importHosts = dir:
|
|
||||||
lib.os.recImport {
|
|
||||||
inherit dir;
|
|
||||||
_import = base: {
|
|
||||||
modules = import "${toString dir}/${base}.nix";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
concatAttrs = lib.fold (attr: sum: lib.recursiveUpdate sum attr) { };
|
concatAttrs = lib.fold (attr: sum: lib.recursiveUpdate sum attr) { };
|
||||||
|
|
||||||
# Filter out packages that support given system and follow flake check requirements
|
|
||||||
filterPackages = system: packages:
|
|
||||||
let
|
|
||||||
# Everything that nix flake check requires for the packages output
|
|
||||||
filter = (n: v: with v; let platforms = meta.hydraPlatforms or meta.platforms or [ ]; in
|
|
||||||
lib.isDerivation v && !meta.broken && builtins.elem system platforms);
|
|
||||||
in
|
|
||||||
lib.filterAttrs filter packages;
|
|
||||||
|
|
||||||
safeReadDir = path:
|
safeReadDir = path:
|
||||||
lib.optionalAttrs (builtins.pathExists (toString path)) (builtins.readDir (toString path));
|
lib.optionalAttrs (builtins.pathExists (toString path)) (builtins.readDir (toString path));
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,17 @@
|
|||||||
collectProfiles = set:
|
collectProfiles = set:
|
||||||
let
|
let
|
||||||
collectNestedProfiles = set:
|
collectNestedProfiles = set:
|
||||||
lib.mapAttrsToList (n: v:
|
lib.mapAttrsToList
|
||||||
|
(n: v:
|
||||||
if builtins.isAttrs v then
|
if builtins.isAttrs v then
|
||||||
[ v.default or null ] ++ collectNestedProfiles v
|
[ v.default or null ] ++ collectNestedProfiles v
|
||||||
else null
|
else null
|
||||||
) set;
|
)
|
||||||
|
set;
|
||||||
in
|
in
|
||||||
builtins.filter (x: x != null) (lib.flatten (collectNestedProfiles set));
|
builtins.filter (x: x != null) (lib.flatten (collectNestedProfiles set));
|
||||||
|
|
||||||
pathsIn = dir:
|
profileMap = list: map (profile: profile.default) (lib.flatten list);
|
||||||
let
|
|
||||||
fullPath = name: "${toString dir}/${name}";
|
|
||||||
in
|
|
||||||
map fullPath (lib.attrNames (lib.safeReadDir dir));
|
|
||||||
|
|
||||||
unifyOverlays = channels: map (o: if builtins.isFunction (o null null) then o channels else o);
|
unifyOverlays = channels: map (o: if builtins.isFunction (o null null) then o channels else o);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
{ lib, deploy }:
|
{ lib, deploy }:
|
||||||
let
|
let
|
||||||
inherit (lib) os;
|
|
||||||
inherit (builtins) mapAttrs attrNames attrValues head isFunction;
|
inherit (builtins) mapAttrs attrNames attrValues head isFunction;
|
||||||
in
|
in
|
||||||
|
|
||||||
@ -73,9 +72,9 @@ lib.systemFlake (lib.mergeAny
|
|||||||
nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules;
|
nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules;
|
||||||
|
|
||||||
homeModules = lib.exporter.modulesFromList cfg.home.modules;
|
homeModules = lib.exporter.modulesFromList cfg.home.modules;
|
||||||
homeConfigurations = os.mkHomeConfigurations self.nixosConfigurations;
|
homeConfigurations = lib.mkHomeConfigurations self.nixosConfigurations;
|
||||||
|
|
||||||
deploy.nodes = os.mkNodes deploy self.nixosConfigurations;
|
deploy.nodes = lib.mkDeployNodes deploy self.nixosConfigurations;
|
||||||
|
|
||||||
overlays = lib.exporter.overlaysFromChannelsExporter {
|
overlays = lib.exporter.overlaysFromChannelsExporter {
|
||||||
# since we can't detect overlays owned by self
|
# since we can't detect overlays owned by self
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
let
|
let
|
||||||
argOpts = with lib; { config, ... }:
|
argOpts = with lib; { config, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) os;
|
|
||||||
|
|
||||||
cfg = config;
|
cfg = config;
|
||||||
inherit (config) self;
|
inherit (config) self;
|
||||||
|
|
||||||
@ -188,7 +186,7 @@ let
|
|||||||
suites = mkOption {
|
suites = mkOption {
|
||||||
type = pathTo (functionTo attrs);
|
type = pathTo (functionTo attrs);
|
||||||
default = _: { };
|
default = _: { };
|
||||||
apply = suites: os.mkSuites {
|
apply = suites: lib.mkSuites {
|
||||||
inherit suites;
|
inherit suites;
|
||||||
inherit (config) profiles;
|
inherit (config) profiles;
|
||||||
};
|
};
|
||||||
|
@ -37,25 +37,6 @@ lib.runTests {
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
testPathsToImportedAttrs = {
|
|
||||||
expr =
|
|
||||||
pathsToImportedAttrs [
|
|
||||||
(toString ./testPathsToImportedAttrs/dir)
|
|
||||||
./testPathsToImportedAttrs/foo.nix
|
|
||||||
./testPathsToImportedAttrs/bar.nix
|
|
||||||
./testPathsToImportedAttrs/t.nix
|
|
||||||
./testPathsToImportedAttrs/f.nix
|
|
||||||
];
|
|
||||||
|
|
||||||
expected = {
|
|
||||||
dir = { a = 5; };
|
|
||||||
foo = { bar = 1; };
|
|
||||||
bar = { foo = 2; };
|
|
||||||
t = true;
|
|
||||||
f = false;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
testRgxToString = lib.testAllTrue [
|
testRgxToString = lib.testAllTrue [
|
||||||
(rgxToString ".+x" "vxk" == "vx")
|
(rgxToString ".+x" "vxk" == "vx")
|
||||||
(rgxToString "^fo" "foo" == "fo")
|
(rgxToString "^fo" "foo" == "fo")
|
||||||
@ -72,7 +53,7 @@ lib.runTests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
testSuites = {
|
testSuites = {
|
||||||
expr = os.mkSuites {
|
expr = mkSuites {
|
||||||
suites = { profiles, ... }: with profiles; {
|
suites = { profiles, ... }: with profiles; {
|
||||||
bar = [ foo ];
|
bar = [ foo ];
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user