From b7bcaea497ed24c0e26266f3d1b1cdf32d1c8bd1 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 11 Apr 2021 20:01:13 -0700 Subject: [PATCH 01/21] Update evalArgs to match the new planned api --- lib/mkFlake/evalArgs.nix | 311 ++++++++++++++++++++++++--------------- 1 file changed, 195 insertions(+), 116 deletions(-) diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 29d04bc6..e6f055ed 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,150 +1,229 @@ -{ self, dev, nixos, inputs, ... }: +{ self, dev, nixos, inputs, utils, ... }: { args }: let - argOpts = with nixos.lib; { config, options, ... }: + argOpts = with nixos.lib; { config, ... }: let inherit (dev) os; inherit (config) self; - inputAttrs = with types; functionTo attrs; + maybeImport = obj: + if (builtins.typeOf obj == "path") || (builtins.typeOf obj == "string") then + import obj + else + obj; + + /* Custom types needed for arguments */ + moduleType = with types; anything // { inherit (submodule { }) check; description = "valid module"; }; + overlayType = types.anything // { + check = builtins.isFunction; + description = "valid Nixpkgs overlay"; + }; + systemType = types.enum (builtins.attrValues config.supportedSystems); + flakeType = with types; (addCheck attrs nixos.lib.isStorePath) // { + description = "nix flake"; + }; + + # Applys maybeImport during merge and before check + # To simplify apply keys and improve type checking + pathTo = elemType: mkOptionType { + name = "pathTo"; + description = "path that evaluates to a(n) ${elemType.name}"; + check = x: elemType.check (maybeImport x); + merge = loc: defs: + (mergeDefinitions loc elemType (map + (x: { + inherit (x) file; + value = maybeImport x.value; + }) + defs)).mergedValue; + getSubOptions = elemType.getSubOptions; + getSubModules = elemType.getSubModules; + substSubModules = m: pathTo (elemType.substSubModules m); + }; + + + /* Submodules needed for API containers */ + + channelsModule = { + options = with types; { + input = mkOption { + type = flakeType; + default = inputs.nixos; + description = '' + nixpkgs flake input to use for this channel + ''; + }; + overlays = mkOption { + type = pathTo (listOf overlayType); + default = [ ]; + description = '' + overlays to apply to this channel + these will get exported under the 'overlays' flake output as / + ''; + }; + externalOverlays = mkOption { + type = pathTo (listOf overlayType); + default = [ ]; + description = '' + overlays to apply to the channel that don't get exported to the flake output + useful to include overlays from inputs + ''; + }; + config = mkOption { + type = pathTo attrs; + default = { }; + description = '' + nixpkgs config for this channel + ''; + }; + }; + }; + + configModule = { name, ... }: { + options = with types; { + system = mkOption { + type = systemType; + default = "x86_64-linux"; + description = '' + system for this config + ''; + }; + channelName = mkOption { + type = types.enum (builtins.attrValues self.channels); + default = "nixpkgs"; + description = '' + Channel this config should follow + ''; + }; + modules = mkOption { + type = pathTo moduleType; + default = [ ]; + description = '' + The configuration for this config + ''; + }; + externalmodules = mkOption { + type = pathTo moduleType; + default = [ ]; + description = '' + The configuration for this config + ''; + }; + }; + }; + + # Home-manager's configs get exported automatically from nixos.hosts + # So there is no need for a config options in the home namespace + # This is only needed for nixos + includeConfigsModule = { + options = with types; { + configDefaults = mkOption { + type = submodule configModule; + default = { }; + description = '' + defaults for all configs + ''; + }; + configs = mkOption { + type = pathTo (attrsOf (submodule configModule)); + default = { }; + description = '' + configurations to include in the ${name}Configurations output + ''; + }; + }; + }; + + # Options to import: modules, profiles, suites + importsModule = { name, ... }: { + options = with types; { + modules = mkOption { + type = pathTo (listOf moduleType); + default = [ ]; + apply = dev.pathsToImportedAttrs; + description = '' + list of modules to include in confgurations and export in '${name}Modules' output + ''; + }; + externalModules = mkOption { + type = pathTo (listOf moduleType); + default = [ ]; + apply = dev.pathsToImportedAttrs; + description = '' + list of modules to include in confguration but these are not exported to the '${name}Modules' output + ''; + }; + profiles = mkOption { + type = path; + default = "${self}/profiles"; + defaultText = "\${self}/profiles"; + apply = x: os.mkProfileAttrs (toString x); + description = "path to profiles folder that can be collected into suites"; + }; + suites = mkOption { + type = pathTo (functionTo attrs); + default = _: { }; + apply = suites: os.mkSuites { + inherit suites; + inherit (config) profiles; + }; + description = '' + Function with the input of 'profiles' that returns an attribute set + with the suites for this config system. + These can be accessed through the 'suites' special argument. + ''; + }; + }; + }; in { options = with types; { self = mkOption { - type = addCheck attrs nixos.lib.isStorePath; + type = flakeType; description = "The flake to create the devos outputs for"; }; - hosts = mkOption { - type = path; - default = "${self}/hosts"; - defaultText = "\${self}/hosts"; - apply = toString; + supportedSystems = mkOption { + type = listOf str; + default = utils.lib.defaultSystems; description = '' - Path to directory containing host configurations that will be exported - to the 'nixosConfigurations' output. + The systems supported by this flake ''; }; - packages = mkOption { - # functionTo changes arg names which breaks flake check - type = types.anything // { - check = builtins.isFunction; - description = "Nixpkgs overlay"; - }; - default = (final: prev: { }); - defaultText = "(final: prev: {})"; - description = '' - Overlay for custom packages that will be included in treewide 'pkgs'. - This should follow the standard nixpkgs overlay format - two argument function - that returns an attrset. - These packages will be exported to the 'packages' and 'legacyPackages' outputs. - ''; - }; - modules = mkOption { - type = listOf moduleType; - default = [ ]; - apply = dev.pathsToImportedAttrs; - description = '' - list of modules to include in confgurations and export in 'nixosModules' output - ''; - }; - userModules = mkOption { - type = listOf moduleType; - default = [ ]; - apply = dev.pathsToImportedAttrs; - description = '' - list of modules to include in home-manager configurations and export in - 'homeModules' output - ''; - }; - profiles = mkOption { - type = path; - default = "${self}/profiles"; - defaultText = "\${self}/profiles"; - apply = x: os.mkProfileAttrs (toString x); - description = "path to profiles folder that can be collected into suites"; - }; - userProfiles = mkOption { - type = path; - default = "${self}/users/profiles"; - defaultText = "\${self}/users/profiles"; - apply = x: os.mkProfileAttrs (toString x); - description = "path to user profiles folder that can be collected into userSuites"; - }; - suites = + channels = let - defaults = { user = { }; system = { }; }; - in - mkOption { - type = inputAttrs; - default = { ... }: defaults; - defaultText = "{ user = {}; system = {}; }"; - apply = suites: defaults // os.mkSuites { - inherit suites; - inherit (config) profiles users userProfiles; - }; - description = '' - Function with inputs 'users' and 'profiles' that returns attribute set - with user and system suites. The former for Home Manager and the latter - for nixos configurations. - These can be accessed through the 'suites' specialArg in each config system. - ''; - }; - users = mkOption { - type = path; - default = "${self}/users"; - defaultText = "\${self}/users"; - apply = x: os.mkProfileAttrs (toString x); - description = '' - path to folder containing profiles that define system users - ''; - }; - extern = - let - defaults = { - modules = [ ]; - overlays = [ ]; - specialArgs = { }; - userModules = [ ]; - userSpecialArgs = { }; + default = { + nixpkgs = { + input = inputs.nixos; + }; }; in mkOption { - type = inputAttrs; - default = { ... }: defaults; - defaultText = '' - { modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; } - ''; - # So unneeded extern attributes can safely be deleted - apply = x: defaults // (x { inputs = inputs // self.inputs; }); + type = attrsOf (submodule channelsModule); + inherit default; + apply = x: default // x; description = '' - Function with argument 'inputs' that contains all devos and ''${self}'s inputs. - The function should return an attribute set with modules, overlays, and - specialArgs to be included across nixos and home manager configurations. - Only attributes that are used should be returned. + nixpkgs channels to create ''; }; - overlays = mkOption { - type = path; - default = "${self}/overlays"; - defaultText = "\${self}/overlays"; - apply = x: dev.pathsToImportedAttrs (dev.pathsIn (toString x)); + nixos = mkOption { + type = submodule [ includeConfigsModule importsModule ]; + default = { }; description = '' - path to folder containing overlays which will be applied to pkgs and exported in - the 'overlays' output + hosts, modules, suites, and profiles for nixos ''; }; - overrides = mkOption rec { - type = attrs; - default = { modules = [ ]; disabledModules = [ ]; packages = _: _: _: { }; }; - defaultText = "{ modules = []; disabledModules = []; packages = {}; }"; - apply = x: default // x; - description = "attrset of packages and modules that will be pulled from nixpkgs master"; + home = mkOption { + type = submodule importsModule; + default = { }; + description = '' + hosts, modules, suites, and profiles for home-manager + ''; }; }; }; From 2b70cd3ae607d8c5d05b4266530be6011e94371b Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 11 Apr 2021 22:25:37 -0700 Subject: [PATCH 02/21] fix some small bugs in mkFlake/evalArgs --- lib/default.nix | 5 ++++- lib/mkFlake/default.nix | 5 ++--- lib/mkFlake/evalArgs.nix | 10 +++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index ee06a3c9..cf8d862c 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -17,7 +17,10 @@ lib.makeExtensible (final: lists = callLibs ./lists.nix; strings = callLibs ./strings.nix; - mkFlake = callLibs ./mkFlake; + mkFlake = { + __functor = callLibs ./mkFlake; + evalArgs = callLibs ./mkFlake/evalArgs.nix; + }; pkgs-lib = callLibs ./pkgs-lib; diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 700773f1..31f019f9 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -2,13 +2,12 @@ let inherit (dev) os; inherit (inputs) utils deploy; - evalFlakeArgs = dev.callLibs ./evalArgs.nix; in -{ self, ... } @ args: +_: { self, ... } @ args: let - cfg = (evalFlakeArgs { inherit args; }).config; + cfg = (dev.mkFlake.evalArgs { inherit args; }).config; multiPkgs = os.mkPkgs { inherit (cfg) extern overrides; }; diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index e6f055ed..d3681760 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -24,7 +24,7 @@ let check = builtins.isFunction; description = "valid Nixpkgs overlay"; }; - systemType = types.enum (builtins.attrValues config.supportedSystems); + systemType = types.enum config.supportedSystems; flakeType = with types; (addCheck attrs nixos.lib.isStorePath) // { description = "nix flake"; }; @@ -85,7 +85,7 @@ let }; }; - configModule = { name, ... }: { + configModule = { options = with types; { system = mkOption { type = systemType; @@ -95,7 +95,7 @@ let ''; }; channelName = mkOption { - type = types.enum (builtins.attrValues self.channels); + type = types.enum (builtins.attrValues config.channels); default = "nixpkgs"; description = '' Channel this config should follow @@ -108,7 +108,7 @@ let The configuration for this config ''; }; - externalmodules = mkOption { + externalModules = mkOption { type = pathTo moduleType; default = [ ]; description = '' @@ -121,7 +121,7 @@ let # Home-manager's configs get exported automatically from nixos.hosts # So there is no need for a config options in the home namespace # This is only needed for nixos - includeConfigsModule = { + includeConfigsModule = { name, ... }: { options = with types; { configDefaults = mkOption { type = submodule configModule; From 0db2bb041e8cfecbbec08010d150539f4e11963e Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 13 Apr 2021 11:24:10 -0700 Subject: [PATCH 03/21] add old evalArgs as evalOldArgs, so flake works --- lib/default.nix | 1 + lib/mkFlake/default.nix | 2 +- lib/mkFlake/evalOldArgs.nix | 154 ++++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 lib/mkFlake/evalOldArgs.nix diff --git a/lib/default.nix b/lib/default.nix index cf8d862c..4ed82a45 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -20,6 +20,7 @@ lib.makeExtensible (final: mkFlake = { __functor = callLibs ./mkFlake; evalArgs = callLibs ./mkFlake/evalArgs.nix; + evalOldArgs = callLibs ./mkFlake/evalOldArgs.nix; }; pkgs-lib = callLibs ./pkgs-lib; diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 31f019f9..4fd6947e 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -7,7 +7,7 @@ in _: { self, ... } @ args: let - cfg = (dev.mkFlake.evalArgs { inherit args; }).config; + cfg = (dev.mkFlake.evalOldArgs { inherit args; }).config; multiPkgs = os.mkPkgs { inherit (cfg) extern overrides; }; diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix new file mode 100644 index 00000000..29d04bc6 --- /dev/null +++ b/lib/mkFlake/evalOldArgs.nix @@ -0,0 +1,154 @@ +{ self, dev, nixos, inputs, ... }: + +{ args }: +let + argOpts = with nixos.lib; { config, options, ... }: + let + inherit (dev) os; + + inherit (config) self; + + inputAttrs = with types; functionTo attrs; + moduleType = with types; anything // { + inherit (submodule { }) check; + description = "valid module"; + }; + in + { + options = with types; { + self = mkOption { + type = addCheck attrs nixos.lib.isStorePath; + description = "The flake to create the devos outputs for"; + }; + hosts = mkOption { + type = path; + default = "${self}/hosts"; + defaultText = "\${self}/hosts"; + apply = toString; + description = '' + Path to directory containing host configurations that will be exported + to the 'nixosConfigurations' output. + ''; + }; + packages = mkOption { + # functionTo changes arg names which breaks flake check + type = types.anything // { + check = builtins.isFunction; + description = "Nixpkgs overlay"; + }; + default = (final: prev: { }); + defaultText = "(final: prev: {})"; + description = '' + Overlay for custom packages that will be included in treewide 'pkgs'. + This should follow the standard nixpkgs overlay format - two argument function + that returns an attrset. + These packages will be exported to the 'packages' and 'legacyPackages' outputs. + ''; + }; + modules = mkOption { + type = listOf moduleType; + default = [ ]; + apply = dev.pathsToImportedAttrs; + description = '' + list of modules to include in confgurations and export in 'nixosModules' output + ''; + }; + userModules = mkOption { + type = listOf moduleType; + default = [ ]; + apply = dev.pathsToImportedAttrs; + description = '' + list of modules to include in home-manager configurations and export in + 'homeModules' output + ''; + }; + profiles = mkOption { + type = path; + default = "${self}/profiles"; + defaultText = "\${self}/profiles"; + apply = x: os.mkProfileAttrs (toString x); + description = "path to profiles folder that can be collected into suites"; + }; + userProfiles = mkOption { + type = path; + default = "${self}/users/profiles"; + defaultText = "\${self}/users/profiles"; + apply = x: os.mkProfileAttrs (toString x); + description = "path to user profiles folder that can be collected into userSuites"; + }; + suites = + let + defaults = { user = { }; system = { }; }; + in + mkOption { + type = inputAttrs; + default = { ... }: defaults; + defaultText = "{ user = {}; system = {}; }"; + apply = suites: defaults // os.mkSuites { + inherit suites; + inherit (config) profiles users userProfiles; + }; + description = '' + Function with inputs 'users' and 'profiles' that returns attribute set + with user and system suites. The former for Home Manager and the latter + for nixos configurations. + These can be accessed through the 'suites' specialArg in each config system. + ''; + }; + users = mkOption { + type = path; + default = "${self}/users"; + defaultText = "\${self}/users"; + apply = x: os.mkProfileAttrs (toString x); + description = '' + path to folder containing profiles that define system users + ''; + }; + extern = + let + defaults = { + modules = [ ]; + overlays = [ ]; + specialArgs = { }; + userModules = [ ]; + userSpecialArgs = { }; + }; + in + mkOption { + type = inputAttrs; + default = { ... }: defaults; + defaultText = '' + { modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; } + ''; + # So unneeded extern attributes can safely be deleted + apply = x: defaults // (x { inputs = inputs // self.inputs; }); + description = '' + Function with argument 'inputs' that contains all devos and ''${self}'s inputs. + The function should return an attribute set with modules, overlays, and + specialArgs to be included across nixos and home manager configurations. + Only attributes that are used should be returned. + ''; + }; + overlays = mkOption { + type = path; + default = "${self}/overlays"; + defaultText = "\${self}/overlays"; + apply = x: dev.pathsToImportedAttrs (dev.pathsIn (toString x)); + description = '' + path to folder containing overlays which will be applied to pkgs and exported in + the 'overlays' output + ''; + }; + overrides = mkOption rec { + type = attrs; + default = { modules = [ ]; disabledModules = [ ]; packages = _: _: _: { }; }; + defaultText = "{ modules = []; disabledModules = []; packages = {}; }"; + apply = x: default // x; + description = "attrset of packages and modules that will be pulled from nixpkgs master"; + }; + }; + }; +in +nixos.lib.evalModules { + modules = [ argOpts args ]; +} From 863c17621c33f8d86aaf949c608155e7fc00e0f6 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sat, 17 Apr 2021 19:30:55 -0500 Subject: [PATCH 04/21] libtests: outfactor in preparation of lib/flake.nix --- lib/pkgs-lib/tests/default.nix | 35 +------ lib/tests/default.nix | 27 ++++++ lib/tests/lib.nix | 93 +++++++++++++++++++ .../tests/profiles/foo/default.nix | 0 .../tests/profiles/t/default.nix | 0 lib/{pkgs-lib => }/tests/testPathsIn/bar | 0 lib/{pkgs-lib => }/tests/testPathsIn/baz | 0 lib/{pkgs-lib => }/tests/testPathsIn/foo | 0 .../tests/testPathsToImportedAttrs/bar.nix | 0 .../testPathsToImportedAttrs/dir/default.nix | 0 .../tests/testPathsToImportedAttrs/f.nix | 0 .../tests/testPathsToImportedAttrs/foo.nix | 0 .../tests/testPathsToImportedAttrs/t.nix | 0 13 files changed, 123 insertions(+), 32 deletions(-) create mode 100644 lib/tests/default.nix create mode 100644 lib/tests/lib.nix rename lib/{pkgs-lib => }/tests/profiles/foo/default.nix (100%) rename lib/{pkgs-lib => }/tests/profiles/t/default.nix (100%) rename lib/{pkgs-lib => }/tests/testPathsIn/bar (100%) rename lib/{pkgs-lib => }/tests/testPathsIn/baz (100%) rename lib/{pkgs-lib => }/tests/testPathsIn/foo (100%) rename lib/{pkgs-lib => }/tests/testPathsToImportedAttrs/bar.nix (100%) rename lib/{pkgs-lib => }/tests/testPathsToImportedAttrs/dir/default.nix (100%) rename lib/{pkgs-lib => }/tests/testPathsToImportedAttrs/f.nix (100%) rename lib/{pkgs-lib => }/tests/testPathsToImportedAttrs/foo.nix (100%) rename lib/{pkgs-lib => }/tests/testPathsToImportedAttrs/t.nix (100%) diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index 3c284683..891baee9 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -1,4 +1,4 @@ -{ pkgs-lib, pkgs, system, inputs, nixos, lib, ... }: +{ pkgs, system, inputs, nixos, lib, ... }: let mkChecks = { hosts, nodes, homes ? { } }: let @@ -7,8 +7,7 @@ let nodes; deployChecks = inputs.deploy.lib.${system}.deployChecks { nodes = deployHosts; }; tests = - { libTests = libTests; } - // lib.optionalAttrs (deployHosts != { }) { + lib.optionalAttrs (deployHosts != { }) { profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))}); } // lib.mapAttrs (n: v: v.activationPackage) homes; @@ -51,33 +50,5 @@ let machine.systemctl("is-system-running --wait") ''; }; - - libTests = pkgs.runCommandNoCC "devos-lib-tests" - { - buildInputs = [ - pkgs.nix - ( - let tests = pkgs-lib.callLibs ./lib.nix; - in - if tests == [ ] - then null - else throw (builtins.toJSON tests) - ) - ]; - } '' - datadir="${pkgs.nix}/share" - export TEST_ROOT=$(pwd)/test-tmp - export NIX_BUILD_HOOK= - export NIX_CONF_DIR=$TEST_ROOT/etc - export NIX_LOCALSTATE_DIR=$TEST_ROOT/var - export NIX_LOG_DIR=$TEST_ROOT/var/log/nix - export NIX_STATE_DIR=$TEST_ROOT/var/nix - export NIX_STORE_DIR=$TEST_ROOT/store - export PAGER=cat - cacheDir=$TEST_ROOT/binary-cache - nix-store --init - - touch $out - ''; in -{ inherit mkTest libTests profilesTest mkChecks; } +{ inherit mkTest profilesTest mkChecks; } diff --git a/lib/tests/default.nix b/lib/tests/default.nix new file mode 100644 index 00000000..c13dd8a1 --- /dev/null +++ b/lib/tests/default.nix @@ -0,0 +1,27 @@ +{ pkgs, lib, dev, ... }: + +pkgs.runCommandNoCC "devos-lib-tests" + { + buildInputs = [ + pkgs.nix + ( + let tests = import ./lib.nix { inherit pkgs lib dev; }; in + if tests == [ ] then null + else throw (builtins.toJSON tests) + ) + ]; + } '' + datadir="${pkgs.nix}/share" + export TEST_ROOT=$(pwd)/test-tmp + export NIX_BUILD_HOOK= + export NIX_CONF_DIR=$TEST_ROOT/etc + export NIX_LOCALSTATE_DIR=$TEST_ROOT/var + export NIX_LOG_DIR=$TEST_ROOT/var/log/nix + export NIX_STATE_DIR=$TEST_ROOT/var/nix + export NIX_STORE_DIR=$TEST_ROOT/store + export PAGER=cat + cacheDir=$TEST_ROOT/binary-cache + nix-store --init + + touch $out + '' diff --git a/lib/tests/lib.nix b/lib/tests/lib.nix new file mode 100644 index 00000000..68baa9f5 --- /dev/null +++ b/lib/tests/lib.nix @@ -0,0 +1,93 @@ +{ pkgs, lib, dev, ... }: +with dev; +lib.runTests { + testConcatAttrs = { + expr = concatAttrs [{ foo = 1; } { bar = 2; } { baz = 3; }]; + + expected = { foo = 1; bar = 2; baz = 3; }; + }; + + testGenAttrs' = { + expr = genAttrs' + [ "/foo/bar" "/baz/buzz" ] + (path: { + name = baseNameOf path; + value = "${path}/fizz"; + }); + + expected = { bar = "/foo/bar/fizz"; buzz = "/baz/buzz/fizz"; }; + }; + + testMapFilterAttrs = { + expr = mapFilterAttrs + (n: v: n == "foobar" && v == 1) + (n: v: lib.nameValuePair ("${n}bar") (v + 1)) + { foo = 0; bar = 2; }; + + expected = { foobar = 1; }; + }; + + testPathsIn = { + expr = pathsIn (toString ./testPathsIn); + + expected = map toString [ + ./testPathsIn/bar + ./testPathsIn/baz + ./testPathsIn/foo + ]; + }; + + 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 [ + (rgxToString ".+x" "vxk" == "vx") + (rgxToString "^fo" "foo" == "fo") + (rgxToString "a?" "a" == "a") + (rgxToString "hat" "foohatbar" == "hat") + ]; + + testSafeReadDir = { + expr = safeReadDir ./profiles // safeReadDir ./nonexistentdir; + expected = { + foo = "directory"; + t = "directory"; + }; + }; + + testSuites = + let + profiles = os.mkProfileAttrs (toString ./profiles); + users = ""; + userProfiles = ""; + suites = { profiles, ... }: { + system.bar = [ profiles.foo ]; + }; + in + { + expr = os.mkSuites { inherit profiles users userProfiles suites; }; + expected = { + system = { + bar = [ profiles.foo.default ]; + allProfiles = [ profiles.foo.default profiles.t.default ]; + allUsers = [ ]; + }; + }; + }; +} diff --git a/lib/pkgs-lib/tests/profiles/foo/default.nix b/lib/tests/profiles/foo/default.nix similarity index 100% rename from lib/pkgs-lib/tests/profiles/foo/default.nix rename to lib/tests/profiles/foo/default.nix diff --git a/lib/pkgs-lib/tests/profiles/t/default.nix b/lib/tests/profiles/t/default.nix similarity index 100% rename from lib/pkgs-lib/tests/profiles/t/default.nix rename to lib/tests/profiles/t/default.nix diff --git a/lib/pkgs-lib/tests/testPathsIn/bar b/lib/tests/testPathsIn/bar similarity index 100% rename from lib/pkgs-lib/tests/testPathsIn/bar rename to lib/tests/testPathsIn/bar diff --git a/lib/pkgs-lib/tests/testPathsIn/baz b/lib/tests/testPathsIn/baz similarity index 100% rename from lib/pkgs-lib/tests/testPathsIn/baz rename to lib/tests/testPathsIn/baz diff --git a/lib/pkgs-lib/tests/testPathsIn/foo b/lib/tests/testPathsIn/foo similarity index 100% rename from lib/pkgs-lib/tests/testPathsIn/foo rename to lib/tests/testPathsIn/foo diff --git a/lib/pkgs-lib/tests/testPathsToImportedAttrs/bar.nix b/lib/tests/testPathsToImportedAttrs/bar.nix similarity index 100% rename from lib/pkgs-lib/tests/testPathsToImportedAttrs/bar.nix rename to lib/tests/testPathsToImportedAttrs/bar.nix diff --git a/lib/pkgs-lib/tests/testPathsToImportedAttrs/dir/default.nix b/lib/tests/testPathsToImportedAttrs/dir/default.nix similarity index 100% rename from lib/pkgs-lib/tests/testPathsToImportedAttrs/dir/default.nix rename to lib/tests/testPathsToImportedAttrs/dir/default.nix diff --git a/lib/pkgs-lib/tests/testPathsToImportedAttrs/f.nix b/lib/tests/testPathsToImportedAttrs/f.nix similarity index 100% rename from lib/pkgs-lib/tests/testPathsToImportedAttrs/f.nix rename to lib/tests/testPathsToImportedAttrs/f.nix diff --git a/lib/pkgs-lib/tests/testPathsToImportedAttrs/foo.nix b/lib/tests/testPathsToImportedAttrs/foo.nix similarity index 100% rename from lib/pkgs-lib/tests/testPathsToImportedAttrs/foo.nix rename to lib/tests/testPathsToImportedAttrs/foo.nix diff --git a/lib/pkgs-lib/tests/testPathsToImportedAttrs/t.nix b/lib/tests/testPathsToImportedAttrs/t.nix similarity index 100% rename from lib/pkgs-lib/tests/testPathsToImportedAttrs/t.nix rename to lib/tests/testPathsToImportedAttrs/t.nix From 5f89d274284e05a0cf35f8b58cae537756375567 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Thu, 1 Apr 2021 21:10:24 -0500 Subject: [PATCH 05/21] ref: extract lib into subflake --- flake.nix | 58 +++++++++++++-------------- lib/default.nix | 32 --------------- lib/devos/default.nix | 2 +- lib/devos/devosSystem.nix | 4 +- lib/devos/mkHosts.nix | 6 +-- lib/devos/mkPkgs.nix | 4 +- lib/flake.nix | 72 ++++++++++++++++++++++++++++++++++ lib/mkFlake/default.nix | 2 +- lib/mkFlake/evalArgs.nix | 14 +++---- lib/mkFlake/evalOldArgs.nix | 8 ++-- lib/pkgs-lib/default.nix | 4 +- lib/pkgs-lib/shell/default.nix | 4 +- lib/pkgs-lib/tests/default.nix | 4 +- lib/tests/default.nix | 4 +- lib/tests/lib.nix | 4 +- 15 files changed, 131 insertions(+), 91 deletions(-) delete mode 100644 lib/default.nix create mode 100644 lib/flake.nix diff --git a/flake.nix b/flake.nix index fddbc850..b030f5cd 100644 --- a/flake.nix +++ b/flake.nix @@ -5,17 +5,22 @@ { nixos.url = "nixpkgs/nixos-unstable"; override.url = "nixpkgs"; + devos.url = "path:./lib"; # TODO: outfactor into separate repo + devos.inputs = { + nixpkgs.follows = "nixos"; + deploy.inputs = { + flake-compat.follows = "flake-compat"; + naersk.follows = "naersk"; + nixpkgs.follows = "nixos"; + }; + }; + ci-agent = { url = "github:hercules-ci/hercules-ci-agent"; inputs = { nix-darwin.follows = "darwin"; flake-compat.follows = "flake-compat"; nixos-20_09.follows = "nixos"; nixos-unstable.follows = "override"; }; }; darwin.url = "github:LnL7/nix-darwin"; darwin.inputs.nixpkgs.follows = "override"; - deploy = { - url = "github:serokell/deploy-rs"; - inputs = { flake-compat.follows = "flake-compat"; naersk.follows = "naersk"; nixpkgs.follows = "override"; utils.follows = "utils"; }; - }; - devshell.url = "github:numtide/devshell"; flake-compat.url = "github:BBBSnowball/flake-compat/pr-1"; flake-compat.flake = false; home.url = "github:nix-community/home-manager"; @@ -23,32 +28,27 @@ naersk.url = "github:nmattia/naersk"; naersk.inputs.nixpkgs.follows = "override"; nixos-hardware.url = "github:nixos/nixos-hardware"; - utils.url = "github:numtide/flake-utils"; + pkgs.url = "path:./pkgs"; pkgs.inputs.nixpkgs.follows = "nixos"; }; - outputs = inputs@{ deploy, nixos, nur, self, utils, ... }: - let - lib = import ./lib { inherit self nixos utils inputs; }; - in - lib.mkFlake - { - inherit self; - hosts = ./hosts; - packages = import ./pkgs; - suites = import ./suites; - extern = import ./extern; - overrides = import ./overrides; - overlays = ./overlays; - profiles = ./profiles; - userProfiles = ./users/profiles; - modules = import ./modules/module-list.nix; - userModules = import ./users/modules/module-list.nix; - } // { - inherit lib; - defaultTemplate = self.templates.flk; - templates.flk.path = ./.; - templates.flk.description = "flk template"; - }; + outputs = inputs@{ self, devos, nixos, nur, ... }: + devos.lib.mkFlake { + inherit self; + hosts = ./hosts; + packages = import ./pkgs; + suites = import ./suites; + extern = import ./extern; + overrides = import ./overrides; + overlays = ./overlays; + profiles = ./profiles; + userProfiles = ./users/profiles; + modules = import ./modules/module-list.nix; + userModules = import ./users/modules/module-list.nix; + } // { + defaultTemplate = self.templates.flk; + templates.flk.path = ./.; + templates.flk.description = "flk template"; + }; } diff --git a/lib/default.nix b/lib/default.nix deleted file mode 100644 index 4ed82a45..00000000 --- a/lib/default.nix +++ /dev/null @@ -1,32 +0,0 @@ -args@{ nixos, self, ... }: -let inherit (nixos) lib; in -lib.makeExtensible (final: - let callLibs = file: import file - ({ - inherit lib; - - dev = final; - } // args); - in - with final; - { - inherit callLibs; - - attrs = callLibs ./attrs.nix; - os = callLibs ./devos; - lists = callLibs ./lists.nix; - strings = callLibs ./strings.nix; - - mkFlake = { - __functor = callLibs ./mkFlake; - evalArgs = callLibs ./mkFlake/evalArgs.nix; - evalOldArgs = callLibs ./mkFlake/evalOldArgs.nix; - }; - - pkgs-lib = callLibs ./pkgs-lib; - - inherit (attrs) mapFilterAttrs genAttrs' safeReadDir - pathsToImportedAttrs concatAttrs filterPackages; - inherit (lists) pathsIn; - inherit (strings) rgxToString; - }) diff --git a/lib/devos/default.nix b/lib/devos/default.nix index e580ef00..68517251 100644 --- a/lib/devos/default.nix +++ b/lib/devos/default.nix @@ -1,4 +1,4 @@ -{ lib, nixos, dev, ... }: +{ lib, dev, ... }: { # pkgImport :: Nixpkgs -> Overlays -> System -> Pkgs pkgImport = nixpkgs: overlays: system: diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index b0f53fd8..32af38a3 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -1,4 +1,4 @@ -{ lib, nixos, self, inputs, ... }: +{ lib, nixpkgs, self, inputs, ... }: { modules, ... } @ args: lib.nixosSystem (args // { @@ -13,7 +13,7 @@ lib.nixosSystem (args // { (args // { modules = moduleList ++ [ - "${nixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" + "${nixpkgs}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ({ config, suites, ... }: { diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 8a8abdb7..984e70ce 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -1,4 +1,4 @@ -{ lib, dev, nixos, inputs, self, ... }: +{ lib, dev, nixpkgs, inputs, self, ... }: { dir, extern, suites, overrides, multiPkgs, ... }: let @@ -36,7 +36,7 @@ let hardware.enableRedistributableFirmware = lib.mkDefault true; nix.nixPath = [ - "nixpkgs=${nixos}" + "nixpkgs=${nixpkgs}" "nixos-config=${self}/compat/nixos" "home-manager=${inputs.home}" ]; @@ -45,7 +45,7 @@ let nix.registry = { devos.flake = self; - nixos.flake = nixos; + nixos.flake = nixpkgs; override.flake = inputs.override; }; diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index f3126eaf..260e97b9 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -1,4 +1,4 @@ -{ lib, dev, nixos, self, inputs, ... }: +{ lib, dev, nixpkgs, self, inputs, ... }: { extern, overrides }: (inputs.utils.lib.eachDefaultSystem @@ -22,6 +22,6 @@ ++ extern.overlays ++ (lib.attrValues self.overlays); in - { pkgs = dev.os.pkgImport nixos overlays system; } + { pkgs = dev.os.pkgImport nixpkgs overlays system; } ) ).pkgs diff --git a/lib/flake.nix b/lib/flake.nix new file mode 100644 index 00000000..b0d362b7 --- /dev/null +++ b/lib/flake.nix @@ -0,0 +1,72 @@ +{ + description = "DevOS environment configuriguration library."; + + inputs = + { + deploy.url = "github:serokell/deploy-rs"; + deploy.inputs = { + utils.follows = "flake-utils"; + }; + devshell.url = "github:numtide/devshell"; + flake-utils.url = "github:numtide/flake-utils"; + + }; + + outputs = inputs@{ self, nixpkgs, deploy, devshell, flake-utils, ... }: let + + inherit (nixpkgs) lib; + + # We work with a combined lib, internally ... + combinedLib = lib.extend (final: prev: + let callLibs = file: import file + ({ + lib = final; + dev = final; + inputs = inputs; + } // inputs); + in + with final; + { + inherit callLibs; + + attrs = callLibs ./attrs.nix; + os = callLibs ./devos; + lists = callLibs ./lists.nix; + strings = callLibs ./strings.nix; + + mkFlake = { + __functor = callLibs ./mkFlake; + evalArgs = callLibs ./mkFlake/evalArgs.nix; + evalOldArgs = callLibs ./mkFlake/evalOldArgs.nix; + }; + + pkgs-lib = callLibs ./pkgs-lib; + + inherit (attrs) mapFilterAttrs genAttrs' safeReadDir + pathsToImportedAttrs concatAttrs filterPackages; + inherit (lists) pathsIn; + inherit (strings) rgxToString; + }); + + in { + + # ... but don't force that choice onto the user + lib = { + mkFlake = combinedLib.mkFlake; + pkgs-lib = combinedLib.pkgs-lib; + }; + + + checks = flake-utils.lib.eachDefaultSystem (system: let + nixpkgs = import nixpkgs { inherit system; overlays = []; config = {}; }; + in + { + tests = import ./tests { + inherit (nixpkgs) pkgs; + inherit (self) lib; + }; + } + ); + }; + +} diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 4fd6947e..916e349d 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,4 +1,4 @@ -{ dev, nixos, inputs, ... }: +{ dev, inputs, ... }: let inherit (dev) os; inherit (inputs) utils deploy; diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index d3681760..ac3d0c88 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,8 +1,8 @@ -{ self, dev, nixos, inputs, utils, ... }: +{ self, dev, lib, inputs, utils, ... }: { args }: let - argOpts = with nixos.lib; { config, ... }: + argOpts = with lib; { config, ... }: let inherit (dev) os; @@ -25,7 +25,7 @@ let description = "valid Nixpkgs overlay"; }; systemType = types.enum config.supportedSystems; - flakeType = with types; (addCheck attrs nixos.lib.isStorePath) // { + flakeType = with types; (addCheck attrs lib.isStorePath) // { description = "nix flake"; }; @@ -54,10 +54,10 @@ let options = with types; { input = mkOption { type = flakeType; - default = inputs.nixos; + default = inputs.nixpkgs; description = '' nixpkgs flake input to use for this channel - ''; + ''; }; overlays = mkOption { type = pathTo (listOf overlayType); @@ -199,7 +199,7 @@ let let default = { nixpkgs = { - input = inputs.nixos; + input = inputs.nixpkgs; }; }; in @@ -228,6 +228,6 @@ let }; }; in -nixos.lib.evalModules { +lib.evalModules { modules = [ argOpts args ]; } diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix index 29d04bc6..ef9360a2 100644 --- a/lib/mkFlake/evalOldArgs.nix +++ b/lib/mkFlake/evalOldArgs.nix @@ -1,8 +1,8 @@ -{ self, dev, nixos, inputs, ... }: +{ self, dev, lib, inputs, ... }: { args }: let - argOpts = with nixos.lib; { config, options, ... }: + argOpts = with lib; { config, options, ... }: let inherit (dev) os; @@ -17,7 +17,7 @@ let { options = with types; { self = mkOption { - type = addCheck attrs nixos.lib.isStorePath; + type = addCheck attrs lib.isStorePath; description = "The flake to create the devos outputs for"; }; hosts = mkOption { @@ -149,6 +149,6 @@ let }; }; in -nixos.lib.evalModules { +lib.evalModules { modules = [ argOpts args ]; } diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index 807b44fc..cf74b7f8 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -1,8 +1,8 @@ -args@{ lib, dev, utils, nixos, ... }: +args@{ lib, dev, utils, nixpkgs, ... }: lib.genAttrs utils.lib.defaultSystems (system: lib.makeExtensible (final: let - pkgs = import nixos { inherit system; }; + pkgs = import nixpkgs { inherit system; }; callLibs = file: import file (args // { inherit pkgs system; diff --git a/lib/pkgs-lib/shell/default.nix b/lib/pkgs-lib/shell/default.nix index ed78187c..6a3e4bf4 100644 --- a/lib/pkgs-lib/shell/default.nix +++ b/lib/pkgs-lib/shell/default.nix @@ -1,4 +1,4 @@ -{ lib, dev, inputs, system, nixos, ... }: +{ lib, dev, inputs, system, nixpkgs, ... }: let overlays = [ inputs.devshell.overlay @@ -8,7 +8,7 @@ let }) ]; - pkgs = dev.os.pkgImport nixos overlays system; + pkgs = dev.os.pkgImport nixpkgs overlays system; flk = pkgs.callPackage ./flk.nix { }; diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index 891baee9..64ca44ee 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -1,4 +1,4 @@ -{ pkgs, system, inputs, nixos, lib, ... }: +{ pkgs, system, inputs, nixpkgs, lib, ... }: let mkChecks = { hosts, nodes, homes ? { } }: let @@ -17,7 +17,7 @@ let mkTest = host: let nixosTesting = - (import "${nixos}/nixos/lib/testing-python.nix" { + (import "${nixpkgs}/nixos/lib/testing-python.nix" { inherit system; inherit (host.config.lib) specialArgs; inherit pkgs; diff --git a/lib/tests/default.nix b/lib/tests/default.nix index c13dd8a1..4863cdf7 100644 --- a/lib/tests/default.nix +++ b/lib/tests/default.nix @@ -1,11 +1,11 @@ -{ pkgs, lib, dev, ... }: +{ pkgs, lib }: pkgs.runCommandNoCC "devos-lib-tests" { buildInputs = [ pkgs.nix ( - let tests = import ./lib.nix { inherit pkgs lib dev; }; in + let tests = import ./lib.nix { inherit pkgs lib; }; in if tests == [ ] then null else throw (builtins.toJSON tests) ) diff --git a/lib/tests/lib.nix b/lib/tests/lib.nix index 68baa9f5..66264787 100644 --- a/lib/tests/lib.nix +++ b/lib/tests/lib.nix @@ -1,5 +1,5 @@ -{ pkgs, lib, dev, ... }: -with dev; +{ pkgs, lib }: +with lib; lib.runTests { testConcatAttrs = { expr = concatAttrs [{ foo = 1; } { bar = 2; } { baz = 3; }]; From 21a03fa94c9a3bb63f1be88857c80e5900c18cf4 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 17:23:27 -0500 Subject: [PATCH 06/21] fixup: nix flake check I / X --- flake.lock | 131 +++++++++++++++++++++++++++++++++++++++----------- lib/flake.nix | 30 +++++++----- 2 files changed, 123 insertions(+), 38 deletions(-) diff --git a/flake.lock b/flake.lock index 39962689..a3c6ce97 100644 --- a/flake.lock +++ b/flake.lock @@ -52,25 +52,17 @@ }, "deploy": { "inputs": { - "flake-compat": [ - "flake-compat" - ], - "naersk": [ - "naersk" - ], - "nixpkgs": [ - "override" - ], - "utils": [ - "utils" - ] + "flake-compat": "flake-compat", + "naersk": "naersk", + "nixpkgs": "nixpkgs", + "utils": "utils" }, "locked": { - "lastModified": 1614654775, - "narHash": "sha256-3mLxoxIXSWUuKE8YgIuqM5AZzXFd1aWxkTlplEDeXIA=", + "lastModified": 1616406726, + "narHash": "sha256-n9zmgxR03QNrvs9/fHewqE0j3SjL7Y+cglBCFu3U3rg=", "owner": "serokell", "repo": "deploy-rs", - "rev": "6278b9bef5ad624676a565980417cbbef42d5227", + "rev": "9e405fbc5ab5bacbd271fd78c6b6b6877c4d9f8d", "type": "github" }, "original": { @@ -79,13 +71,32 @@ "type": "github" } }, + "devos": { + "inputs": { + "deploy": "deploy", + "devshell": "devshell", + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixos" + ] + }, + "locked": { + "narHash": "sha256-077+hIF3WGvzgD3DeykCCKFL4xsgnE3ONaCNDnxH1t4=", + "path": "./lib", + "type": "path" + }, + "original": { + "path": "./lib", + "type": "path" + } + }, "devshell": { "locked": { - "lastModified": 1613641255, - "narHash": "sha256-iSvjFK4WYAKhuXCCtkY7uy/cFQTzS3D3Ml5WZqjEfL0=", + "lastModified": 1618523768, + "narHash": "sha256-Gev9da35pHUey3kGz/zrJFc/9ICs++vPCho7qB1mqd8=", "owner": "numtide", "repo": "devshell", - "rev": "ff6cffba08600f5b7b43f398fcb58bef023bc4c4", + "rev": "709fe4d04a9101c9d224ad83f73416dce71baf21", "type": "github" }, "original": { @@ -95,6 +106,22 @@ } }, "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1606424373, + "narHash": "sha256-oq8d4//CJOrVj+EcOaSXvMebvuTkmBJuT5tzlfewUnQ=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "99f1c2157fba4bfe6211a321fd0ee43199025dbf", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_2": { "flake": false, "locked": { "lastModified": 1611461076, @@ -111,6 +138,21 @@ "type": "github" } }, + "flake-utils": { + "locked": { + "lastModified": 1618217525, + "narHash": "sha256-WGrhVczjXTiswQaoxQ+0PTfbLNeOQM6M36zvLn78AYg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c6169a2772643c4a93a0b5ac1c61e296cba68544", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "home": { "inputs": { "nixpkgs": [ @@ -132,6 +174,27 @@ } }, "naersk": { + "inputs": { + "nixpkgs": [ + "override" + ] + }, + "locked": { + "lastModified": 1610392286, + "narHash": "sha256-3wFl5y+4YZO4SgRYK8WE7JIS3p0sxbgrGaQ6RMw+d98=", + "owner": "nmattia", + "repo": "naersk", + "rev": "d7bfbad3304fd768c0f93a4c3b50976275e6d4be", + "type": "github" + }, + "original": { + "owner": "nmattia", + "ref": "master", + "repo": "naersk", + "type": "github" + } + }, + "naersk_2": { "inputs": { "nixpkgs": [ "override" @@ -181,6 +244,22 @@ "type": "github" } }, + "nixpkgs": { + "locked": { + "lastModified": 1610942247, + "narHash": "sha256-PKo1ATAlC6BmfYSRmX0TVmNoFbrec+A5OKcabGEu2yU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7d71001b796340b219d1bfa8552c81995017544a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "nur": { "locked": { "lastModified": 1615921934, @@ -245,26 +324,24 @@ "inputs": { "ci-agent": "ci-agent", "darwin": "darwin", - "deploy": "deploy", - "devshell": "devshell", - "flake-compat": "flake-compat", + "devos": "devos", + "flake-compat": "flake-compat_2", "home": "home", - "naersk": "naersk", + "naersk": "naersk_2", "nixos": "nixos", "nixos-hardware": "nixos-hardware", "nur": "nur", "override": "override", - "pkgs": "pkgs", - "utils": "utils" + "pkgs": "pkgs" } }, "utils": { "locked": { - "lastModified": 1614513358, - "narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=", + "lastModified": 1610051610, + "narHash": "sha256-U9rPz/usA1/Aohhk7Cmc2gBrEEKRzcW4nwPWMPwja4Y=", "owner": "numtide", "repo": "flake-utils", - "rev": "5466c5bbece17adaab2d82fae80b46e807611bf3", + "rev": "3982c9903e93927c2164caa727cd3f6a0e6d14cc", "type": "github" }, "original": { diff --git a/lib/flake.nix b/lib/flake.nix index b0d362b7..620e2082 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -5,14 +5,14 @@ { deploy.url = "github:serokell/deploy-rs"; deploy.inputs = { - utils.follows = "flake-utils"; + utils.follows = "utils"; }; devshell.url = "github:numtide/devshell"; - flake-utils.url = "github:numtide/flake-utils"; + utils.url = "github:numtide/flake-utils"; }; - outputs = inputs@{ self, nixpkgs, deploy, devshell, flake-utils, ... }: let + outputs = inputs@{ self, nixpkgs, deploy, devshell, utils, ... }: let inherit (nixpkgs) lib; @@ -48,7 +48,9 @@ inherit (strings) rgxToString; }); - in { + in + + { # ... but don't force that choice onto the user lib = { @@ -57,16 +59,22 @@ }; - checks = flake-utils.lib.eachDefaultSystem (system: let - nixpkgs = import nixpkgs { inherit system; overlays = []; config = {}; }; + } + + // + + utils.lib.eachDefaultSystem (system: + let + nixpkgs' = import nixpkgs { inherit system; overlays = []; config = {}; }; in { - tests = import ./tests { - inherit (nixpkgs) pkgs; - inherit (self) lib; + checks = { + tests = import ./tests { + inherit (nixpkgs') pkgs; + lib = combinedLib; + }; }; } - ); - }; + ); } From 6116779b23e5e5e189175fd29b220f13525fbdb0 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 17:40:57 -0500 Subject: [PATCH 07/21] fixup: nix flake check II / II --- lib/flake.nix | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/flake.nix b/lib/flake.nix index 620e2082..25e451ca 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -26,13 +26,15 @@ } // inputs); in with final; + let + attrs = callLibs ./attrs.nix; + lists = callLibs ./lists.nix; + strings = callLibs ./strings.nix; + in { inherit callLibs; - attrs = callLibs ./attrs.nix; os = callLibs ./devos; - lists = callLibs ./lists.nix; - strings = callLibs ./strings.nix; mkFlake = { __functor = callLibs ./mkFlake; From 19c900e2933999f27fbe5a2015745a02adb3a6e6 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 17:45:51 -0500 Subject: [PATCH 08/21] workarround for unkown problem --- flake.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index b030f5cd..443c9b98 100644 --- a/flake.nix +++ b/flake.nix @@ -8,11 +8,11 @@ devos.url = "path:./lib"; # TODO: outfactor into separate repo devos.inputs = { nixpkgs.follows = "nixos"; - deploy.inputs = { - flake-compat.follows = "flake-compat"; - naersk.follows = "naersk"; - nixpkgs.follows = "nixos"; - }; + # deploy.inputs = { + # flake-compat.follows = "flake-compat"; + # naersk.follows = "naersk"; + # nixpkgs.follows = "nixos"; + # }; }; ci-agent = { From c24199649a3f58a6203f823d555143394a8cd134 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 18:30:07 -0500 Subject: [PATCH 09/21] fixup: distinguish self and userSelf --- lib/devos/devosSystem.nix | 6 +++--- lib/devos/mkHomeConfigurations.nix | 4 ++-- lib/devos/mkHosts.nix | 14 +++++++------- lib/devos/mkPackages.nix | 4 ++-- lib/devos/mkPkgs.nix | 6 +++--- lib/mkFlake/default.nix | 12 +++++++----- lib/mkFlake/evalArgs.nix | 6 +++--- lib/mkFlake/evalOldArgs.nix | 26 +++++++++++++------------- 8 files changed, 40 insertions(+), 38 deletions(-) diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index 32af38a3..dbe3af48 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -1,4 +1,4 @@ -{ lib, nixpkgs, self, inputs, ... }: +{ lib, nixpkgs, userSelf, inputs, ... }: { modules, ... } @ args: lib.nixosSystem (args // { @@ -27,11 +27,11 @@ lib.nixosSystem (args // { isoImage.isoBaseName = "nixos-" + config.networking.hostName; isoImage.contents = [{ - source = self; + source = userSelf; target = "/devos/"; }]; isoImage.storeContents = [ - self.devShell.${config.nixpkgs.system} + userSelf.devShell.${config.nixpkgs.system} # include also closures that are "switched off" by the # above profile filter on the local config attribute fullHostConfig.system.build.toplevel diff --git a/lib/devos/mkHomeConfigurations.nix b/lib/devos/mkHomeConfigurations.nix index 490975a1..5d39cdd7 100644 --- a/lib/devos/mkHomeConfigurations.nix +++ b/lib/devos/mkHomeConfigurations.nix @@ -1,4 +1,4 @@ -{ lib, self, ... }: +{ lib, userSelf, ... }: with lib; let @@ -6,7 +6,7 @@ let mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) config.config.system.build.homes; - hmConfigs = mapAttrs mkHomes self.nixosConfigurations; + hmConfigs = mapAttrs mkHomes userSelf.nixosConfigurations; in foldl recursiveUpdate { } (attrValues hmConfigs) diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 984e70ce..1bc6bf98 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -1,4 +1,4 @@ -{ lib, dev, nixpkgs, inputs, self, ... }: +{ lib, dev, nixpkgs, inputs, userSelf, ... }: { dir, extern, suites, overrides, multiPkgs, ... }: let @@ -29,7 +29,7 @@ let useUserPackages = true; extraSpecialArgs = extern.userSpecialArgs // { suites = suites.user; }; - sharedModules = extern.userModules ++ (builtins.attrValues self.homeModules); + sharedModules = extern.userModules ++ (builtins.attrValues userSelf.homeModules); }; users.mutableUsers = lib.mkDefault false; @@ -37,14 +37,14 @@ let nix.nixPath = [ "nixpkgs=${nixpkgs}" - "nixos-config=${self}/compat/nixos" + "nixos-config=${userSelf}/compat/nixos" "home-manager=${inputs.home}" ]; nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; nix.registry = { - devos.flake = self; + devos.flake = userSelf; nixos.flake = nixpkgs; override.flake = inputs.override; }; @@ -57,11 +57,11 @@ let } ''; - system.configurationRevision = lib.mkIf (self ? rev) self.rev; + system.configurationRevision = lib.mkIf (userSelf ? rev) userSelf.rev; }; # Everything in `./modules/list.nix`. - flakeModules = { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; + flakeModules = { imports = builtins.attrValues userSelf.nixosModules ++ extern.modules; }; cachix = ../../cachix.nix; }; @@ -78,7 +78,7 @@ let networking = { inherit hostName; }; _module.args = { - inherit self; + self = userSelf; hosts = builtins.mapAttrs (_: host: host.config) (removeAttrs hosts [ hostName ]); }; diff --git a/lib/devos/mkPackages.nix b/lib/devos/mkPackages.nix index a876ea0b..1b3404a1 100644 --- a/lib/devos/mkPackages.nix +++ b/lib/devos/mkPackages.nix @@ -1,8 +1,8 @@ -{ lib, dev, self, ... }: +{ lib, dev, userSelf, ... }: { pkgs }: let - inherit (self) overlay overlays; + inherit (userSelf) overlay overlays; packagesNames = lib.attrNames (overlay null null) ++ lib.attrNames (dev.concatAttrs (lib.attrValues diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index 260e97b9..d2d07db1 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -1,4 +1,4 @@ -{ lib, dev, nixpkgs, self, inputs, ... }: +{ lib, dev, nixpkgs, userSelf, inputs, ... }: { extern, overrides }: (inputs.utils.lib.eachDefaultSystem @@ -17,10 +17,10 @@ }); }) (overridesOverlay overridePkgs) - self.overlay + userSelf.overlay ] ++ extern.overlays - ++ (lib.attrValues self.overlays); + ++ (lib.attrValues userSelf.overlays); in { pkgs = dev.os.pkgImport nixpkgs overlays system; } ) diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 916e349d..6fdca16f 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -7,13 +7,15 @@ in _: { self, ... } @ args: let + userSelf = self; + cfg = (dev.mkFlake.evalOldArgs { inherit args; }).config; multiPkgs = os.mkPkgs { inherit (cfg) extern overrides; }; outputs = { nixosConfigurations = os.mkHosts { - inherit self multiPkgs; + inherit userSelf multiPkgs; inherit (cfg) extern suites overrides; dir = cfg.hosts; }; @@ -27,7 +29,7 @@ let overlay = cfg.packages; inherit (cfg) overlays; - deploy.nodes = os.mkNodes deploy self.nixosConfigurations; + deploy.nodes = os.mkNodes deploy userSelf.nixosConfigurations; }; systemOutputs = utils.lib.eachDefaultSystem (system: @@ -39,9 +41,9 @@ let in { checks = pkgs-lib.tests.mkChecks { - inherit (self.deploy) nodes; - hosts = self.nixosConfigurations; - homes = self.homeConfigurations; + inherit (userSelf.deploy) nodes; + hosts = userSelf.nixosConfigurations; + homes = userSelf.homeConfigurations; }; inherit legacyPackages; diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index ac3d0c88..ad866ea6 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,4 +1,4 @@ -{ self, dev, lib, inputs, utils, ... }: +{ userSelf, dev, lib, inputs, utils, ... }: { args }: let @@ -161,8 +161,8 @@ let }; profiles = mkOption { type = path; - default = "${self}/profiles"; - defaultText = "\${self}/profiles"; + default = "${userSelf}/profiles"; + defaultText = "\${userSelf}/profiles"; apply = x: os.mkProfileAttrs (toString x); description = "path to profiles folder that can be collected into suites"; }; diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix index ef9360a2..f728b480 100644 --- a/lib/mkFlake/evalOldArgs.nix +++ b/lib/mkFlake/evalOldArgs.nix @@ -1,4 +1,4 @@ -{ self, dev, lib, inputs, ... }: +{ userSelf, dev, lib, inputs, ... }: { args }: let @@ -22,8 +22,8 @@ let }; hosts = mkOption { type = path; - default = "${self}/hosts"; - defaultText = "\${self}/hosts"; + default = "${userSelf}/hosts"; + defaultText = "\${userSelf}/hosts"; apply = toString; description = '' Path to directory containing host configurations that will be exported @@ -64,15 +64,15 @@ let }; profiles = mkOption { type = path; - default = "${self}/profiles"; - defaultText = "\${self}/profiles"; + default = "${userSelf}/profiles"; + defaultText = "\${userSelf}/profiles"; apply = x: os.mkProfileAttrs (toString x); description = "path to profiles folder that can be collected into suites"; }; userProfiles = mkOption { type = path; - default = "${self}/users/profiles"; - defaultText = "\${self}/users/profiles"; + default = "${userSelf}/users/profiles"; + defaultText = "\${userSelf}/users/profiles"; apply = x: os.mkProfileAttrs (toString x); description = "path to user profiles folder that can be collected into userSuites"; }; @@ -97,8 +97,8 @@ let }; users = mkOption { type = path; - default = "${self}/users"; - defaultText = "\${self}/users"; + default = "${userSelf}/users"; + defaultText = "\${userSelf}/users"; apply = x: os.mkProfileAttrs (toString x); description = '' path to folder containing profiles that define system users @@ -121,9 +121,9 @@ let { modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; } ''; # So unneeded extern attributes can safely be deleted - apply = x: defaults // (x { inputs = inputs // self.inputs; }); + apply = x: defaults // (x { inputs = inputs // userSelf.inputs; }); description = '' - Function with argument 'inputs' that contains all devos and ''${self}'s inputs. + Function with argument 'inputs' that contains all devos and ''${userSelf}'s inputs. The function should return an attribute set with modules, overlays, and specialArgs to be included across nixos and home manager configurations. Only attributes that are used should be returned. @@ -131,8 +131,8 @@ let }; overlays = mkOption { type = path; - default = "${self}/overlays"; - defaultText = "\${self}/overlays"; + default = "${userSelf}/overlays"; + defaultText = "\${userSelf}/overlays"; apply = x: dev.pathsToImportedAttrs (dev.pathsIn (toString x)); description = '' path to folder containing overlays which will be applied to pkgs and exported in From fb6c6ba4cf693df6f87921d418a2e8d176d45a4b Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 19:15:53 -0500 Subject: [PATCH 10/21] fix: update devos in flake.lock --- flake.lock | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/flake.lock b/flake.lock index a3c6ce97..531c9813 100644 --- a/flake.lock +++ b/flake.lock @@ -75,13 +75,13 @@ "inputs": { "deploy": "deploy", "devshell": "devshell", - "flake-utils": "flake-utils", "nixpkgs": [ "nixos" - ] + ], + "utils": "utils_2" }, "locked": { - "narHash": "sha256-077+hIF3WGvzgD3DeykCCKFL4xsgnE3ONaCNDnxH1t4=", + "narHash": "sha256-/SJJ8u/qBnCtMbMxBmDNBDnLWnmro2ioi35gL45hP9w=", "path": "./lib", "type": "path" }, @@ -138,21 +138,6 @@ "type": "github" } }, - "flake-utils": { - "locked": { - "lastModified": 1618217525, - "narHash": "sha256-WGrhVczjXTiswQaoxQ+0PTfbLNeOQM6M36zvLn78AYg=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c6169a2772643c4a93a0b5ac1c61e296cba68544", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "home": { "inputs": { "nixpkgs": [ @@ -349,6 +334,21 @@ "repo": "flake-utils", "type": "github" } + }, + "utils_2": { + "locked": { + "lastModified": 1618217525, + "narHash": "sha256-WGrhVczjXTiswQaoxQ+0PTfbLNeOQM6M36zvLn78AYg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c6169a2772643c4a93a0b5ac1c61e296cba68544", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } } }, "root": "root", From 16b3fad559b6f44eda5068eb369d1dd83827de7f Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sat, 17 Apr 2021 20:35:05 -0500 Subject: [PATCH 11/21] ref: merge dev into lib --- lib/devos/default.nix | 20 ++++++++++---------- lib/devos/mkHosts.nix | 6 +++--- lib/devos/mkPackages.nix | 4 ++-- lib/devos/mkPkgs.nix | 8 ++++---- lib/devos/mkProfileAttrs.nix | 4 ++-- lib/devos/mkSuites.nix | 4 ++-- lib/devos/recImport.nix | 6 +++--- lib/flake.nix | 1 - lib/lists.nix | 4 ++-- lib/mkFlake/default.nix | 8 ++++---- lib/mkFlake/evalArgs.nix | 8 ++++---- lib/mkFlake/evalOldArgs.nix | 10 +++++----- lib/pkgs-lib/default.nix | 2 +- lib/pkgs-lib/shell/default.nix | 4 ++-- lib/pkgs-lib/tests/lib.nix | 4 ++-- 15 files changed, 46 insertions(+), 47 deletions(-) diff --git a/lib/devos/default.nix b/lib/devos/default.nix index 68517251..fb9e990f 100644 --- a/lib/devos/default.nix +++ b/lib/devos/default.nix @@ -1,4 +1,4 @@ -{ lib, dev, ... }: +{ lib, ... }: { # pkgImport :: Nixpkgs -> Overlays -> System -> Pkgs pkgImport = nixpkgs: overlays: system: @@ -9,22 +9,22 @@ profileMap = map (profile: profile.default); - mkNodes = dev.callLibs ./mkNodes.nix; + mkNodes = lib.callLibs ./mkNodes.nix; - mkHosts = dev.callLibs ./mkHosts.nix; + mkHosts = lib.callLibs ./mkHosts.nix; - mkSuites = dev.callLibs ./mkSuites.nix; + mkSuites = lib.callLibs ./mkSuites.nix; - mkProfileAttrs = dev.callLibs ./mkProfileAttrs.nix; + mkProfileAttrs = lib.callLibs ./mkProfileAttrs.nix; - mkPkgs = dev.callLibs ./mkPkgs.nix; + mkPkgs = lib.callLibs ./mkPkgs.nix; - recImport = dev.callLibs ./recImport.nix; + recImport = lib.callLibs ./recImport.nix; - devosSystem = dev.callLibs ./devosSystem.nix; + devosSystem = lib.callLibs ./devosSystem.nix; - mkHomeConfigurations = dev.callLibs ./mkHomeConfigurations.nix; + mkHomeConfigurations = lib.callLibs ./mkHomeConfigurations.nix; - mkPackages = dev.callLibs ./mkPackages.nix; + mkPackages = lib.callLibs ./mkPackages.nix; } diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 1bc6bf98..056c4e78 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -1,4 +1,4 @@ -{ lib, dev, nixpkgs, inputs, userSelf, ... }: +{ lib, nixpkgs, inputs, userSelf, ... }: { dir, extern, suites, overrides, multiPkgs, ... }: let @@ -90,13 +90,13 @@ let }; }; in - dev.os.devosSystem { + lib.os.devosSystem { inherit specialArgs; system = defaultSystem; modules = modules // { inherit local lib; }; }; - hosts = dev.os.recImport + hosts = lib.os.recImport { inherit dir; _import = mkHostConfig; diff --git a/lib/devos/mkPackages.nix b/lib/devos/mkPackages.nix index 1b3404a1..a9d37bb0 100644 --- a/lib/devos/mkPackages.nix +++ b/lib/devos/mkPackages.nix @@ -1,10 +1,10 @@ -{ lib, dev, userSelf, ... }: +{ lib, userSelf, ... }: { pkgs }: let inherit (userSelf) overlay overlays; packagesNames = lib.attrNames (overlay null null) - ++ lib.attrNames (dev.concatAttrs + ++ lib.attrNames (lib.concatAttrs (lib.attrValues (lib.mapAttrs (_: v: v null null) overlays) ) diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index d2d07db1..fda3cad3 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -1,16 +1,16 @@ -{ lib, dev, nixpkgs, userSelf, inputs, ... }: +{ lib, nixpkgs, userSelf, inputs, ... }: { extern, overrides }: (inputs.utils.lib.eachDefaultSystem (system: let - overridePkgs = dev.os.pkgImport inputs.override [ ] system; + overridePkgs = lib.os.pkgImport inputs.override [ ] system; overridesOverlay = overrides.packages; overlays = [ (final: prev: { lib = prev.lib.extend (lfinal: lprev: { - inherit dev; + inherit lib; inherit (lib) nixosSystem; utils = inputs.utils.lib; @@ -22,6 +22,6 @@ ++ extern.overlays ++ (lib.attrValues userSelf.overlays); in - { pkgs = dev.os.pkgImport nixpkgs overlays system; } + { pkgs = lib.os.pkgImport nixpkgs overlays system; } ) ).pkgs diff --git a/lib/devos/mkProfileAttrs.nix b/lib/devos/mkProfileAttrs.nix index d89c6ba2..7168b291 100644 --- a/lib/devos/mkProfileAttrs.nix +++ b/lib/devos/mkProfileAttrs.nix @@ -1,4 +1,4 @@ -{ lib, dev, ... }: +{ lib, ... }: let mkProfileAttrs = /** @@ -16,7 +16,7 @@ let mkProfileAttrs = let imports = let - files = dev.safeReadDir dir; + files = lib.safeReadDir dir; p = n: v: v == "directory" diff --git a/lib/devos/mkSuites.nix b/lib/devos/mkSuites.nix index a3a32944..0a5950bb 100644 --- a/lib/devos/mkSuites.nix +++ b/lib/devos/mkSuites.nix @@ -1,8 +1,8 @@ -{ lib, dev, ... }: +{ lib, ... }: { users, profiles, userProfiles, suites } @ args: let - inherit (dev) os; + inherit (lib) os; definedSuites = suites { inherit (args) users profiles userProfiles; diff --git a/lib/devos/recImport.nix b/lib/devos/recImport.nix index d7f2aa82..e9e5da68 100644 --- a/lib/devos/recImport.nix +++ b/lib/devos/recImport.nix @@ -1,7 +1,7 @@ -{ lib, dev, ... }: +{ lib, ... }: { dir, _import ? base: import "${dir}/${base}.nix" }: -dev.mapFilterAttrs +lib.mapFilterAttrs (_: v: v != null) (n: v: if n != "default.nix" && lib.hasSuffix ".nix" n && v == "regular" @@ -9,4 +9,4 @@ dev.mapFilterAttrs let name = lib.removeSuffix ".nix" n; in lib.nameValuePair (name) (_import name) else lib.nameValuePair ("") (null)) - (dev.safeReadDir dir) + (lib.safeReadDir dir) diff --git a/lib/flake.nix b/lib/flake.nix index 25e451ca..75bfb89c 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -21,7 +21,6 @@ let callLibs = file: import file ({ lib = final; - dev = final; inputs = inputs; } // inputs); in diff --git a/lib/lists.nix b/lib/lists.nix index b6530f13..74cf9bd4 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -1,8 +1,8 @@ -{ lib, dev, ... }: +{ lib, ... }: { pathsIn = dir: let fullPath = name: "${toString dir}/${name}"; in - map fullPath (lib.attrNames (dev.safeReadDir dir)); + map fullPath (lib.attrNames (lib.safeReadDir dir)); } diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 6fdca16f..eadb7e4d 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,4 +1,4 @@ -{ dev, inputs, ... }: +{ lib, inputs, ... }: let inherit (dev) os; inherit (inputs) utils deploy; @@ -9,7 +9,7 @@ let userSelf = self; - cfg = (dev.mkFlake.evalOldArgs { inherit args; }).config; + cfg = (lib.mkFlake.evalOldArgs { inherit args; }).config; multiPkgs = os.mkPkgs { inherit (cfg) extern overrides; }; @@ -35,7 +35,7 @@ let systemOutputs = utils.lib.eachDefaultSystem (system: let pkgs = multiPkgs.${system}; - pkgs-lib = dev.pkgs-lib.${system}; + pkgs-lib = lib.pkgs-lib.${system}; # all packages that are defined in ./pkgs legacyPackages = os.mkPackages { inherit pkgs; }; in @@ -47,7 +47,7 @@ let }; inherit legacyPackages; - packages = dev.filterPackages system legacyPackages; + packages = lib.filterPackages system legacyPackages; devShell = pkgs-lib.shell; }); diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index ad866ea6..9836b25d 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,10 +1,10 @@ -{ userSelf, dev, lib, inputs, utils, ... }: +{ userSelf, lib, inputs, utils, ... }: { args }: let argOpts = with lib; { config, ... }: let - inherit (dev) os; + inherit (lib) os; inherit (config) self; @@ -146,7 +146,7 @@ let modules = mkOption { type = pathTo (listOf moduleType); default = [ ]; - apply = dev.pathsToImportedAttrs; + apply = lib.pathsToImportedAttrs; description = '' list of modules to include in confgurations and export in '${name}Modules' output ''; @@ -154,7 +154,7 @@ let externalModules = mkOption { type = pathTo (listOf moduleType); default = [ ]; - apply = dev.pathsToImportedAttrs; + apply = lib.pathsToImportedAttrs; description = '' list of modules to include in confguration but these are not exported to the '${name}Modules' output ''; diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix index f728b480..68a0d5fe 100644 --- a/lib/mkFlake/evalOldArgs.nix +++ b/lib/mkFlake/evalOldArgs.nix @@ -1,10 +1,10 @@ -{ userSelf, dev, lib, inputs, ... }: +{ userSelf, lib, inputs, ... }: { args }: let argOpts = with lib; { config, options, ... }: let - inherit (dev) os; + inherit (lib) os; inherit (config) self; @@ -48,7 +48,7 @@ let modules = mkOption { type = listOf moduleType; default = [ ]; - apply = dev.pathsToImportedAttrs; + apply = lib.pathsToImportedAttrs; description = '' list of modules to include in confgurations and export in 'nixosModules' output ''; @@ -56,7 +56,7 @@ let userModules = mkOption { type = listOf moduleType; default = [ ]; - apply = dev.pathsToImportedAttrs; + apply = lib.pathsToImportedAttrs; description = '' list of modules to include in home-manager configurations and export in 'homeModules' output @@ -133,7 +133,7 @@ let type = path; default = "${userSelf}/overlays"; defaultText = "\${userSelf}/overlays"; - apply = x: dev.pathsToImportedAttrs (dev.pathsIn (toString x)); + apply = x: lib.pathsToImportedAttrs (lib.pathsIn (toString x)); description = '' path to folder containing overlays which will be applied to pkgs and exported in the 'overlays' output diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index cf74b7f8..ae448a45 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -1,4 +1,4 @@ -args@{ lib, dev, utils, nixpkgs, ... }: +args@{ lib, utils, nixpkgs, ... }: lib.genAttrs utils.lib.defaultSystems (system: lib.makeExtensible (final: let diff --git a/lib/pkgs-lib/shell/default.nix b/lib/pkgs-lib/shell/default.nix index 6a3e4bf4..e5c2d7ca 100644 --- a/lib/pkgs-lib/shell/default.nix +++ b/lib/pkgs-lib/shell/default.nix @@ -1,4 +1,4 @@ -{ lib, dev, inputs, system, nixpkgs, ... }: +{ lib, inputs, system, nixpkgs, ... }: let overlays = [ inputs.devshell.overlay @@ -8,7 +8,7 @@ let }) ]; - pkgs = dev.os.pkgImport nixpkgs overlays system; + pkgs = lib.os.pkgImport nixpkgs overlays system; flk = pkgs.callPackage ./flk.nix { }; diff --git a/lib/pkgs-lib/tests/lib.nix b/lib/pkgs-lib/tests/lib.nix index 68baa9f5..586eac31 100644 --- a/lib/pkgs-lib/tests/lib.nix +++ b/lib/pkgs-lib/tests/lib.nix @@ -1,5 +1,5 @@ -{ pkgs, lib, dev, ... }: -with dev; +{ pkgs, lib, ... }: +with lib; lib.runTests { testConcatAttrs = { expr = concatAttrs [{ foo = 1; } { bar = 2; } { baz = 3; }]; From cd7fb4f54c81e19c93e7cc067b2022d6216bf0fc Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sat, 17 Apr 2021 20:46:20 -0500 Subject: [PATCH 12/21] ref: flatten out inputs --- lib/devos/devosSystem.nix | 4 ++-- lib/devos/mkHosts.nix | 6 +++--- lib/devos/mkPkgs.nix | 6 +++--- lib/flake.nix | 2 +- lib/mkFlake/default.nix | 3 +-- lib/mkFlake/evalArgs.nix | 6 +++--- lib/pkgs-lib/shell/default.nix | 6 +++--- lib/pkgs-lib/tests/default.nix | 4 ++-- 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index dbe3af48..249e2c74 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -1,4 +1,4 @@ -{ lib, nixpkgs, userSelf, inputs, ... }: +{ lib, nixpkgs, userSelf, userFlakeInputs, ... }: { modules, ... } @ args: lib.nixosSystem (args // { @@ -23,7 +23,7 @@ lib.nixosSystem (args // { disabledModules = map (x: [ x ]) (lib.remove modules.core suites.allProfiles); - nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs; + nix.registry = lib.mapAttrs (n: v: { flake = v; }) userFlakeInputs; isoImage.isoBaseName = "nixos-" + config.networking.hostName; isoImage.contents = [{ diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 056c4e78..21ece03c 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -1,4 +1,4 @@ -{ lib, nixpkgs, inputs, userSelf, ... }: +{ lib, nixpkgs, userFlakeInputs, userSelf, ... }: { dir, extern, suites, overrides, multiPkgs, ... }: let @@ -38,7 +38,7 @@ let nix.nixPath = [ "nixpkgs=${nixpkgs}" "nixos-config=${userSelf}/compat/nixos" - "home-manager=${inputs.home}" + "home-manager=${userFlakeInputs.home}" ]; nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; @@ -46,7 +46,7 @@ let nix.registry = { devos.flake = userSelf; nixos.flake = nixpkgs; - override.flake = inputs.override; + override.flake = userFlakeInputs.override; }; nix.package = pkgs.nixFlakes; diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index fda3cad3..61657077 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -1,10 +1,10 @@ -{ lib, nixpkgs, userSelf, inputs, ... }: +{ lib, nixpkgs, userSelf, utils, userFlakeInputs, ... }: { extern, overrides }: -(inputs.utils.lib.eachDefaultSystem +(utils.lib.eachDefaultSystem (system: let - overridePkgs = lib.os.pkgImport inputs.override [ ] system; + overridePkgs = lib.os.pkgImport userFlakeInputs.override [ ] system; overridesOverlay = overrides.packages; overlays = [ diff --git a/lib/flake.nix b/lib/flake.nix index 75bfb89c..47b9ffc2 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -21,7 +21,7 @@ let callLibs = file: import file ({ lib = final; - inputs = inputs; + userFlakeInputs = {}; # TODO: Erm, this must become a proper argument to mkFlake } // inputs); in with final; diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index eadb7e4d..a37fa83c 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,7 +1,6 @@ -{ lib, inputs, ... }: +{ lib, utils, deploy, ... }: let inherit (dev) os; - inherit (inputs) utils deploy; in _: { self, ... } @ args: diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 9836b25d..c157164b 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,4 +1,4 @@ -{ userSelf, lib, inputs, utils, ... }: +{ userSelf, lib, nixpkgs, utils, ... }: { args }: let @@ -54,7 +54,7 @@ let options = with types; { input = mkOption { type = flakeType; - default = inputs.nixpkgs; + default = nixpkgs; description = '' nixpkgs flake input to use for this channel ''; @@ -199,7 +199,7 @@ let let default = { nixpkgs = { - input = inputs.nixpkgs; + input = nixpkgs; }; }; in diff --git a/lib/pkgs-lib/shell/default.nix b/lib/pkgs-lib/shell/default.nix index e5c2d7ca..71c6c29e 100644 --- a/lib/pkgs-lib/shell/default.nix +++ b/lib/pkgs-lib/shell/default.nix @@ -1,10 +1,10 @@ -{ lib, inputs, system, nixpkgs, ... }: +{ lib, devshell, deploy, system, nixpkgs, ... }: let overlays = [ - inputs.devshell.overlay + devshell.overlay (final: prev: { deploy-rs = - inputs.deploy.packages.${prev.system}.deploy-rs; + deploy.packages.${prev.system}.deploy-rs; }) ]; diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index 64ca44ee..a72ade6e 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -1,11 +1,11 @@ -{ pkgs, system, inputs, nixpkgs, lib, ... }: +{ pkgs, system, deploy, nixpkgs, lib, ... }: let mkChecks = { hosts, nodes, homes ? { } }: let deployHosts = lib.filterAttrs (n: _: hosts.${n}.config.nixpkgs.system == system) nodes; - deployChecks = inputs.deploy.lib.${system}.deployChecks { nodes = deployHosts; }; + deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; }; tests = lib.optionalAttrs (deployHosts != { }) { profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))}); From 6cccb5526378452afeafd7fca5e66dee41a44b46 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 19:35:11 -0500 Subject: [PATCH 13/21] ref: userSelf -> userFlakeSelf --- lib/devos/devosSystem.nix | 6 +++--- lib/devos/mkHomeConfigurations.nix | 4 ++-- lib/devos/mkHosts.nix | 14 +++++++------- lib/devos/mkPackages.nix | 4 ++-- lib/devos/mkPkgs.nix | 6 +++--- lib/mkFlake/default.nix | 12 ++++++------ lib/mkFlake/evalArgs.nix | 6 +++--- lib/mkFlake/evalOldArgs.nix | 26 +++++++++++++------------- 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index 249e2c74..121638cb 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -1,4 +1,4 @@ -{ lib, nixpkgs, userSelf, userFlakeInputs, ... }: +{ lib, nixpkgs, userFlakeSelf, userFlakeInputs, ... }: { modules, ... } @ args: lib.nixosSystem (args // { @@ -27,11 +27,11 @@ lib.nixosSystem (args // { isoImage.isoBaseName = "nixos-" + config.networking.hostName; isoImage.contents = [{ - source = userSelf; + source = userFlakeSelf; target = "/devos/"; }]; isoImage.storeContents = [ - userSelf.devShell.${config.nixpkgs.system} + userFlakeSelf.devShell.${config.nixpkgs.system} # include also closures that are "switched off" by the # above profile filter on the local config attribute fullHostConfig.system.build.toplevel diff --git a/lib/devos/mkHomeConfigurations.nix b/lib/devos/mkHomeConfigurations.nix index 5d39cdd7..34c5e938 100644 --- a/lib/devos/mkHomeConfigurations.nix +++ b/lib/devos/mkHomeConfigurations.nix @@ -1,4 +1,4 @@ -{ lib, userSelf, ... }: +{ lib, userFlakeSelf, ... }: with lib; let @@ -6,7 +6,7 @@ let mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) config.config.system.build.homes; - hmConfigs = mapAttrs mkHomes userSelf.nixosConfigurations; + hmConfigs = mapAttrs mkHomes userFlakeSelf.nixosConfigurations; in foldl recursiveUpdate { } (attrValues hmConfigs) diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 21ece03c..b11bda95 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -1,4 +1,4 @@ -{ lib, nixpkgs, userFlakeInputs, userSelf, ... }: +{ lib, nixpkgs, userFlakeInputs, userFlakeSelf, ... }: { dir, extern, suites, overrides, multiPkgs, ... }: let @@ -29,7 +29,7 @@ let useUserPackages = true; extraSpecialArgs = extern.userSpecialArgs // { suites = suites.user; }; - sharedModules = extern.userModules ++ (builtins.attrValues userSelf.homeModules); + sharedModules = extern.userModules ++ (builtins.attrValues userFlakeSelf.homeModules); }; users.mutableUsers = lib.mkDefault false; @@ -37,14 +37,14 @@ let nix.nixPath = [ "nixpkgs=${nixpkgs}" - "nixos-config=${userSelf}/compat/nixos" + "nixos-config=${userFlakeSelf}/compat/nixos" "home-manager=${userFlakeInputs.home}" ]; nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; nix.registry = { - devos.flake = userSelf; + devos.flake = userFlakeSelf; nixos.flake = nixpkgs; override.flake = userFlakeInputs.override; }; @@ -57,11 +57,11 @@ let } ''; - system.configurationRevision = lib.mkIf (userSelf ? rev) userSelf.rev; + system.configurationRevision = lib.mkIf (userFlakeSelf ? rev) userFlakeSelf.rev; }; # Everything in `./modules/list.nix`. - flakeModules = { imports = builtins.attrValues userSelf.nixosModules ++ extern.modules; }; + flakeModules = { imports = builtins.attrValues userFlakeSelf.nixosModules ++ extern.modules; }; cachix = ../../cachix.nix; }; @@ -78,7 +78,7 @@ let networking = { inherit hostName; }; _module.args = { - self = userSelf; + self = userFlakeSelf; hosts = builtins.mapAttrs (_: host: host.config) (removeAttrs hosts [ hostName ]); }; diff --git a/lib/devos/mkPackages.nix b/lib/devos/mkPackages.nix index a9d37bb0..17cba0e2 100644 --- a/lib/devos/mkPackages.nix +++ b/lib/devos/mkPackages.nix @@ -1,8 +1,8 @@ -{ lib, userSelf, ... }: +{ lib, userFlakeSelf, ... }: { pkgs }: let - inherit (userSelf) overlay overlays; + inherit (userFlakeSelf) overlay overlays; packagesNames = lib.attrNames (overlay null null) ++ lib.attrNames (lib.concatAttrs (lib.attrValues diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index 61657077..ed669e40 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -1,4 +1,4 @@ -{ lib, nixpkgs, userSelf, utils, userFlakeInputs, ... }: +{ lib, nixpkgs, userFlakeSelf, utils, userFlakeInputs, ... }: { extern, overrides }: (utils.lib.eachDefaultSystem @@ -17,10 +17,10 @@ }); }) (overridesOverlay overridePkgs) - userSelf.overlay + userFlakeSelf.overlay ] ++ extern.overlays - ++ (lib.attrValues userSelf.overlays); + ++ (lib.attrValues userFlakeSelf.overlays); in { pkgs = lib.os.pkgImport nixpkgs overlays system; } ) diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index a37fa83c..fbb2554e 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -6,7 +6,7 @@ in _: { self, ... } @ args: let - userSelf = self; + userFlakeSelf = self; cfg = (lib.mkFlake.evalOldArgs { inherit args; }).config; @@ -14,7 +14,7 @@ let outputs = { nixosConfigurations = os.mkHosts { - inherit userSelf multiPkgs; + inherit userFlakeSelf multiPkgs; inherit (cfg) extern suites overrides; dir = cfg.hosts; }; @@ -28,7 +28,7 @@ let overlay = cfg.packages; inherit (cfg) overlays; - deploy.nodes = os.mkNodes deploy userSelf.nixosConfigurations; + deploy.nodes = os.mkNodes deploy userFlakeSelf.nixosConfigurations; }; systemOutputs = utils.lib.eachDefaultSystem (system: @@ -40,9 +40,9 @@ let in { checks = pkgs-lib.tests.mkChecks { - inherit (userSelf.deploy) nodes; - hosts = userSelf.nixosConfigurations; - homes = userSelf.homeConfigurations; + inherit (userFlakeSelf.deploy) nodes; + hosts = userFlakeSelf.nixosConfigurations; + homes = userFlakeSelf.homeConfigurations; }; inherit legacyPackages; diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index c157164b..3f850801 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,4 +1,4 @@ -{ userSelf, lib, nixpkgs, utils, ... }: +{ userFlakeSelf, lib, nixpkgs, utils, ... }: { args }: let @@ -161,8 +161,8 @@ let }; profiles = mkOption { type = path; - default = "${userSelf}/profiles"; - defaultText = "\${userSelf}/profiles"; + default = "${userFlakeSelf}/profiles"; + defaultText = "\${userFlakeSelf}/profiles"; apply = x: os.mkProfileAttrs (toString x); description = "path to profiles folder that can be collected into suites"; }; diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix index 68a0d5fe..25dd7c9d 100644 --- a/lib/mkFlake/evalOldArgs.nix +++ b/lib/mkFlake/evalOldArgs.nix @@ -1,4 +1,4 @@ -{ userSelf, lib, inputs, ... }: +{ userFlakeSelf, lib, inputs, ... }: { args }: let @@ -22,8 +22,8 @@ let }; hosts = mkOption { type = path; - default = "${userSelf}/hosts"; - defaultText = "\${userSelf}/hosts"; + default = "${userFlakeSelf}/hosts"; + defaultText = "\${userFlakeSelf}/hosts"; apply = toString; description = '' Path to directory containing host configurations that will be exported @@ -64,15 +64,15 @@ let }; profiles = mkOption { type = path; - default = "${userSelf}/profiles"; - defaultText = "\${userSelf}/profiles"; + default = "${userFlakeSelf}/profiles"; + defaultText = "\${userFlakeSelf}/profiles"; apply = x: os.mkProfileAttrs (toString x); description = "path to profiles folder that can be collected into suites"; }; userProfiles = mkOption { type = path; - default = "${userSelf}/users/profiles"; - defaultText = "\${userSelf}/users/profiles"; + default = "${userFlakeSelf}/users/profiles"; + defaultText = "\${userFlakeSelf}/users/profiles"; apply = x: os.mkProfileAttrs (toString x); description = "path to user profiles folder that can be collected into userSuites"; }; @@ -97,8 +97,8 @@ let }; users = mkOption { type = path; - default = "${userSelf}/users"; - defaultText = "\${userSelf}/users"; + default = "${userFlakeSelf}/users"; + defaultText = "\${userFlakeSelf}/users"; apply = x: os.mkProfileAttrs (toString x); description = '' path to folder containing profiles that define system users @@ -121,9 +121,9 @@ let { modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; } ''; # So unneeded extern attributes can safely be deleted - apply = x: defaults // (x { inputs = inputs // userSelf.inputs; }); + apply = x: defaults // (x { inputs = inputs // userFlakeSelf.inputs; }); description = '' - Function with argument 'inputs' that contains all devos and ''${userSelf}'s inputs. + Function with argument 'inputs' that contains all devos and ''${userFlakeSelf}'s inputs. The function should return an attribute set with modules, overlays, and specialArgs to be included across nixos and home manager configurations. Only attributes that are used should be returned. @@ -131,8 +131,8 @@ let }; overlays = mkOption { type = path; - default = "${userSelf}/overlays"; - defaultText = "\${userSelf}/overlays"; + default = "${userFlakeSelf}/overlays"; + defaultText = "\${userFlakeSelf}/overlays"; apply = x: lib.pathsToImportedAttrs (lib.pathsIn (toString x)); description = '' path to folder containing overlays which will be applied to pkgs and exported in From 9dca402914d6cd20791836d0da559adb03466aa5 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sat, 17 Apr 2021 20:56:24 -0500 Subject: [PATCH 14/21] ref: make onion with flake-utils --- lib/devos/mkPkgs.nix | 2 -- lib/flake.nix | 11 ++++++++--- lib/mkFlake/default.nix | 4 ++-- lib/mkFlake/evalArgs.nix | 4 ++-- lib/pkgs-lib/default.nix | 4 ++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index ed669e40..7fb2570d 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -12,8 +12,6 @@ lib = prev.lib.extend (lfinal: lprev: { inherit lib; inherit (lib) nixosSystem; - - utils = inputs.utils.lib; }); }) (overridesOverlay overridePkgs) diff --git a/lib/flake.nix b/lib/flake.nix index 47b9ffc2..506fdb2d 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -30,6 +30,11 @@ lists = callLibs ./lists.nix; strings = callLibs ./strings.nix; in + + utils.lib + + // + { inherit callLibs; @@ -47,19 +52,19 @@ pathsToImportedAttrs concatAttrs filterPackages; inherit (lists) pathsIn; inherit (strings) rgxToString; - }); + } + ); in { # ... but don't force that choice onto the user - lib = { + lib = utils.lib // { mkFlake = combinedLib.mkFlake; pkgs-lib = combinedLib.pkgs-lib; }; - } // diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index fbb2554e..19dd1cf1 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,4 +1,4 @@ -{ lib, utils, deploy, ... }: +{ lib, deploy, ... }: let inherit (dev) os; in @@ -31,7 +31,7 @@ let deploy.nodes = os.mkNodes deploy userFlakeSelf.nixosConfigurations; }; - systemOutputs = utils.lib.eachDefaultSystem (system: + systemOutputs = lib.eachDefaultSystem (system: let pkgs = multiPkgs.${system}; pkgs-lib = lib.pkgs-lib.${system}; diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 3f850801..b7902b83 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,4 +1,4 @@ -{ userFlakeSelf, lib, nixpkgs, utils, ... }: +{ userFlakeSelf, lib, nixpkgs, ... }: { args }: let @@ -190,7 +190,7 @@ let }; supportedSystems = mkOption { type = listOf str; - default = utils.lib.defaultSystems; + default = lib.defaultSystems; description = '' The systems supported by this flake ''; diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index ae448a45..d2dde9b0 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -1,5 +1,5 @@ -args@{ lib, utils, nixpkgs, ... }: -lib.genAttrs utils.lib.defaultSystems (system: +args@{ lib, nixpkgs, ... }: +lib.genAttrs lib.defaultSystems (system: lib.makeExtensible (final: let pkgs = import nixpkgs { inherit system; }; From be924bcb27432d1e3293a12be5675f849bfe3afc Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sat, 17 Apr 2021 21:29:45 -0500 Subject: [PATCH 15/21] ref: reduce exposure to callLibs for clarity's sake, expose which function uses final and prev, so that people can have a clearer understanding how they relate to each other in terms of dependencies. also a simple `{ lib = final; }` probably does not warrant a complete callLibs obscurization. --- lib/attrs.nix | 2 +- lib/devos/default.nix | 2 +- lib/flake.nix | 18 ++++++++++++------ lib/lists.nix | 2 +- lib/pkgs-lib/default.nix | 2 +- lib/strings.nix | 2 +- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/attrs.nix b/lib/attrs.nix index 50c72d22..1ecc2544 100644 --- a/lib/attrs.nix +++ b/lib/attrs.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib }: rec { # mapFilterAttrs :: # (name -> value -> bool ) diff --git a/lib/devos/default.nix b/lib/devos/default.nix index fb9e990f..a8ecd940 100644 --- a/lib/devos/default.nix +++ b/lib/devos/default.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib }: { # pkgImport :: Nixpkgs -> Overlays -> System -> Pkgs pkgImport = nixpkgs: overlays: system: diff --git a/lib/flake.nix b/lib/flake.nix index 506fdb2d..1810b1b8 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -21,14 +21,17 @@ let callLibs = file: import file ({ lib = final; - userFlakeInputs = {}; # TODO: Erm, this must become a proper argument to mkFlake + userFlakeNixos = {}; + userFlakeSelf = {}; + userFlakeInputs = {}; # TODO: Erm, theese must become proper arguments to mkFlake } // inputs); in with final; let - attrs = callLibs ./attrs.nix; - lists = callLibs ./lists.nix; - strings = callLibs ./strings.nix; + + attrs = import ./attrs.nix { lib = prev; }; + lists = import ./lists.nix { lib = prev; }; + strings = import ./strings.nix { lib = prev; }; in utils.lib @@ -38,7 +41,7 @@ { inherit callLibs; - os = callLibs ./devos; + os = import ./devos { lib = final; }; mkFlake = { __functor = callLibs ./mkFlake; @@ -46,7 +49,10 @@ evalOldArgs = callLibs ./mkFlake/evalOldArgs.nix; }; - pkgs-lib = callLibs ./pkgs-lib; + pkgs-lib = import ./pkgs-lib { + lib = final; + inherit nixpkgs deploy devshell; + }; inherit (attrs) mapFilterAttrs genAttrs' safeReadDir pathsToImportedAttrs concatAttrs filterPackages; diff --git a/lib/lists.nix b/lib/lists.nix index 74cf9bd4..18620412 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib }: { pathsIn = dir: let diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index d2dde9b0..a298d411 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -1,4 +1,4 @@ -args@{ lib, nixpkgs, ... }: +args@{ lib, nixpkgs, deploy, devshell }: lib.genAttrs lib.defaultSystems (system: lib.makeExtensible (final: let diff --git a/lib/strings.nix b/lib/strings.nix index 56a0861d..d411bab8 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib }: { # returns matching part of _regex_ _string_; null indicates failure. rgxToString = regex: string: From 40acfd13e319bc51a5109dbadc73d2478897da5f Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 21:45:08 -0500 Subject: [PATCH 16/21] use: makeExtensible --- lib/devos/default.nix | 20 ++++++------ lib/devos/devosSystem.nix | 6 ++-- lib/devos/mkHomeConfigurations.nix | 4 ++- lib/devos/mkHosts.nix | 8 ++--- lib/devos/mkNodes.nix | 2 +- lib/devos/mkPackages.nix | 4 ++- lib/devos/mkPkgs.nix | 6 ++-- lib/devos/mkProfileAttrs.nix | 2 +- lib/devos/mkSuites.nix | 2 +- lib/devos/recImport.nix | 2 +- lib/flake.nix | 52 +++++++++++++++--------------- 11 files changed, 57 insertions(+), 51 deletions(-) diff --git a/lib/devos/default.nix b/lib/devos/default.nix index a8ecd940..cd97181f 100644 --- a/lib/devos/default.nix +++ b/lib/devos/default.nix @@ -1,4 +1,4 @@ -{ lib }: +{ lib, utils }: { # pkgImport :: Nixpkgs -> Overlays -> System -> Pkgs pkgImport = nixpkgs: overlays: system: @@ -9,22 +9,22 @@ profileMap = map (profile: profile.default); - mkNodes = lib.callLibs ./mkNodes.nix; + mkNodes = import ./mkNodes.nix { inherit lib; }; - mkHosts = lib.callLibs ./mkHosts.nix; + mkHosts = import ./mkHosts.nix { inherit lib; }; - mkSuites = lib.callLibs ./mkSuites.nix; + mkSuites = import ./mkSuites.nix { inherit lib; }; - mkProfileAttrs = lib.callLibs ./mkProfileAttrs.nix; + mkProfileAttrs = import ./mkProfileAttrs.nix { inherit lib; }; - mkPkgs = lib.callLibs ./mkPkgs.nix; + mkPkgs = import ./mkPkgs.nix { inherit lib utils; }; - recImport = lib.callLibs ./recImport.nix; + recImport = import ./recImport.nix { inherit lib; }; - devosSystem = lib.callLibs ./devosSystem.nix; + devosSystem = import ./devosSystem.nix { inherit lib; }; - mkHomeConfigurations = lib.callLibs ./mkHomeConfigurations.nix; + mkHomeConfigurations = import ./mkHomeConfigurations.nix { inherit lib; }; - mkPackages = lib.callLibs ./mkPackages.nix; + mkPackages = import ./mkPackages.nix { inherit lib; }; } diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index 121638cb..f9a84d0f 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -1,4 +1,6 @@ -{ lib, nixpkgs, userFlakeSelf, userFlakeInputs, ... }: +{ lib }: + +{ userFlakeNixos, userFlakeSelf, userFlakeInputs }: { modules, ... } @ args: lib.nixosSystem (args // { @@ -13,7 +15,7 @@ lib.nixosSystem (args // { (args // { modules = moduleList ++ [ - "${nixpkgs}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" + "${userFlakeNixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ({ config, suites, ... }: { diff --git a/lib/devos/mkHomeConfigurations.nix b/lib/devos/mkHomeConfigurations.nix index 34c5e938..6ccfa50a 100644 --- a/lib/devos/mkHomeConfigurations.nix +++ b/lib/devos/mkHomeConfigurations.nix @@ -1,4 +1,6 @@ -{ lib, userFlakeSelf, ... }: +{ lib }: + +{ userFlakeSelf }: with lib; let diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index b11bda95..3bb010bb 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -1,6 +1,6 @@ -{ lib, nixpkgs, userFlakeInputs, userFlakeSelf, ... }: +{ lib }: -{ dir, extern, suites, overrides, multiPkgs, ... }: +{ dir, extern, suites, overrides, multiPkgs, userFlakeNixOS, userFlakeInputs, userFlakeSelf }: let defaultSystem = "x86_64-linux"; @@ -36,7 +36,7 @@ let hardware.enableRedistributableFirmware = lib.mkDefault true; nix.nixPath = [ - "nixpkgs=${nixpkgs}" + "nixpkgs=${userFlakeNixOS}" "nixos-config=${userFlakeSelf}/compat/nixos" "home-manager=${userFlakeInputs.home}" ]; @@ -45,7 +45,7 @@ let nix.registry = { devos.flake = userFlakeSelf; - nixos.flake = nixpkgs; + nixos.flake = userFlakeNixOS; override.flake = userFlakeInputs.override; }; diff --git a/lib/devos/mkNodes.nix b/lib/devos/mkNodes.nix index 7892506e..83906ce8 100644 --- a/lib/devos/mkNodes.nix +++ b/lib/devos/mkNodes.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib }: /** Synopsis: mkNodes _nixosConfigurations_ diff --git a/lib/devos/mkPackages.nix b/lib/devos/mkPackages.nix index 17cba0e2..eeac9294 100644 --- a/lib/devos/mkPackages.nix +++ b/lib/devos/mkPackages.nix @@ -1,4 +1,6 @@ -{ lib, userFlakeSelf, ... }: +{ lib }: + +{ userFlakeSelf }: { pkgs }: let diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index 7fb2570d..8fb22013 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -1,6 +1,6 @@ -{ lib, nixpkgs, userFlakeSelf, utils, userFlakeInputs, ... }: +{ lib, utils }: -{ extern, overrides }: +{ extern, overrides, userFlakeNixOS, userFlakeSelf, userFlakeInputs }: (utils.lib.eachDefaultSystem (system: let @@ -20,6 +20,6 @@ ++ extern.overlays ++ (lib.attrValues userFlakeSelf.overlays); in - { pkgs = lib.os.pkgImport nixpkgs overlays system; } + { pkgs = lib.os.pkgImport userFlakeNixOS overlays system; } ) ).pkgs diff --git a/lib/devos/mkProfileAttrs.nix b/lib/devos/mkProfileAttrs.nix index 7168b291..0a96cfb5 100644 --- a/lib/devos/mkProfileAttrs.nix +++ b/lib/devos/mkProfileAttrs.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib }: let mkProfileAttrs = /** diff --git a/lib/devos/mkSuites.nix b/lib/devos/mkSuites.nix index 0a5950bb..cb736793 100644 --- a/lib/devos/mkSuites.nix +++ b/lib/devos/mkSuites.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib }: { users, profiles, userProfiles, suites } @ args: let diff --git a/lib/devos/recImport.nix b/lib/devos/recImport.nix index e9e5da68..c96c9352 100644 --- a/lib/devos/recImport.nix +++ b/lib/devos/recImport.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib }: { dir, _import ? base: import "${dir}/${base}.nix" }: lib.mapFilterAttrs diff --git a/lib/flake.nix b/lib/flake.nix index 1810b1b8..17d4754d 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -14,24 +14,19 @@ outputs = inputs@{ self, nixpkgs, deploy, devshell, utils, ... }: let - inherit (nixpkgs) lib; - - # We work with a combined lib, internally ... - combinedLib = lib.extend (final: prev: - let callLibs = file: import file - ({ - lib = final; - userFlakeNixos = {}; - userFlakeSelf = {}; - userFlakeInputs = {}; # TODO: Erm, theese must become proper arguments to mkFlake - } // inputs); - in - with final; + lib = nixpkgs.lib.makeExtensible (self: let + callLibs = file: import file + ({ + lib = self; + userFlakeNixos = {}; + userFlakeSelf = {}; + userFlakeInputs = {}; # TODO: Erm, theese must become proper arguments to mkFlake + } // inputs); - attrs = import ./attrs.nix { lib = prev; }; - lists = import ./lists.nix { lib = prev; }; - strings = import ./strings.nix { lib = prev; }; + attrs = import ./attrs.nix { lib = nixpkgs.lib // self; }; + lists = import ./lists.nix { lib = nixpkgs.lib // self; }; + strings = import ./strings.nix { lib = nixpkgs.lib // self; }; in utils.lib @@ -39,9 +34,10 @@ // { - inherit callLibs; - - os = import ./devos { lib = final; }; + os = import ./devos { + lib = nixpkgs.lib // self; + inherit utils; + }; mkFlake = { __functor = callLibs ./mkFlake; @@ -50,12 +46,17 @@ }; pkgs-lib = import ./pkgs-lib { - lib = final; + lib = nixpkgs.lib // self; inherit nixpkgs deploy devshell; }; - inherit (attrs) mapFilterAttrs genAttrs' safeReadDir - pathsToImportedAttrs concatAttrs filterPackages; + inherit (attrs) + mapFilterAttrs + genAttrs' + safeReadDir + pathsToImportedAttrs + concatAttrs + filterPackages; inherit (lists) pathsIn; inherit (strings) rgxToString; } @@ -65,10 +66,9 @@ { - # ... but don't force that choice onto the user lib = utils.lib // { - mkFlake = combinedLib.mkFlake; - pkgs-lib = combinedLib.pkgs-lib; + inherit (lib) + mkFlake; }; } @@ -83,7 +83,7 @@ checks = { tests = import ./tests { inherit (nixpkgs') pkgs; - lib = combinedLib; + lib = nixpkgs.lib // lib; }; }; } From 6f0392b55e12b86695995e1744221bc27a382998 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 22:00:49 -0500 Subject: [PATCH 17/21] ref: cave out instances of userFLake dependencies and intject them as if functions where contructors --- lib/devos/mkHosts.nix | 6 +++++- lib/devos/mkPkgs.nix | 4 +++- lib/mkFlake/default.nix | 27 ++++++++++++++++++--------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 3bb010bb..d86de4e5 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -1,6 +1,8 @@ { lib }: -{ dir, extern, suites, overrides, multiPkgs, userFlakeNixOS, userFlakeInputs, userFlakeSelf }: +{ userFlakeNixOS, userFlakeInputs, userFlakeSelf }: + +{ dir, extern, suites, overrides, multiPkgs }: let defaultSystem = "x86_64-linux"; @@ -91,6 +93,8 @@ let }; in lib.os.devosSystem { + inherit userFlakeNixOS userFlakeInputs userFlakeSelf; + } { inherit specialArgs; system = defaultSystem; modules = modules // { inherit local lib; }; diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index 8fb22013..be32dddf 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -1,6 +1,8 @@ { lib, utils }: -{ extern, overrides, userFlakeNixOS, userFlakeSelf, userFlakeInputs }: +{ userFlakeNixOS, userFlakeSelf, userFlakeInputs }: + +{ extern, overrides }: (utils.lib.eachDefaultSystem (system: let diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 19dd1cf1..8b257066 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -3,23 +3,30 @@ let inherit (dev) os; in -_: { self, ... } @ args: +_: { self, inputs, nixos, ... } @ args: let userFlakeSelf = self; + userFlakeInputs = inputs; + userFlakeNixOS = nixos; cfg = (lib.mkFlake.evalOldArgs { inherit args; }).config; - multiPkgs = os.mkPkgs { inherit (cfg) extern overrides; }; + multiPkgs = os.mkPkgs + { inherit userFlakeSelf userFlakeInputs userFlakeNixOS; } + { inherit (cfg) extern overrides; }; outputs = { - nixosConfigurations = os.mkHosts { - inherit userFlakeSelf multiPkgs; - inherit (cfg) extern suites overrides; - dir = cfg.hosts; - }; + nixosConfigurations = os.mkHosts + { inherit userFlakeSelf userFlakeInputs userFlakeNixOS; } + { + inherit multiPkgs; + inherit (cfg) extern suites overrides; + dir = cfg.hosts; + }; - homeConfigurations = os.mkHomeConfigurations; + homeConfigurations = os.mkHomeConfigurations + { inherit userFlakeSelf; }; nixosModules = cfg.modules; @@ -36,7 +43,9 @@ let pkgs = multiPkgs.${system}; pkgs-lib = lib.pkgs-lib.${system}; # all packages that are defined in ./pkgs - legacyPackages = os.mkPackages { inherit pkgs; }; + legacyPackages = os.mkPackages + { inherit userFlakeSelf; } + { inherit pkgs; }; in { checks = pkgs-lib.tests.mkChecks { From 362cc31827d32d9d187808d4f8b66a12d683f6fd Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 22:29:28 -0500 Subject: [PATCH 18/21] fix: constructors of mkFlake function family --- lib/flake.nix | 17 ++++++----------- lib/mkFlake/default.nix | 10 +++++++--- lib/mkFlake/evalArgs.nix | 8 +++++--- lib/mkFlake/evalOldArgs.nix | 6 ++++-- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/lib/flake.nix b/lib/flake.nix index 17d4754d..14e2947a 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -16,14 +16,6 @@ lib = nixpkgs.lib.makeExtensible (self: let - callLibs = file: import file - ({ - lib = self; - userFlakeNixos = {}; - userFlakeSelf = {}; - userFlakeInputs = {}; # TODO: Erm, theese must become proper arguments to mkFlake - } // inputs); - attrs = import ./attrs.nix { lib = nixpkgs.lib // self; }; lists = import ./lists.nix { lib = nixpkgs.lib // self; }; strings = import ./strings.nix { lib = nixpkgs.lib // self; }; @@ -40,9 +32,12 @@ }; mkFlake = { - __functor = callLibs ./mkFlake; - evalArgs = callLibs ./mkFlake/evalArgs.nix; - evalOldArgs = callLibs ./mkFlake/evalOldArgs.nix; + __functor = import ./mkFlake { + lib = nixpkgs.lib // self; + inherit deploy; + }; + evalArgs = import ./mkFlake/evalArgs.nix { lib = nixpkgs.lib // self; }; + evalOldArgs = import ./mkFlake/evalOldArgs.nix { lib = nixpkgs.lib // self; }; }; pkgs-lib = import ./pkgs-lib { diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 8b257066..217baa6b 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,6 +1,6 @@ -{ lib, deploy, ... }: +{ lib, deploy }: let - inherit (dev) os; + inherit (lib) os; in _: { self, inputs, nixos, ... } @ args: @@ -10,7 +10,11 @@ let userFlakeInputs = inputs; userFlakeNixOS = nixos; - cfg = (lib.mkFlake.evalOldArgs { inherit args; }).config; + cfg = ( + lib.mkFlake.evalOldArgs + { inherit userFlakeSelf userFlakeInputs; } + { inherit args; } + ).config; multiPkgs = os.mkPkgs { inherit userFlakeSelf userFlakeInputs userFlakeNixOS; } diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index b7902b83..166fcf0c 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,4 +1,6 @@ -{ userFlakeSelf, lib, nixpkgs, ... }: +{ lib }: + +{ userFlakeSelf, userFlakeNixOS }: { args }: let @@ -54,7 +56,7 @@ let options = with types; { input = mkOption { type = flakeType; - default = nixpkgs; + default = userFlakeNixOS; description = '' nixpkgs flake input to use for this channel ''; @@ -199,7 +201,7 @@ let let default = { nixpkgs = { - input = nixpkgs; + input = userFlakeNixOS; }; }; in diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix index 25dd7c9d..d15fbc97 100644 --- a/lib/mkFlake/evalOldArgs.nix +++ b/lib/mkFlake/evalOldArgs.nix @@ -1,4 +1,6 @@ -{ userFlakeSelf, lib, inputs, ... }: +{ lib }: + +{ userFlakeSelf, userFlakeInputs }: { args }: let @@ -121,7 +123,7 @@ let { modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; } ''; # So unneeded extern attributes can safely be deleted - apply = x: defaults // (x { inputs = inputs // userFlakeSelf.inputs; }); + apply = x: defaults // (x { inputs = userFlakeInputs // userFlakeSelf.inputs; }); description = '' Function with argument 'inputs' that contains all devos and ''${userFlakeSelf}'s inputs. The function should return an attribute set with modules, overlays, and From 8134350545305cc970069ea92fe9dbadbc346840 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 22:40:53 -0500 Subject: [PATCH 19/21] ref: simplify pkgs-lib deps injection --- lib/pkgs-lib/default.nix | 23 ++++++----------------- lib/pkgs-lib/shell/default.nix | 7 +++++-- lib/pkgs-lib/tests/default.nix | 4 +++- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index a298d411..1b7c6422 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -1,20 +1,9 @@ -args@{ lib, nixpkgs, deploy, devshell }: -lib.genAttrs lib.defaultSystems (system: - lib.makeExtensible (final: - let - pkgs = import nixpkgs { inherit system; }; - callLibs = file: import file - (args // { - inherit pkgs system; - pkgs-lib = final; - }); - in - with final; - { - inherit callLibs; +{ lib, nixpkgs, deploy, devshell }: - tests = callLibs ./tests; - shell = callLibs ./shell; +lib.genAttrs + lib.defaultSystems (system: + { + tests = import ./tests { inherit lib deploy nixpkgs pkgs system; }; + shell = import ./shell { inherit lib devshell deploy nixpkgs system; }; } ) -) diff --git a/lib/pkgs-lib/shell/default.nix b/lib/pkgs-lib/shell/default.nix index 71c6c29e..e43155b1 100644 --- a/lib/pkgs-lib/shell/default.nix +++ b/lib/pkgs-lib/shell/default.nix @@ -1,14 +1,17 @@ -{ lib, devshell, deploy, system, nixpkgs, ... }: +{ lib, nixpkgs, devshell, deploy, system }: let overlays = [ + devshell.overlay + (final: prev: { deploy-rs = deploy.packages.${prev.system}.deploy-rs; }) + ]; - pkgs = lib.os.pkgImport nixpkgs overlays system; + pkgs = import nixpkgs { inherit system overlays;; config = {}; }; flk = pkgs.callPackage ./flk.nix { }; diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index a72ade6e..6111acde 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -1,5 +1,7 @@ -{ pkgs, system, deploy, nixpkgs, lib, ... }: +{ lib, nixpkgs, deploy, system }: let + pkgs = import nixpkgs { inherit system; overlays = []; config = {}; }; + mkChecks = { hosts, nodes, homes ? { } }: let deployHosts = lib.filterAttrs From a714cf466dc6e104fedd616e51bb111e4327766b Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 23:48:19 -0500 Subject: [PATCH 20/21] fix: various left-overs --- extern/default.nix | 4 ---- flake.lock | 2 +- flake.nix | 2 +- lib/devos/devosSystem.nix | 4 ++-- lib/devos/mkHosts.nix | 8 ++++---- lib/mkFlake/evalOldArgs.nix | 8 ++++++++ lib/pkgs-lib/default.nix | 2 +- lib/pkgs-lib/shell/default.nix | 2 +- profiles/core/default.nix | 1 - 9 files changed, 18 insertions(+), 15 deletions(-) diff --git a/extern/default.nix b/extern/default.nix index 4ca9df6b..19c1bae6 100644 --- a/extern/default.nix +++ b/extern/default.nix @@ -7,10 +7,6 @@ overlays = [ nur.overlay - devshell.overlay - (final: prev: { - deploy-rs = deploy.packages.${prev.system}.deploy-rs; - }) pkgs.overlay ]; diff --git a/flake.lock b/flake.lock index 531c9813..7d108f46 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-/SJJ8u/qBnCtMbMxBmDNBDnLWnmro2ioi35gL45hP9w=", + "narHash": "sha256-Mf67M0twCyNmRQxnhH51f6VroHaCwJKvFDMc1Wc7pt8=", "path": "./lib", "type": "path" }, diff --git a/flake.nix b/flake.nix index 443c9b98..4bf5bdb7 100644 --- a/flake.nix +++ b/flake.nix @@ -35,7 +35,7 @@ outputs = inputs@{ self, devos, nixos, nur, ... }: devos.lib.mkFlake { - inherit self; + inherit self inputs nixos; hosts = ./hosts; packages = import ./pkgs; suites = import ./suites; diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index f9a84d0f..6ea50dab 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -1,6 +1,6 @@ { lib }: -{ userFlakeNixos, userFlakeSelf, userFlakeInputs }: +{ userFlakeNixOS, userFlakeSelf, userFlakeInputs }: { modules, ... } @ args: lib.nixosSystem (args // { @@ -15,7 +15,7 @@ lib.nixosSystem (args // { (args // { modules = moduleList ++ [ - "${userFlakeNixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" + "${userFlakeNixOS}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ({ config, suites, ... }: { diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index d86de4e5..d4a785fe 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -65,7 +65,7 @@ let # Everything in `./modules/list.nix`. flakeModules = { imports = builtins.attrValues userFlakeSelf.nixosModules ++ extern.modules; }; - cachix = ../../cachix.nix; + cachix = "${userFlakeSelf}/cachix.nix"; }; specialArgs = extern.specialArgs // { suites = suites.system; }; @@ -84,12 +84,12 @@ let hosts = builtins.mapAttrs (_: host: host.config) (removeAttrs hosts [ hostName ]); }; - }; - lib = { + lib = { inherit specialArgs; }; lib.testModule = { imports = builtins.attrValues modules; }; + }; in lib.os.devosSystem { @@ -97,7 +97,7 @@ let } { inherit specialArgs; system = defaultSystem; - modules = modules // { inherit local lib; }; + modules = modules // { inherit local; }; }; hosts = lib.os.recImport diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix index d15fbc97..2cf92214 100644 --- a/lib/mkFlake/evalOldArgs.nix +++ b/lib/mkFlake/evalOldArgs.nix @@ -22,6 +22,14 @@ let type = addCheck attrs lib.isStorePath; description = "The flake to create the devos outputs for"; }; + nixos = mkOption { + type = addCheck attrs lib.isStorePath; + description = "The default nixpkgs channel of the devos"; + }; + inputs = mkOption { + type = addCheck attrs lib.isStorePath; + description = "All inptus of the devos"; + }; hosts = mkOption { type = path; default = "${userFlakeSelf}/hosts"; diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index 1b7c6422..40b451c2 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -3,7 +3,7 @@ lib.genAttrs lib.defaultSystems (system: { - tests = import ./tests { inherit lib deploy nixpkgs pkgs system; }; + tests = import ./tests { inherit lib deploy nixpkgs system; }; shell = import ./shell { inherit lib devshell deploy nixpkgs system; }; } ) diff --git a/lib/pkgs-lib/shell/default.nix b/lib/pkgs-lib/shell/default.nix index e43155b1..7744f68f 100644 --- a/lib/pkgs-lib/shell/default.nix +++ b/lib/pkgs-lib/shell/default.nix @@ -11,7 +11,7 @@ let ]; - pkgs = import nixpkgs { inherit system overlays;; config = {}; }; + pkgs = import nixpkgs { inherit system overlays; config = {}; }; flk = pkgs.callPackage ./flk.nix { }; diff --git a/profiles/core/default.nix b/profiles/core/default.nix index f5a654c0..077ffa26 100644 --- a/profiles/core/default.nix +++ b/profiles/core/default.nix @@ -11,7 +11,6 @@ in binutils coreutils curl - deploy-rs direnv dnsutils dosfstools From 24dbb2b3231b5a9f4a9aae57ef90436d59db300b Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 11 Apr 2021 22:27:59 -0700 Subject: [PATCH 21/21] add mkFlakeDoc to pkgs-lib to build options doc --- lib/flake.nix | 3 +++ lib/jobs/default.nix | 5 +++++ lib/jobs/mkFlakeDoc.nix | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 lib/jobs/default.nix create mode 100644 lib/jobs/mkFlakeDoc.nix diff --git a/lib/flake.nix b/lib/flake.nix index 14e2947a..4120e83a 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -57,9 +57,12 @@ } ); + jobs = import ./jobs { inherit nixpkgs; lib = nixpkgs.lib // lib; }; + in { + inherit jobs; lib = utils.lib // { inherit (lib) diff --git a/lib/jobs/default.nix b/lib/jobs/default.nix new file mode 100644 index 00000000..2f108ed7 --- /dev/null +++ b/lib/jobs/default.nix @@ -0,0 +1,5 @@ +{ nixpkgs, lib, system ? "x86_64-linux" }: let + pkgs = import nixpkgs { inherit system; overlays = []; config = {}; }; +in { + mkFlakeDoc = import ./mkFlakeDoc.nix { inherit pkgs lib; }; +} diff --git a/lib/jobs/mkFlakeDoc.nix b/lib/jobs/mkFlakeDoc.nix new file mode 100644 index 00000000..45ddeed5 --- /dev/null +++ b/lib/jobs/mkFlakeDoc.nix @@ -0,0 +1,35 @@ +{ pkgs, lib, ... }: +let + singleDoc = name: value: '' + ## ${name} + ${value.description} + ${lib.optionalString (value ? type) '' + *_Type_*: + ${value.type} + ''} + ${lib.optionalString (value ? default) '' + *_Default_* + ``` + ${builtins.toJSON value.default} + ``` + ''} + ${lib.optionalString (value ? example) '' + *_Example_* + ``` + ${value.example} + ``` + ''} + ''; + + options = ( + lib.mkFlake.evalArgs + { userFlakeSelf = {}; userFlakeNixOS = {}; } + { args = { }; } + ).options; + + processedOptions = (pkgs.nixosOptionsDoc { inherit options; }).optionsNix; + + fullDoc = lib.concatStringsSep "" (lib.mapAttrsToList singleDoc processedOptions); +in +pkgs.writeText "devosOptions.md" fullDoc +