From b7bcaea497ed24c0e26266f3d1b1cdf32d1c8bd1 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 11 Apr 2021 20:01:13 -0700 Subject: [PATCH 01/91] 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/91] 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/91] 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/91] 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/91] 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/91] 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/91] 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/91] 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/91] 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/91] 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/91] 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/91] 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/91] 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/91] 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/91] 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/91] 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/91] 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/91] 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/91] 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/91] 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/91] 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 + From f3defb486d1e79c62e5188da297743d12e8500da Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 12 Apr 2021 08:42:22 -0700 Subject: [PATCH 22/91] used coercedTo for typing and improve options allow lists, nested lists, and non-lists for list like options drop config..externalModules --- lib/mkFlake/evalArgs.nix | 89 ++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 49 deletions(-) diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 166fcf0c..6560f91b 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -18,37 +18,32 @@ let /* Custom types needed for arguments */ - moduleType = with types; anything // { + moduleType = with types; pathTo (anything // { inherit (submodule { }) check; description = "valid module"; - }; - overlayType = types.anything // { + }); + overlayType = pathTo (types.anything // { check = builtins.isFunction; description = "valid Nixpkgs overlay"; - }; + }); systemType = types.enum config.supportedSystems; flakeType = with types; (addCheck attrs lib.isStorePath) // { description = "nix flake"; }; - # Applys maybeImport during merge and before check + # Apply 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); - }; + pathTo = elemType: coercedTo path maybeImort elemType; + # Accepts single item or a list + # apply keys end up with a list + # This should not be used if expecting a nested list + # all lists will get flattened by this + coercedListOf = elemType: + let coerceToList = x: flatten (singleton x); in + with types; coercedTo elemType coerceToList (listOf elemType); + + pathToListOf = x: pathTo (coercedListOf x); /* Submodules needed for API containers */ @@ -62,7 +57,7 @@ let ''; }; overlays = mkOption { - type = pathTo (listOf overlayType); + type = pathToListOf overlayType; default = [ ]; description = '' overlays to apply to this channel @@ -70,7 +65,7 @@ let ''; }; externalOverlays = mkOption { - type = pathTo (listOf overlayType); + type = pathToListOf overlayType; default = [ ]; description = '' overlays to apply to the channel that don't get exported to the flake output @@ -104,14 +99,21 @@ let ''; }; modules = mkOption { - type = pathTo moduleType; + type = pathToListOf moduleType; default = [ ]; description = '' The configuration for this config ''; }; + }; + }; + + # This is only needed for configDefaults + # modules in each config don't get exported + externalModulesModule = { + options = { externalModules = mkOption { - type = pathTo moduleType; + type = pathToListOf moduleType; default = [ ]; description = '' The configuration for this config @@ -126,14 +128,17 @@ let includeConfigsModule = { name, ... }: { options = with types; { configDefaults = mkOption { - type = submodule configModule; + type = submodule [ configModule externalModulesModule ]; default = { }; description = '' - defaults for all configs + Defaults for all configs. + the modules passed under configDefault will be exported + to the '${name}Modules' flake output. + They will also be added to all configs. ''; }; configs = mkOption { - type = pathTo (attrsOf (submodule configModule)); + type = attrsOf (submodule configModule); default = { }; description = '' configurations to include in the ${name}Configurations output @@ -142,30 +147,16 @@ let }; }; - # Options to import: modules, profiles, suites - importsModule = { name, ... }: { + # profiles and suites - which are profile collections + profilesModule = { name, ... }: { options = with types; { - modules = mkOption { - type = pathTo (listOf moduleType); - default = [ ]; - apply = lib.pathsToImportedAttrs; - description = '' - list of modules to include in confgurations and export in '${name}Modules' output - ''; - }; - externalModules = mkOption { - type = pathTo (listOf moduleType); - default = [ ]; - apply = lib.pathsToImportedAttrs; - description = '' - list of modules to include in confguration but these are not exported to the '${name}Modules' output - ''; - }; profiles = mkOption { - type = path; - default = "${userFlakeSelf}/profiles"; - defaultText = "\${userFlakeSelf}/profiles"; - apply = x: os.mkProfileAttrs (toString x); + type = coercedListOf path; + default = [ ]; + apply = list: + # Merge a list of profiles to one set + let profileList = map (x: os.mkProfileAttrs (toString x)) list; in + foldl (a: b: a // b) { } profileList; description = "path to profiles folder that can be collected into suites"; }; suites = mkOption { From eea4e40d7e0d996bc2d0091fd4be3bedef22cf32 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Wed, 21 Apr 2021 21:44:08 -0500 Subject: [PATCH 23/91] ref: config -> hosts | nixos -> os in devos, we differentiate clearly between home and os configuration, reason for which we are more precise by not naming after the (more generic) fup API. --- lib/mkFlake/evalArgs.nix | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 6560f91b..6e5c2cfc 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -82,63 +82,63 @@ let }; }; - configModule = { + hostModule = { options = with types; { system = mkOption { type = systemType; default = "x86_64-linux"; description = '' - system for this config + system for this host ''; }; channelName = mkOption { type = types.enum (builtins.attrValues config.channels); default = "nixpkgs"; description = '' - Channel this config should follow + Channel this host should follow ''; }; modules = mkOption { type = pathToListOf moduleType; default = [ ]; description = '' - The configuration for this config + The configuration for this host ''; }; }; }; - # This is only needed for configDefaults - # modules in each config don't get exported + # This is only needed for hostDefaults + # modules in each host don't get exported externalModulesModule = { options = { externalModules = mkOption { type = pathToListOf moduleType; default = [ ]; description = '' - The configuration for this config + The configuration for this host ''; }; }; }; # Home-manager's configs get exported automatically from nixos.hosts - # So there is no need for a config options in the home namespace + # So there is no need for a host options in the home namespace # This is only needed for nixos - includeConfigsModule = { name, ... }: { + includeHostsModule = { name, ... }: { options = with types; { - configDefaults = mkOption { - type = submodule [ configModule externalModulesModule ]; + hostDefaults = mkOption { + type = submodule [ hostModule externalModulesModule ]; default = { }; description = '' - Defaults for all configs. - the modules passed under configDefault will be exported + Defaults for all hosts. + the modules passed under hostDefaults will be exported to the '${name}Modules' flake output. - They will also be added to all configs. + They will also be added to all hosts. ''; }; - configs = mkOption { - type = attrsOf (submodule configModule); + hosts = mkOption { + type = attrsOf (submodule hostModule); default = { }; description = '' configurations to include in the ${name}Configurations output @@ -204,8 +204,8 @@ let nixpkgs channels to create ''; }; - nixos = mkOption { - type = submodule [ includeConfigsModule importsModule ]; + os = mkOption { + type = submodule [ includeHostsModule importsModule ]; default = { }; description = '' hosts, modules, suites, and profiles for nixos From fe9ba26561d42f97bbc77d257cdd2823e98b4b2b Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 23 Apr 2021 17:59:01 -0700 Subject: [PATCH 24/91] evalArgs: cleanup module and type references fix pathTo and coercedList types add modulesModule to also include modules option under home --- lib/mkFlake/evalArgs.nix | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 6e5c2cfc..b162ad1a 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -33,7 +33,7 @@ let # Apply maybeImport during merge and before check # To simplify apply keys and improve type checking - pathTo = elemType: coercedTo path maybeImort elemType; + pathTo = elemType: with types; coercedTo path maybeImport elemType; # Accepts single item or a list # apply keys end up with a list @@ -98,13 +98,7 @@ let Channel this host should follow ''; }; - modules = mkOption { - type = pathToListOf moduleType; - default = [ ]; - description = '' - The configuration for this host - ''; - }; + }; }; @@ -122,13 +116,25 @@ let }; }; + modulesModule = { + options = { + modules = mkOption { + type = pathToListOf moduleType; + default = [ ]; + description = '' + modules to include + ''; + }; + }; + }; + # Home-manager's configs get exported automatically from nixos.hosts # So there is no need for a host options in the home namespace # This is only needed for nixos includeHostsModule = { name, ... }: { options = with types; { hostDefaults = mkOption { - type = submodule [ hostModule externalModulesModule ]; + type = submodule [ hostModule externalModulesModule modulesModule ]; default = { }; description = '' Defaults for all hosts. @@ -138,7 +144,7 @@ let ''; }; hosts = mkOption { - type = attrsOf (submodule hostModule); + type = attrsOf (submodule [ hostModule modulesModule ]); default = { }; description = '' configurations to include in the ${name}Configurations output @@ -205,14 +211,14 @@ let ''; }; os = mkOption { - type = submodule [ includeHostsModule importsModule ]; + type = submodule [ includeHostsModule profilesModule ]; default = { }; description = '' hosts, modules, suites, and profiles for nixos ''; }; home = mkOption { - type = submodule importsModule; + type = submodule [ profilesModule modulesModule ]; default = { }; description = '' hosts, modules, suites, and profiles for home-manager From eab0bf074c221a5dcd810aa587dfac5b17d01ae5 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 23 Apr 2021 18:13:03 -0700 Subject: [PATCH 25/91] lib: one line for arguments, drop userFlake* Also format all files and add a flake.lock for lib for a folder thats meant to work on other flakes theres never a reason it should need to refer to itself, only other flakes. So "self" and "inputs" are better namings for these variables. The userFlake* is redundant and confusing, when trying to call the functions its hard to figure out how to use them when there are now two lines of arguments to figure out. --- flake.lock | 10 +- lib/devos/default.nix | 2 +- lib/devos/devosSystem.nix | 13 ++- lib/devos/mkHomeConfigurations.nix | 4 +- lib/devos/mkHosts.nix | 32 +++---- lib/devos/mkPackages.nix | 5 +- lib/devos/mkPkgs.nix | 12 +-- lib/devos/mkProfileAttrs.nix | 16 ++-- lib/flake.lock | 147 +++++++++++++++++++++++++++++ lib/flake.nix | 135 +++++++++++++------------- lib/jobs/default.nix | 8 +- lib/jobs/mkFlakeDoc.nix | 4 +- lib/mkFlake/default.nix | 34 +++---- lib/mkFlake/evalArgs.nix | 10 +- lib/mkFlake/evalOldArgs.nix | 28 +++--- lib/pkgs-lib/default.nix | 8 +- lib/pkgs-lib/shell/default.nix | 2 +- lib/pkgs-lib/tests/default.nix | 11 +-- lib/tests/default.nix | 46 ++++----- 19 files changed, 328 insertions(+), 199 deletions(-) create mode 100644 lib/flake.lock diff --git a/flake.lock b/flake.lock index f2b65a39..00b07283 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-aGpcPxOBIPnwj6uLNtpKefZjEbDkZnMHZ2mH12veHnY=", + "narHash": "sha256-LvO5VwFNFzb2xbmgw+fWhkrRY1KMlp5vxqQU/BqS0H8=", "path": "./lib", "type": "path" }, @@ -280,7 +280,7 @@ ] }, "locked": { - "narHash": "sha256-XG4TOZObj2Wd8KiqnHgtlWjjMbJOIJB7+DxUFzMCXw8=", + "narHash": "sha256-Zs7dc0dNNa0Z3//+Gckxj7SKrMqVovY0xZZ1z8xWnEg=", "path": "./pkgs", "type": "path" }, @@ -337,11 +337,11 @@ }, "utils_2": { "locked": { - "lastModified": 1618217525, - "narHash": "sha256-WGrhVczjXTiswQaoxQ+0PTfbLNeOQM6M36zvLn78AYg=", + "lastModified": 1618868421, + "narHash": "sha256-vyoJhLV6cJ8/tWz+l9HZLIkb9Rd9esE7p+0RL6zDR6Y=", "owner": "numtide", "repo": "flake-utils", - "rev": "c6169a2772643c4a93a0b5ac1c61e296cba68544", + "rev": "eed214942bcfb3a8cc09eb3b28ca7d7221e44a94", "type": "github" }, "original": { diff --git a/lib/devos/default.nix b/lib/devos/default.nix index 05ec38fc..9a3118f5 100644 --- a/lib/devos/default.nix +++ b/lib/devos/default.nix @@ -9,7 +9,7 @@ profileMap = list: map (profile: profile.default) (lib.flatten list); - mkNodes = import ./mkNodes.nix { inherit lib; }; + mkNodes = import ./mkNodes.nix { inherit lib; }; mkHosts = import ./mkHosts.nix { inherit lib; }; diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index 6ea50dab..c27a5a88 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -1,8 +1,7 @@ { lib }: -{ userFlakeNixOS, userFlakeSelf, userFlakeInputs }: - -{ modules, ... } @ args: +{ self, nixos, inputs, modules, ... } @ allArgs: +let args = builtins.removeAttrs allArgs [ "self" "nixos" "inputs" ]; in lib.nixosSystem (args // { modules = let @@ -15,7 +14,7 @@ lib.nixosSystem (args // { (args // { modules = moduleList ++ [ - "${userFlakeNixOS}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" + "${nixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ({ config, suites, ... }: { @@ -25,15 +24,15 @@ lib.nixosSystem (args // { disabledModules = map (x: [ x ]) (lib.remove modules.core suites.allProfiles); - nix.registry = lib.mapAttrs (n: v: { flake = v; }) userFlakeInputs; + nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs; isoImage.isoBaseName = "nixos-" + config.networking.hostName; isoImage.contents = [{ - source = userFlakeSelf; + source = self; target = "/devos/"; }]; isoImage.storeContents = [ - userFlakeSelf.devShell.${config.nixpkgs.system} + self.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 6ccfa50a..3a07ba82 100644 --- a/lib/devos/mkHomeConfigurations.nix +++ b/lib/devos/mkHomeConfigurations.nix @@ -1,6 +1,6 @@ { lib }: -{ userFlakeSelf }: +nixosConfigurations: with lib; let @@ -8,7 +8,7 @@ let mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) config.config.system.build.homes; - hmConfigs = mapAttrs mkHomes userFlakeSelf.nixosConfigurations; + hmConfigs = mapAttrs mkHomes nixosConfigurations; in foldl recursiveUpdate { } (attrValues hmConfigs) diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 3dc811ed..2316da33 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -1,8 +1,6 @@ -{ lib }: +{ lib }: -{ userFlakeNixOS, userFlakeInputs, userFlakeSelf }: - -{ dir, extern, suites, overrides, multiPkgs }: +{ self, nixos, inputs, dir, extern, suites, overrides, multiPkgs }: let defaultSystem = "x86_64-linux"; @@ -31,24 +29,24 @@ let useUserPackages = true; extraSpecialArgs = extern.userSpecialArgs // { suites = suites.user; }; - sharedModules = extern.userModules ++ (builtins.attrValues userFlakeSelf.homeModules); + sharedModules = extern.userModules ++ (builtins.attrValues self.homeModules); }; users.mutableUsers = lib.mkDefault false; hardware.enableRedistributableFirmware = lib.mkDefault true; nix.nixPath = [ - "nixpkgs=${userFlakeNixOS}" - "nixos-config=${userFlakeSelf}/lib/compat/nixos" - "home-manager=${userFlakeInputs.home}" + "nixpkgs=${nixos}" + "nixos-config=${self}/lib/compat/nixos" + "home-manager=${inputs.home}" ]; nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; nix.registry = { - devos.flake = userFlakeSelf; - nixos.flake = userFlakeNixOS; - override.flake = userFlakeInputs.override; + devos.flake = self; + nixos.flake = nixos; + override.flake = inputs.override; }; nix.package = pkgs.nixFlakes; @@ -59,13 +57,13 @@ let } ''; - system.configurationRevision = lib.mkIf (userFlakeSelf ? rev) userFlakeSelf.rev; + system.configurationRevision = lib.mkIf (self ? rev) self.rev; }; # Everything in `./modules/list.nix`. - flakeModules = { imports = builtins.attrValues userFlakeSelf.nixosModules ++ extern.modules; }; + flakeModules = { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; - cachix = let rootCachix = "${userFlakeSelf}/cachix.nix"; in + cachix = let rootCachix = "${self}/cachix.nix"; in if builtins.pathExists rootCachix then rootCachix else { } @@ -84,7 +82,7 @@ let networking = { inherit hostName; }; _module.args = { - self = userFlakeSelf; + self = self; hosts = builtins.mapAttrs (_: host: host.config) (removeAttrs hosts [ hostName ]); }; @@ -97,9 +95,7 @@ let }; in lib.os.devosSystem { - inherit userFlakeNixOS userFlakeInputs userFlakeSelf; - } { - inherit specialArgs; + inherit self nixos inputs specialArgs; system = defaultSystem; modules = modules // { inherit local; }; }; diff --git a/lib/devos/mkPackages.nix b/lib/devos/mkPackages.nix index eeac9294..d8992685 100644 --- a/lib/devos/mkPackages.nix +++ b/lib/devos/mkPackages.nix @@ -1,10 +1,7 @@ { lib }: -{ userFlakeSelf }: - -{ pkgs }: +{ overlay, overlays, pkgs }: let - 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 be32dddf..a7cf2366 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -1,12 +1,10 @@ { lib, utils }: -{ userFlakeNixOS, userFlakeSelf, userFlakeInputs }: - -{ extern, overrides }: +{ self, nixos, inputs, extern, overrides }: (utils.lib.eachDefaultSystem (system: let - overridePkgs = lib.os.pkgImport userFlakeInputs.override [ ] system; + overridePkgs = lib.os.pkgImport inputs.override [ ] system; overridesOverlay = overrides.packages; overlays = [ @@ -17,11 +15,11 @@ }); }) (overridesOverlay overridePkgs) - userFlakeSelf.overlay + self.overlay ] ++ extern.overlays - ++ (lib.attrValues userFlakeSelf.overlays); + ++ (lib.attrValues self.overlays); in - { pkgs = lib.os.pkgImport userFlakeNixOS overlays system; } + { pkgs = lib.os.pkgImport nixos overlays system; } ) ).pkgs diff --git a/lib/devos/mkProfileAttrs.nix b/lib/devos/mkProfileAttrs.nix index 0a96cfb5..cdfc32e7 100644 --- a/lib/devos/mkProfileAttrs.nix +++ b/lib/devos/mkProfileAttrs.nix @@ -2,16 +2,16 @@ let mkProfileAttrs = /** - Synopsis: mkProfileAttrs _path_ + Synopsis: mkProfileAttrs _path_ - Recursively collect the subdirs of _path_ containing a default.nix into attrs. - This sets a contract, eliminating ambiguity for _default.nix_ living under the - profile directory. + Recursively collect the subdirs of _path_ containing a default.nix into attrs. + This sets a contract, eliminating ambiguity for _default.nix_ living under the + profile directory. - Example: - let profiles = mkProfileAttrs ./profiles; in - assert profiles ? core.default; 0 - **/ + Example: + let profiles = mkProfileAttrs ./profiles; in + assert profiles ? core.default; 0 + **/ dir: let imports = diff --git a/lib/flake.lock b/lib/flake.lock new file mode 100644 index 00000000..f70c491f --- /dev/null +++ b/lib/flake.lock @@ -0,0 +1,147 @@ +{ + "nodes": { + "deploy": { + "inputs": { + "flake-compat": "flake-compat", + "naersk": "naersk", + "nixpkgs": "nixpkgs", + "utils": "utils" + }, + "locked": { + "lastModified": 1616406726, + "narHash": "sha256-n9zmgxR03QNrvs9/fHewqE0j3SjL7Y+cglBCFu3U3rg=", + "owner": "serokell", + "repo": "deploy-rs", + "rev": "9e405fbc5ab5bacbd271fd78c6b6b6877c4d9f8d", + "type": "github" + }, + "original": { + "owner": "serokell", + "repo": "deploy-rs", + "type": "github" + } + }, + "devshell": { + "locked": { + "lastModified": 1618523768, + "narHash": "sha256-Gev9da35pHUey3kGz/zrJFc/9ICs++vPCho7qB1mqd8=", + "owner": "numtide", + "repo": "devshell", + "rev": "709fe4d04a9101c9d224ad83f73416dce71baf21", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "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" + } + }, + "naersk": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "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" + } + }, + "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" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1619244632, + "narHash": "sha256-IDcbMRnyKO9WlQ5xzIlM3HfWAUKTy+3xSd+CvDGiLgE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5cecebfb2f76da7b93f19967e99b3ff4fb4d2850", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "deploy": "deploy", + "devshell": "devshell", + "nixpkgs": "nixpkgs_2", + "utils": "utils_2" + } + }, + "utils": { + "locked": { + "lastModified": 1610051610, + "narHash": "sha256-U9rPz/usA1/Aohhk7Cmc2gBrEEKRzcW4nwPWMPwja4Y=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3982c9903e93927c2164caa727cd3f6a0e6d14cc", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "utils_2": { + "locked": { + "lastModified": 1618868421, + "narHash": "sha256-vyoJhLV6cJ8/tWz+l9HZLIkb9Rd9esE7p+0RL6zDR6Y=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "eed214942bcfb3a8cc09eb3b28ca7d7221e44a94", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/lib/flake.nix b/lib/flake.nix index 4120e83a..c9bd99a5 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -4,87 +4,84 @@ inputs = { deploy.url = "github:serokell/deploy-rs"; - deploy.inputs = { - utils.follows = "utils"; - }; devshell.url = "github:numtide/devshell"; utils.url = "github:numtide/flake-utils"; - }; - outputs = inputs@{ self, nixpkgs, deploy, devshell, utils, ... }: let - - lib = nixpkgs.lib.makeExtensible (self: - let - 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 - - // - - { - os = import ./devos { - lib = nixpkgs.lib // self; - inherit utils; - }; - - mkFlake = { - __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 { - lib = nixpkgs.lib // self; - inherit nixpkgs deploy devshell; - }; - - inherit (attrs) - mapFilterAttrs - genAttrs' - safeReadDir - pathsToImportedAttrs - concatAttrs - filterPackages; - inherit (lists) pathsIn; - inherit (strings) rgxToString; - } - ); - - jobs = import ./jobs { inherit nixpkgs; lib = nixpkgs.lib // lib; }; - - in - - { - inherit jobs; - - lib = utils.lib // { - inherit (lib) - mkFlake; - }; - - } - - // - - utils.lib.eachDefaultSystem (system: + outputs = inputs@{ self, nixpkgs, deploy, devshell, utils, ... }: let - nixpkgs' = import nixpkgs { inherit system; overlays = []; config = {}; }; + + lib = nixpkgs.lib.makeExtensible (self: + let + 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 + + // + + { + os = import ./devos { + lib = nixpkgs.lib // self; + inherit utils; + }; + + mkFlake = { + __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 { + lib = nixpkgs.lib // self; + inherit nixpkgs deploy devshell; + }; + + inherit (attrs) + mapFilterAttrs + genAttrs' + safeReadDir + pathsToImportedAttrs + concatAttrs + filterPackages; + inherit (lists) pathsIn; + inherit (strings) rgxToString; + } + ); + + jobs = import ./jobs { inherit nixpkgs; lib = nixpkgs.lib // lib; }; + in + + { + inherit jobs; + + lib = utils.lib // { + inherit (lib) + mkFlake; + }; + + } + + // + + utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + in { checks = { tests = import ./tests { - inherit (nixpkgs') pkgs; + inherit pkgs; lib = nixpkgs.lib // lib; }; }; } - ); + ); } diff --git a/lib/jobs/default.nix b/lib/jobs/default.nix index 2f108ed7..5e9cff28 100644 --- a/lib/jobs/default.nix +++ b/lib/jobs/default.nix @@ -1,5 +1,7 @@ -{ nixpkgs, lib, system ? "x86_64-linux" }: let - pkgs = import nixpkgs { inherit system; overlays = []; config = {}; }; -in { +{ 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 index 45ddeed5..5a13d9f4 100644 --- a/lib/jobs/mkFlakeDoc.nix +++ b/lib/jobs/mkFlakeDoc.nix @@ -22,9 +22,7 @@ let ''; options = ( - lib.mkFlake.evalArgs - { userFlakeSelf = {}; userFlakeNixOS = {}; } - { args = { }; } + lib.mkFlake.evalArgs { nixos = "nixos"; args = { }; } ).options; processedOptions = (pkgs.nixosOptionsDoc { inherit options; }).optionsNix; diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 217baa6b..d086283a 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -6,31 +6,26 @@ in _: { self, inputs, nixos, ... } @ args: let - userFlakeSelf = self; - userFlakeInputs = inputs; - userFlakeNixOS = nixos; - cfg = ( lib.mkFlake.evalOldArgs - { inherit userFlakeSelf userFlakeInputs; } - { inherit args; } + { inherit self inputs args; } ).config; multiPkgs = os.mkPkgs - { inherit userFlakeSelf userFlakeInputs userFlakeNixOS; } - { inherit (cfg) extern overrides; }; + { + inherit self inputs nixos; + inherit (cfg) extern overrides; + }; outputs = { nixosConfigurations = os.mkHosts - { inherit userFlakeSelf userFlakeInputs userFlakeNixOS; } { - inherit multiPkgs; + inherit self inputs nixos multiPkgs; inherit (cfg) extern suites overrides; dir = cfg.hosts; }; - homeConfigurations = os.mkHomeConfigurations - { inherit userFlakeSelf; }; + homeConfigurations = os.mkHomeConfigurations self.nixosConfigurations; nixosModules = cfg.modules; @@ -39,7 +34,7 @@ let overlay = cfg.packages; inherit (cfg) overlays; - deploy.nodes = os.mkNodes deploy userFlakeSelf.nixosConfigurations; + deploy.nodes = os.mkNodes deploy self.nixosConfigurations; }; systemOutputs = lib.eachDefaultSystem (system: @@ -47,15 +42,16 @@ let pkgs = multiPkgs.${system}; pkgs-lib = lib.pkgs-lib.${system}; # all packages that are defined in ./pkgs - legacyPackages = os.mkPackages - { inherit userFlakeSelf; } - { inherit pkgs; }; + legacyPackages = os.mkPackages { + inherit pkgs; + inherit (self) overlay overlays; + }; in { checks = pkgs-lib.tests.mkChecks { - inherit (userFlakeSelf.deploy) nodes; - hosts = userFlakeSelf.nixosConfigurations; - homes = userFlakeSelf.homeConfigurations; + inherit (self.deploy) nodes; + hosts = self.nixosConfigurations; + homes = self.homeConfigurations; }; inherit legacyPackages; diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index b162ad1a..cb90f614 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,8 +1,6 @@ { lib }: -{ userFlakeSelf, userFlakeNixOS }: - -{ args }: +{ nixos, args }: let argOpts = with lib; { config, ... }: let @@ -51,10 +49,10 @@ let options = with types; { input = mkOption { type = flakeType; - default = userFlakeNixOS; + default = nixos; description = '' nixpkgs flake input to use for this channel - ''; + ''; }; overlays = mkOption { type = pathToListOf overlayType; @@ -198,7 +196,7 @@ let let default = { nixpkgs = { - input = userFlakeNixOS; + input = nixos; }; }; in diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix index 2cf92214..c319d43a 100644 --- a/lib/mkFlake/evalOldArgs.nix +++ b/lib/mkFlake/evalOldArgs.nix @@ -1,8 +1,6 @@ { lib }: -{ userFlakeSelf, userFlakeInputs }: - -{ args }: +{ self, inputs, args }: let argOpts = with lib; { config, options, ... }: let @@ -32,8 +30,8 @@ let }; hosts = mkOption { type = path; - default = "${userFlakeSelf}/hosts"; - defaultText = "\${userFlakeSelf}/hosts"; + default = "${self}/hosts"; + defaultText = "\${self}/hosts"; apply = toString; description = '' Path to directory containing host configurations that will be exported @@ -74,15 +72,15 @@ let }; profiles = mkOption { type = path; - default = "${userFlakeSelf}/profiles"; - defaultText = "\${userFlakeSelf}/profiles"; + 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 = "${userFlakeSelf}/users/profiles"; - defaultText = "\${userFlakeSelf}/users/profiles"; + 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"; }; @@ -107,8 +105,8 @@ let }; users = mkOption { type = path; - default = "${userFlakeSelf}/users"; - defaultText = "\${userFlakeSelf}/users"; + default = "${self}/users"; + defaultText = "\${self}/users"; apply = x: os.mkProfileAttrs (toString x); description = '' path to folder containing profiles that define system users @@ -131,9 +129,9 @@ let { modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; } ''; # So unneeded extern attributes can safely be deleted - apply = x: defaults // (x { inputs = userFlakeInputs // userFlakeSelf.inputs; }); + apply = x: defaults // (x { inputs = inputs // self.inputs; }); description = '' - Function with argument 'inputs' that contains all devos and ''${userFlakeSelf}'s inputs. + 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. @@ -141,8 +139,8 @@ let }; overlays = mkOption { type = path; - default = "${userFlakeSelf}/overlays"; - defaultText = "\${userFlakeSelf}/overlays"; + default = "${self}/overlays"; + defaultText = "\${self}/overlays"; apply = x: lib.pathsToImportedAttrs (lib.pathsIn (toString x)); description = '' path to folder containing overlays which will be applied to pkgs and exported in diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index 40b451c2..1cadc2fe 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -1,9 +1,13 @@ { lib, nixpkgs, deploy, devshell }: lib.genAttrs - lib.defaultSystems (system: + lib.defaultSystems + (system: + let + pkgs = import nixpkgs { inherit system; }; + in { - tests = import ./tests { inherit lib deploy nixpkgs 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 7744f68f..0146ca22 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/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index 6111acde..b3e60624 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -1,7 +1,5 @@ -{ lib, nixpkgs, deploy, system }: +{ lib, nixpkgs, pkgs, deploy, system }: let - pkgs = import nixpkgs { inherit system; overlays = []; config = {}; }; - mkChecks = { hosts, nodes, homes ? { } }: let deployHosts = lib.filterAttrs @@ -9,9 +7,10 @@ let nodes; deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; }; tests = - lib.optionalAttrs (deployHosts != { }) { - profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))}); - } // lib.mapAttrs (n: v: v.activationPackage) homes; + lib.optionalAttrs (deployHosts != { }) + { + profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))}); + } // lib.mapAttrs (n: v: v.activationPackage) homes; in lib.recursiveUpdate tests deployChecks; diff --git a/lib/tests/default.nix b/lib/tests/default.nix index 4863cdf7..ab4d516b 100644 --- a/lib/tests/default.nix +++ b/lib/tests/default.nix @@ -1,27 +1,27 @@ { pkgs, lib }: pkgs.runCommandNoCC "devos-lib-tests" - { - buildInputs = [ - pkgs.nix - ( - let tests = import ./lib.nix { inherit pkgs lib; }; 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 +{ + buildInputs = [ + pkgs.nix + ( + let tests = import ./lib.nix { inherit pkgs lib; }; 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 - '' + touch $out +'' From 1cd4ed136a76f8c5342168ff86e8af93f7eb5e45 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 24 Apr 2021 08:14:58 -0700 Subject: [PATCH 26/91] mkFlakeDoc: move to packages output the packages output allows us to do `nix build .#nixosOptionsDoc`. theres also already an instantiated nixpkgs available there. --- flake.lock | 2 +- lib/flake.nix | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/flake.lock b/flake.lock index 00b07283..23e60897 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-LvO5VwFNFzb2xbmgw+fWhkrRY1KMlp5vxqQU/BqS0H8=", + "narHash": "sha256-eZJ8p2u56dkLPxF7GiQLbQ6YRKHP6DoOM52G/p+M/3w=", "path": "./lib", "type": "path" }, diff --git a/lib/flake.nix b/lib/flake.nix index c9bd99a5..6c7484a0 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -81,6 +81,14 @@ lib = nixpkgs.lib // lib; }; }; + packages = { + mkFlakeDoc = pkgs.writeText "mkFlakeOptions.md" + ( + pkgs.nixosOptionsDoc { + inherit (lib.mkFlake.evalArgs { nixos = "nixos"; args = { }; }) options; + } + ).optionsMDDoc; + }; } ); From a53aa8b7eb04f87c8dda74cf82282f73230d4c06 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 24 Apr 2021 08:37:23 -0700 Subject: [PATCH 27/91] lib: drop jobs output, prefer checks and packages With mkFlakeDoc in packages there is no need for jobs. And I think anything that could go in jobs really should go in checks or packages. If something needs to be tested - checks, if something needs to be built - packages. jobs is not multi-arch and is redundant to build/test things with when official flake outputs exist --- flake.lock | 2 +- lib/flake.nix | 4 ---- lib/jobs/default.nix | 7 ------- lib/jobs/mkFlakeDoc.nix | 33 --------------------------------- 4 files changed, 1 insertion(+), 45 deletions(-) delete mode 100644 lib/jobs/default.nix delete mode 100644 lib/jobs/mkFlakeDoc.nix diff --git a/flake.lock b/flake.lock index 23e60897..0e3ada8b 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-eZJ8p2u56dkLPxF7GiQLbQ6YRKHP6DoOM52G/p+M/3w=", + "narHash": "sha256-7Y6SqdLWr/g8tqNjqakRbS0KVIA/yzRm3D/RnoTAuzE=", "path": "./lib", "type": "path" }, diff --git a/lib/flake.nix b/lib/flake.nix index 6c7484a0..c6941695 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -54,13 +54,9 @@ } ); - jobs = import ./jobs { inherit nixpkgs; lib = nixpkgs.lib // lib; }; - in { - inherit jobs; - lib = utils.lib // { inherit (lib) mkFlake; diff --git a/lib/jobs/default.nix b/lib/jobs/default.nix deleted file mode 100644 index 5e9cff28..00000000 --- a/lib/jobs/default.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ 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 deleted file mode 100644 index 5a13d9f4..00000000 --- a/lib/jobs/mkFlakeDoc.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ 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 { nixos = "nixos"; args = { }; } - ).options; - - processedOptions = (pkgs.nixosOptionsDoc { inherit options; }).optionsNix; - - fullDoc = lib.concatStringsSep "" (lib.mapAttrsToList singleDoc processedOptions); -in -pkgs.writeText "devosOptions.md" fullDoc - From 2d9ea0d27edebd81fb599d87167548e5365e9b69 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 24 Apr 2021 08:56:51 -0700 Subject: [PATCH 28/91] lib: init modules and move mkHosts modules there This helps to split up the code in mkHosts and creates a place where we can store modules relevent to devos. It will also be easier to remove unecessary parts of each module in the future when they are all compartmentalized. --- flake.lock | 2 +- lib/devos/mkHosts.nix | 74 +++++++------------------------------------ lib/flake.nix | 2 ++ lib/modules.nix | 74 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 64 deletions(-) create mode 100644 lib/modules.nix diff --git a/flake.lock b/flake.lock index 0e3ada8b..a9e5e03c 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-7Y6SqdLWr/g8tqNjqakRbS0KVIA/yzRm3D/RnoTAuzE=", + "narHash": "sha256-9mdO1eRrHz/3EAr3M8Ugdc8T6qWu4UbogafqO4mruKo=", "path": "./lib", "type": "path" }, diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 2316da33..2fe4ed36 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -4,70 +4,18 @@ let defaultSystem = "x86_64-linux"; - experimentalFeatures = [ - "flakes" - "nix-command" - "ca-references" - "ca-derivations" - ]; - - modules = { - modOverrides = { config, overrideModulesPath, ... }: - let - inherit (overrides) modules disabledModules; - in - { - disabledModules = modules ++ disabledModules; - imports = map - (path: "${overrideModulesPath}/${path}") - modules; - }; - - global = { config, pkgs, ... }: { - home-manager = { - useGlobalPkgs = true; - useUserPackages = true; - - extraSpecialArgs = extern.userSpecialArgs // { suites = suites.user; }; - sharedModules = extern.userModules ++ (builtins.attrValues self.homeModules); - }; - users.mutableUsers = lib.mkDefault false; - - hardware.enableRedistributableFirmware = lib.mkDefault true; - - nix.nixPath = [ - "nixpkgs=${nixos}" - "nixos-config=${self}/lib/compat/nixos" - "home-manager=${inputs.home}" - ]; - - nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; - - nix.registry = { - devos.flake = self; - nixos.flake = nixos; - override.flake = inputs.override; - }; - - nix.package = pkgs.nixFlakes; - - nix.extraOptions = '' - experimental-features = ${lib.concatStringsSep " " - experimentalFeatures - } - ''; - - system.configurationRevision = lib.mkIf (self ? rev) self.rev; + modules = with lib.modules; { + modOverrides = modOverrides { inherit overrides; }; + hmDefaults = hmDefaults { + inherit extern; + inherit (self) homeModules; + userSuites = suites.user; }; - - # Everything in `./modules/list.nix`. - flakeModules = { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; - - cachix = let rootCachix = "${self}/cachix.nix"; in - if builtins.pathExists rootCachix - then rootCachix - else { } - ; + globalDefaults = globalDefaults { + inherit self nixos inputs multiPkgs; + }; + cachix = cachix { inherit self; }; + flakeModules = flakeModules { inherit self extern; }; }; specialArgs = extern.specialArgs // { suites = suites.system; }; diff --git a/lib/flake.nix b/lib/flake.nix index c6941695..8e6063ce 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -16,6 +16,7 @@ attrs = import ./attrs.nix { lib = nixpkgs.lib // self; }; lists = import ./lists.nix { lib = nixpkgs.lib // self; }; strings = import ./strings.nix { lib = nixpkgs.lib // self; }; + modules = import ./modules.nix { lib = nixpkgs.lib // self; }; in utils.lib @@ -51,6 +52,7 @@ filterPackages; inherit (lists) pathsIn; inherit (strings) rgxToString; + inherit modules; } ); diff --git a/lib/modules.nix b/lib/modules.nix new file mode 100644 index 00000000..1e5b8a8a --- /dev/null +++ b/lib/modules.nix @@ -0,0 +1,74 @@ +{ lib }: +{ + modOverrides = { overrides }: + { config, overrideModulesPath, ... }: + let + inherit (overrides) modules disabledModules; + in + { + disabledModules = modules ++ disabledModules; + imports = map + (path: "${overrideModulesPath}/${path}") + modules; + }; + + hmDefaults = { userSuites, extern, homeModules }: { + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + + extraSpecialArgs = extern.userSpecialArgs // { suites = userSuites; }; + sharedModules = extern.userModules ++ (builtins.attrValues homeModules); + }; + }; + + globalDefaults = { self, nixos, inputs, multiPkgs }: + let + experimentalFeatures = [ + "flakes" + "nix-command" + "ca-references" + "ca-derivations" + ]; + in + { config, pkgs, ... }: { + users.mutableUsers = lib.mkDefault false; + + hardware.enableRedistributableFirmware = lib.mkDefault true; + + nix.nixPath = [ + "nixpkgs=${nixos}" + "nixos-config=${self}/lib/compat/nixos" + "home-manager=${inputs.home}" + ]; + + nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; + + nix.registry = { + devos.flake = self; + nixos.flake = nixos; + override.flake = inputs.override; + }; + + nix.package = pkgs.nixFlakes; + + nix.extraOptions = '' + experimental-features = ${lib.concatStringsSep " " + experimentalFeatures + } + ''; + + system.configurationRevision = lib.mkIf (self ? rev) self.rev; + }; + + cachix = { self }: + let rootCachix = "${self}/cachix.nix"; in + if builtins.pathExists rootCachix + then rootCachix + else { }; + + flakeModules = { self, extern }: { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; + + +} + From 4e28ec2d8ef8125d8b2d99e0c81c3fa4efde2d62 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 23 Apr 2021 23:51:51 -0700 Subject: [PATCH 29/91] devosSystem: fix iso build - can't remove core --- lib/devos/devosSystem.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index c27a5a88..cc03a67f 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -21,8 +21,7 @@ lib.nixosSystem (args // { # avoid unwanted systemd service startups # all strings in disabledModules get appended to modulesPath # so convert each to list which can be coerced to string - disabledModules = map (x: [ x ]) - (lib.remove modules.core suites.allProfiles); + disabledModules = map lib.singleton suites.allProfiles; nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs; From 58c7d0403649c5f5362c1ea717fe40758a065f0d Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 24 Apr 2021 09:10:10 -0700 Subject: [PATCH 30/91] extract iso/hm config modules to lib.modules --- flake.lock | 2 +- lib/devos/devosSystem.nix | 76 ++------------------------------------- lib/modules.nix | 74 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 75 deletions(-) diff --git a/flake.lock b/flake.lock index a9e5e03c..0f3b3eb9 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-9mdO1eRrHz/3EAr3M8Ugdc8T6qWu4UbogafqO4mruKo=", + "narHash": "sha256-IvKVn4U3Ts2aw8JoKvBCte6Z77JynuNob8LClmsopFo=", "path": "./lib", "type": "path" }, diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index cc03a67f..00c9e3e6 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -6,91 +6,19 @@ lib.nixosSystem (args // { modules = let moduleList = builtins.attrValues modules; - modpath = "nixos/modules"; fullHostConfig = (lib.nixosSystem (args // { modules = moduleList; })).config; isoConfig = (lib.nixosSystem (args // { modules = moduleList ++ [ - - "${nixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" - - ({ config, suites, ... }: { - - # avoid unwanted systemd service startups - # all strings in disabledModules get appended to modulesPath - # so convert each to list which can be coerced to string - disabledModules = map lib.singleton suites.allProfiles; - - nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs; - - isoImage.isoBaseName = "nixos-" + config.networking.hostName; - isoImage.contents = [{ - source = self; - target = "/devos/"; - }]; - isoImage.storeContents = [ - self.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 - ]; - # still pull in tools of deactivated profiles - environment.systemPackages = fullHostConfig.environment.systemPackages; - - # confilcts with networking.wireless which might be slightly - # more useful on a stick - networking.networkmanager.enable = lib.mkForce false; - # confilcts with networking.wireless - networking.wireless.iwd.enable = lib.mkForce false; - - # Set up a link-local boostrap network - # See also: https://github.com/NixOS/nixpkgs/issues/75515#issuecomment-571661659 - networking.usePredictableInterfaceNames = lib.mkForce true; # so prefix matching works - networking.useNetworkd = lib.mkForce true; - networking.useDHCP = lib.mkForce false; - networking.dhcpcd.enable = lib.mkForce false; - systemd.network = { - # https://www.freedesktop.org/software/systemd/man/systemd.network.html - networks."boostrap-link-local" = { - matchConfig = { - Name = "en* wl* ww*"; - }; - networkConfig = { - Description = "Link-local host bootstrap network"; - MulticastDNS = true; - LinkLocalAddressing = "ipv6"; - DHCP = "yes"; - }; - address = [ - # fall back well-known link-local for situations where MulticastDNS is not available - "fe80::47" # 47: n=14 i=9 x=24; n+i+x - ]; - extraConfig = '' - # Unique, yet stable. Based off the MAC address. - IPv6LinkLocalAddressGenerationMode = "eui64" - ''; - }; - }; - }) + (lib.modules.iso { inherit self nixos inputs fullHostConfig; }) ]; })).config; hmConfig = (lib.nixosSystem (args // { modules = moduleList ++ [ - ({ config, ... }: { - home-manager.useUserPackages = lib.mkForce false; - home-manager.sharedModules = [ - { - home.sessionVariables = { - inherit (config.environment.sessionVariables) NIX_PATH; - }; - xdg.configFile."nix/registry.json".text = - config.environment.etc."nix/registry.json".text; - } - ]; - }) + (lib.modules.hmConfig) ]; })).config; in diff --git a/lib/modules.nix b/lib/modules.nix index 1e5b8a8a..7024f13f 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -69,6 +69,80 @@ flakeModules = { self, extern }: { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; + isoConfig = { self, nixos, inputs, fullHostConfig }: + { config, suites, ... }: { + imports = let modpath = "nixos/modules"; in + [ "${nixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ]; + # avoid unwanted systemd service startups + # all strings in disabledModules get appended to modulesPath + # so convert each to list which can be coerced to string + disabledModules = map lib.singleton suites.allProfiles; + + nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs; + + isoImage.isoBaseName = "nixos-" + config.networking.hostName; + isoImage.contents = [{ + source = self; + target = "/devos/"; + }]; + isoImage.storeContents = [ + self.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 + ]; + # still pull in tools of deactivated profiles + environment.systemPackages = fullHostConfig.environment.systemPackages; + + # confilcts with networking.wireless which might be slightly + # more useful on a stick + networking.networkmanager.enable = lib.mkForce false; + # confilcts with networking.wireless + networking.wireless.iwd.enable = lib.mkForce false; + + # Set up a link-local boostrap network + # See also: https://github.com/NixOS/nixpkgs/issues/75515#issuecomment-571661659 + networking.usePredictableInterfaceNames = lib.mkForce true; # so prefix matching works + networking.useNetworkd = lib.mkForce true; + networking.useDHCP = lib.mkForce false; + networking.dhcpcd.enable = lib.mkForce false; + systemd.network = { + # https://www.freedesktop.org/software/systemd/man/systemd.network.html + networks."boostrap-link-local" = { + matchConfig = { + Name = "en* wl* ww*"; + }; + networkConfig = { + Description = "Link-local host bootstrap network"; + MulticastDNS = true; + LinkLocalAddressing = "ipv6"; + DHCP = "yes"; + }; + address = [ + # fall back well-known link-local for situations where MulticastDNS is not available + "fe80::47" # 47: n=14 i=9 x=24; n+i+x + ]; + extraConfig = '' + # Unique, yet stable. Based off the MAC address. + IPv6LinkLocalAddressGenerationMode = "eui64" + ''; + }; + }; + }; + + hmConfig = + { config, ... }: { + home-manager.useUserPackages = lib.mkForce false; + home-manager.sharedModules = [ + { + home.sessionVariables = { + inherit (config.environment.sessionVariables) NIX_PATH; + }; + xdg.configFile."nix/registry.json".text = + config.environment.etc."nix/registry.json".text; + } + ]; + }; } From 2cab5b5d2b30fba6431a4a2b82f0e83afac19589 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 20:53:16 -0700 Subject: [PATCH 31/91] add and use lib.collectProfiles this function collects profiles recursively --- flake.lock | 2 +- lib/devos/mkSuites.nix | 8 ++------ lib/flake.nix | 2 +- lib/lists.nix | 11 +++++++++++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/flake.lock b/flake.lock index 0f3b3eb9..1c95e54a 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-IvKVn4U3Ts2aw8JoKvBCte6Z77JynuNob8LClmsopFo=", + "narHash": "sha256-t14TKUtw83dZ2mbqjRpeUvdAx4zpe/ySr5KhPhB1JMU=", "path": "./lib", "type": "path" }, diff --git a/lib/devos/mkSuites.nix b/lib/devos/mkSuites.nix index cb736793..66a36ea1 100644 --- a/lib/devos/mkSuites.nix +++ b/lib/devos/mkSuites.nix @@ -8,13 +8,9 @@ let inherit (args) users profiles userProfiles; }; - allProfiles = - let defaults = lib.collect (x: x ? default) profiles; - in map (x: x.default) defaults; + allProfiles = lib.collectProfiles profiles; - allUsers = - let defaults = lib.collect (x: x ? default) users; - in map (x: x.default) defaults; + allUsers = lib.collectProfiles users; createSuites = _: suites: lib.mapAttrs (_: v: os.profileMap v) suites // { inherit allProfiles allUsers; diff --git a/lib/flake.nix b/lib/flake.nix index 8e6063ce..15d87197 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -50,7 +50,7 @@ pathsToImportedAttrs concatAttrs filterPackages; - inherit (lists) pathsIn; + inherit (lists) pathsIn collectProfiles; inherit (strings) rgxToString; inherit modules; } diff --git a/lib/lists.nix b/lib/lists.nix index 18620412..c20a4d7b 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -1,5 +1,16 @@ { lib }: { + collectProfiles = set: + let + collectNestedProfiles = set: + lib.mapAttrsToList (n: v: + if builtins.isAttrs v then + [ v.default or null ] ++ collectNestedProfiles v + else null + ) set; + in + builtins.filter (x: x != null) (lib.flatten (collectNestedProfiles set)); + pathsIn = dir: let fullPath = name: "${toString dir}/${name}"; From abd133c244e9c9f9be8a66bd4a2e1a98e4090270 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 16:21:40 -0700 Subject: [PATCH 32/91] make devosSystem construct a proper nixos builder Get `self` and `inputs` during construction, and rely on specialArgs.channel for nixos flake --- lib/devos/devosSystem.nix | 63 ++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index 00c9e3e6..c48f68a5 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -1,31 +1,40 @@ { lib }: -{ self, nixos, inputs, modules, ... } @ allArgs: -let args = builtins.removeAttrs allArgs [ "self" "nixos" "inputs" ]; in -lib.nixosSystem (args // { - modules = - let - moduleList = builtins.attrValues modules; +# dependencies to return a builder +{ self, inputs }: - fullHostConfig = (lib.nixosSystem (args // { modules = moduleList; })).config; +{ modules, specialArgs, ... } @ args: +let inherit (specialArgs.channel.input.lib) nixosSystem; in +nixosSystem + (args // { + modules = + let + fullHostConfig = (nixosSystem (args // { inherit modules; })).config; - isoConfig = (lib.nixosSystem - (args // { - modules = moduleList ++ [ - (lib.modules.iso { inherit self nixos inputs fullHostConfig; }) - ]; - })).config; - hmConfig = (lib.nixosSystem - (args // { - modules = moduleList ++ [ - (lib.modules.hmConfig) - ]; - })).config; - in - moduleList ++ [{ - system.build = { - iso = isoConfig.system.build.isoImage; - homes = hmConfig.home-manager.users; - }; - }]; -}) + isoConfig = (nixosSystem + (args // { + modules = modules ++ [ + (lib.modules.iso { inherit self inputs fullHostConfig; }) + ]; + })).config; + + hmConfig = (nixosSystem + (args // { + modules = modules ++ [ + (lib.modules.hmConfig) + ]; + })).config; + in + modules ++ [{ + system.build = { + iso = isoConfig.system.build.isoImage; + homes = hmConfig.home-manager.users; + }; + lib = { + inherit specialArgs; + testModule = { + imports = modules; + }; + }; + }]; + }) From 59383e871f882cb1a72c64392bdb48220db1367c Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 16:22:33 -0700 Subject: [PATCH 33/91] modules: drop any logic already done by fup this includes creating multiPkgs, and dropping options already set by fup --- lib/modules.nix | 46 ++++++++++------------------------------------ 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/lib/modules.nix b/lib/modules.nix index 7024f13f..2cd965ff 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -1,28 +1,16 @@ { lib }: { - modOverrides = { overrides }: - { config, overrideModulesPath, ... }: - let - inherit (overrides) modules disabledModules; - in - { - disabledModules = modules ++ disabledModules; - imports = map - (path: "${overrideModulesPath}/${path}") - modules; - }; - - hmDefaults = { userSuites, extern, homeModules }: { + hmDefaults = { suites, modules }: { home-manager = { useGlobalPkgs = true; useUserPackages = true; - extraSpecialArgs = extern.userSpecialArgs // { suites = userSuites; }; - sharedModules = extern.userModules ++ (builtins.attrValues homeModules); + extraSpecialArgs = { inherit suites; }; + sharedModules = modules; }; }; - globalDefaults = { self, nixos, inputs, multiPkgs }: + globalDefaults = { self, inputs }: let experimentalFeatures = [ "flakes" @@ -31,27 +19,22 @@ "ca-derivations" ]; in - { config, pkgs, ... }: { + { channel, config, pkgs, ... }: { users.mutableUsers = lib.mkDefault false; hardware.enableRedistributableFirmware = lib.mkDefault true; nix.nixPath = [ - "nixpkgs=${nixos}" + "nixpkgs=${channel.input}" "nixos-config=${self}/lib/compat/nixos" "home-manager=${inputs.home}" ]; - nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; - nix.registry = { devos.flake = self; - nixos.flake = nixos; - override.flake = inputs.override; + nixos.flake = channel.input; }; - nix.package = pkgs.nixFlakes; - nix.extraOptions = '' experimental-features = ${lib.concatStringsSep " " experimentalFeatures @@ -61,19 +44,10 @@ system.configurationRevision = lib.mkIf (self ? rev) self.rev; }; - cachix = { self }: - let rootCachix = "${self}/cachix.nix"; in - if builtins.pathExists rootCachix - then rootCachix - else { }; + isoConfig = { self, inputs, fullHostConfig }: + { config, modulesPath, suites, ... }: { - flakeModules = { self, extern }: { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; - - isoConfig = { self, nixos, inputs, fullHostConfig }: - { config, suites, ... }: { - - imports = let modpath = "nixos/modules"; in - [ "${nixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ]; + imports = [ "${modulesPath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ]; # avoid unwanted systemd service startups # all strings in disabledModules get appended to modulesPath # so convert each to list which can be coerced to string From ba01aa7db7419a3e301f5f9251eff358d88c7e17 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 10:52:26 -0700 Subject: [PATCH 34/91] mkSuites: generalize for one profile/suite pair --- lib/devos/mkSuites.nix | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/devos/mkSuites.nix b/lib/devos/mkSuites.nix index 66a36ea1..45d8a10f 100644 --- a/lib/devos/mkSuites.nix +++ b/lib/devos/mkSuites.nix @@ -1,20 +1,20 @@ { lib }: -{ users, profiles, userProfiles, suites } @ args: +{ suites, profiles } @ args: let inherit (lib) os; - definedSuites = suites { - inherit (args) users profiles userProfiles; - }; + profileSet = lib.genAttrs' profiles (path: { + name = baseNameOf path; + value = os.mkProfileAttrs (toString path); + }); - allProfiles = lib.collectProfiles profiles; - - allUsers = lib.collectProfiles users; - - createSuites = _: suites: lib.mapAttrs (_: v: os.profileMap v) suites // { - inherit allProfiles allUsers; - }; + definedSuites = suites profileSet; + allProfiles = lib.collectProfiles profileSet; in -lib.mapAttrs createSuites definedSuites +lib.mapAttrs (_: v: os.profileMap v) definedSuites // { + inherit allProfiles; +} + + From 3986cc441b86cb7873c99eb2252df4b080976f76 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 16:36:48 -0700 Subject: [PATCH 35/91] pkgs-lib: don't system space functions have each function take pkgs as an argument, so a nixpkgs isn't created just for pkgs-lib and they support more systems --- lib/flake.nix | 2 +- lib/pkgs-lib/default.nix | 17 +++++------------ lib/pkgs-lib/shell/default.nix | 25 ++++++++++++++----------- lib/pkgs-lib/tests/default.nix | 25 ++++++++++++++----------- 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/lib/flake.nix b/lib/flake.nix index 15d87197..393c9d6a 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -40,7 +40,7 @@ pkgs-lib = import ./pkgs-lib { lib = nixpkgs.lib // self; - inherit nixpkgs deploy devshell; + inherit deploy devshell; }; inherit (attrs) diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index 1cadc2fe..bcaee771 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -1,13 +1,6 @@ -{ lib, nixpkgs, deploy, devshell }: +{ lib, deploy, devshell }: +{ + tests = import ./tests { inherit lib deploy; }; + shell = import ./shell { inherit lib devshell deploy; }; +} -lib.genAttrs - lib.defaultSystems - (system: - let - pkgs = import nixpkgs { inherit system; }; - in - { - 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 0146ca22..5b73b54c 100644 --- a/lib/pkgs-lib/shell/default.nix +++ b/lib/pkgs-lib/shell/default.nix @@ -1,27 +1,30 @@ -{ lib, nixpkgs, devshell, deploy, system }: +{ lib, devshell, deploy }: + +{ pkgs }: let overlays = [ - devshell.overlay (final: prev: { deploy-rs = deploy.packages.${prev.system}.deploy-rs; }) - ]; - pkgs = import nixpkgs { inherit system overlays; config = { }; }; + pkgs' = import pkgs.path { + inherit (pkgs) system; + inherit overlays; + }; - flk = pkgs.callPackage ./flk.nix { }; + flk = pkgs'.callPackage ./flk.nix { }; installPkgs = (lib.nixosSystem { - inherit system; + inherit (pkgs') system; modules = [ ]; }).config.system.build; in -pkgs.devshell.mkShell { - imports = [ (pkgs.devshell.importTOML ./devshell.toml) ]; +pkgs'.devshell.mkShell { + imports = [ (pkgs'.devshell.importTOML ./devshell.toml) ]; packages = with installPkgs; [ nixos-install @@ -33,13 +36,13 @@ pkgs.devshell.mkShell { pre-commit.text = lib.fileContents ./pre-commit.sh; }; - commands = with pkgs; [ + commands = with pkgs'; [ { package = flk; } { name = "nix"; - help = pkgs.nixFlakes.meta.description; + help = pkgs'.nixFlakes.meta.description; command = '' - ${pkgs.nixFlakes}/bin/nix --experimental-features "nix-command flakes ca-references" "${"\${@}"}" + ${pkgs'.nixFlakes}/bin/nix --experimental-features "nix-command flakes ca-references" "${"\${@}"}" ''; } ] diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index b3e60624..854332fe 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -1,25 +1,28 @@ -{ lib, nixpkgs, pkgs, deploy, system }: +{ lib, deploy }: let - mkChecks = { hosts, nodes, homes ? { } }: + mkChecks = { pkgs, hosts, nodes, homes ? { } }: let deployHosts = lib.filterAttrs - (n: _: hosts.${n}.config.nixpkgs.system == system) + (n: _: hosts.${n}.config.nixpkgs.system == pkgs.system) nodes; - deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; }; + deployChecks = deploy.lib.${pkgs.system}.deployChecks { nodes = deployHosts; }; tests = lib.optionalAttrs (deployHosts != { }) { - profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))}); + profilesTest = profilesTest { + inherit pkgs; + host = hosts.${(builtins.head (builtins.attrNames deployHosts))}; + }; } // lib.mapAttrs (n: v: v.activationPackage) homes; in lib.recursiveUpdate tests deployChecks; - mkTest = host: + mkTest = { pkgs, host }: let nixosTesting = - (import "${nixpkgs}/nixos/lib/testing-python.nix" { - inherit system; + (import "${toString pkgs.path}/nixos/lib/testing-python.nix" { + inherit (pkgs) system; inherit (host.config.lib) specialArgs; inherit pkgs; extraConfigurations = [ @@ -40,15 +43,15 @@ let in nixosTesting.makeTest calledTest; - profilesTest = host: mkTest host { + profilesTest = args@{ host, ... }: mkTest args { name = "profiles"; machine = { suites, ... }: { - imports = suites.allProfiles ++ suites.allUsers; + imports = suites.allProfiles; }; testScript = '' - machine.systemctl("is-system-running --wait") + ${host.config.networking.hostName}.systemctl("is-system-running --wait") ''; }; in From ceef51425e222c85eab4c4053426f08ba880ebe3 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 16:46:02 -0700 Subject: [PATCH 36/91] init unifyOverlays: to pass channels to overlays Only to those with three arguments --- lib/flake.nix | 2 +- lib/lists.nix | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/flake.nix b/lib/flake.nix index 393c9d6a..862570c0 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -50,7 +50,7 @@ pathsToImportedAttrs concatAttrs filterPackages; - inherit (lists) pathsIn collectProfiles; + inherit (lists) pathsIn collectProfiles unifyOverlays; inherit (strings) rgxToString; inherit modules; } diff --git a/lib/lists.nix b/lib/lists.nix index c20a4d7b..5e9c57b2 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -16,4 +16,6 @@ fullPath = name: "${toString dir}/${name}"; in map fullPath (lib.attrNames (lib.safeReadDir dir)); + + unifyOverlays = channels: map (o: if builtins.isFunction (o null null) then o channels else o); } From 377381de51b4dcbf5aea1ee7f80abd12abd63d47 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 11:34:24 -0700 Subject: [PATCH 37/91] export pathsIn in lib and update devos input --- flake.lock | 2 +- lib/flake.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.lock b/flake.lock index 1c95e54a..014caf82 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-t14TKUtw83dZ2mbqjRpeUvdAx4zpe/ySr5KhPhB1JMU=", + "narHash": "sha256-JBTc4NiKuJ99+u8ey+1gQezW5pihAnfnyupBmdj4zUk=", "path": "./lib", "type": "path" }, diff --git a/lib/flake.nix b/lib/flake.nix index 862570c0..65c0e20c 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -61,7 +61,7 @@ { lib = utils.lib // { inherit (lib) - mkFlake; + mkFlake pathsIn; }; } From 3bb26330b457c32aee5249c8c114517466044a5b Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 16:46:59 -0700 Subject: [PATCH 38/91] switch to flake-utils-plus staging for rebase --- flake.lock | 35 +++++++++++++++++++++++++++-------- lib/flake.lock | 33 ++++++++++++++++++++++++++------- lib/flake.nix | 2 +- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/flake.lock b/flake.lock index 014caf82..b862c3f7 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-JBTc4NiKuJ99+u8ey+1gQezW5pihAnfnyupBmdj4zUk=", + "narHash": "sha256-y0IZEAqpQpdGhxfc6REAT2PY2nEbikusUlXCRv264vI=", "path": "./lib", "type": "path" }, @@ -138,6 +138,21 @@ "type": "github" } }, + "flake-utils": { + "locked": { + "lastModified": 1619345332, + "narHash": "sha256-qHnQkEp1uklKTpx3MvKtY6xzgcqXDsz5nLilbbuL+3A=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "2ebf2558e5bf978c7fb8ea927dfaed8fefab2e28", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "home": { "inputs": { "nixpkgs": [ @@ -336,17 +351,21 @@ } }, "utils_2": { + "inputs": { + "flake-utils": "flake-utils" + }, "locked": { - "lastModified": 1618868421, - "narHash": "sha256-vyoJhLV6cJ8/tWz+l9HZLIkb9Rd9esE7p+0RL6zDR6Y=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "eed214942bcfb3a8cc09eb3b28ca7d7221e44a94", + "lastModified": 1619438935, + "narHash": "sha256-B8OGqX9QBMW5G8DYTRdY0cb62ETaV0YxBayCZMiaVqQ=", + "owner": "gytis-ivaskevicius", + "repo": "flake-utils-plus", + "rev": "80b53eeda3102bb5aed31ec818c6485e35caffc3", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "gytis-ivaskevicius", + "ref": "staging", + "repo": "flake-utils-plus", "type": "github" } } diff --git a/lib/flake.lock b/lib/flake.lock index f70c491f..6942e2a8 100644 --- a/lib/flake.lock +++ b/lib/flake.lock @@ -52,6 +52,21 @@ "type": "github" } }, + "flake-utils": { + "locked": { + "lastModified": 1619345332, + "narHash": "sha256-qHnQkEp1uklKTpx3MvKtY6xzgcqXDsz5nLilbbuL+3A=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "2ebf2558e5bf978c7fb8ea927dfaed8fefab2e28", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "naersk": { "inputs": { "nixpkgs": [ @@ -127,17 +142,21 @@ } }, "utils_2": { + "inputs": { + "flake-utils": "flake-utils" + }, "locked": { - "lastModified": 1618868421, - "narHash": "sha256-vyoJhLV6cJ8/tWz+l9HZLIkb9Rd9esE7p+0RL6zDR6Y=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "eed214942bcfb3a8cc09eb3b28ca7d7221e44a94", + "lastModified": 1619438935, + "narHash": "sha256-B8OGqX9QBMW5G8DYTRdY0cb62ETaV0YxBayCZMiaVqQ=", + "owner": "gytis-ivaskevicius", + "repo": "flake-utils-plus", + "rev": "80b53eeda3102bb5aed31ec818c6485e35caffc3", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "gytis-ivaskevicius", + "ref": "staging", + "repo": "flake-utils-plus", "type": "github" } } diff --git a/lib/flake.nix b/lib/flake.nix index 65c0e20c..9025477a 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -5,7 +5,7 @@ { deploy.url = "github:serokell/deploy-rs"; devshell.url = "github:numtide/devshell"; - utils.url = "github:numtide/flake-utils"; + utils.url = "github:gytis-ivaskevicius/flake-utils-plus/staging"; }; outputs = inputs@{ self, nixpkgs, deploy, devshell, utils, ... }: From f8315a293c4585f89aef4f5815f94ceac7f28fd9 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 16:52:02 -0700 Subject: [PATCH 39/91] evalArgs: general api improvements drop default channel, it is confusing and complicates api don't take nixos input, using channels is better manually pass names for outputs to improve documentation --- lib/mkFlake/evalArgs.nix | 124 ++++++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 54 deletions(-) diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index cb90f614..5884dcfb 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,11 +1,12 @@ { lib }: -{ nixos, args }: +{ args }: let argOpts = with lib; { config, ... }: let inherit (lib) os; + cfg = config; inherit (config) self; maybeImport = obj: @@ -33,23 +34,19 @@ let # To simplify apply keys and improve type checking pathTo = elemType: with types; coercedTo path maybeImport elemType; - # Accepts single item or a list - # apply keys end up with a list - # This should not be used if expecting a nested list - # all lists will get flattened by this - coercedListOf = elemType: - let coerceToList = x: flatten (singleton x); in - with types; coercedTo elemType coerceToList (listOf elemType); + pathToListOf = elemType: with types; pathTo (listOf elemType); - pathToListOf = x: pathTo (coercedListOf x); + coercedListOf = elemType: with types; + coercedTo elemType (x: flatten (singleton x)) (listOf elemType); /* Submodules needed for API containers */ - channelsModule = { + channelsModule = { name, ... }: { options = with types; { input = mkOption { type = flakeType; - default = nixos; + default = cfg.inputs.${name}; + defaultText = escape [ "<" ">" ] "inputs."; description = '' nixpkgs flake input to use for this channel ''; @@ -57,22 +54,15 @@ let overlays = mkOption { type = pathToListOf overlayType; default = [ ]; - description = '' + description = escape [ "<" ">" ] '' overlays to apply to this channel these will get exported under the 'overlays' flake output as / ''; }; - externalOverlays = mkOption { - type = pathToListOf 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 = { }; + apply = lib.recursiveUpdate cfg.channelsConfig; description = '' nixpkgs config for this channel ''; @@ -82,21 +72,21 @@ let hostModule = { options = with types; { + # anything null in hosts gets filtered out by mkFlake system = mkOption { - type = systemType; - default = "x86_64-linux"; + type = nullOr systemType; + default = null; description = '' system for this host ''; }; channelName = mkOption { - type = types.enum (builtins.attrValues config.channels); - default = "nixpkgs"; + type = nullOr (types.enum (builtins.attrNames config.channels)); + default = null; description = '' Channel this host should follow ''; }; - }; }; @@ -105,7 +95,7 @@ let externalModulesModule = { options = { externalModules = mkOption { - type = pathToListOf moduleType; + type = with types; listOf moduleType; default = [ ]; description = '' The configuration for this host @@ -117,7 +107,7 @@ let modulesModule = { options = { modules = mkOption { - type = pathToListOf moduleType; + type = with types; coercedListOf moduleType; default = [ ]; description = '' modules to include @@ -126,13 +116,34 @@ let }; }; + exportModulesModule = name: { + options = { + modules = mkOption { + type = with types; pathToListOf + # check if the path evaluates to a proper module + # but this must be a path for the export to work + (addCheck path (x: moduleType.check (import x))); + default = [ ]; + description = '' + modules to include in all hosts and export to ${name}Modules output + ''; + }; + }; + }; + + + # Home-manager's configs get exported automatically from nixos.hosts # So there is no need for a host options in the home namespace # This is only needed for nixos - includeHostsModule = { name, ... }: { + includeHostsModule = name: { options = with types; { hostDefaults = mkOption { - type = submodule [ hostModule externalModulesModule modulesModule ]; + type = submodule [ + hostModule + externalModulesModule + (exportModulesModule name) + ]; default = { }; description = '' Defaults for all hosts. @@ -152,15 +163,11 @@ let }; # profiles and suites - which are profile collections - profilesModule = { name, ... }: { + profilesModule = { config, ... }: { options = with types; { profiles = mkOption { - type = coercedListOf path; + type = listOf path; default = [ ]; - apply = list: - # Merge a list of profiles to one set - let profileList = map (x: os.mkProfileAttrs (toString x)) list; in - foldl (a: b: a // b) { } profileList; description = "path to profiles folder that can be collected into suites"; }; suites = mkOption { @@ -185,6 +192,13 @@ let type = flakeType; description = "The flake to create the devos outputs for"; }; + inputs = mkOption { + type = attrsOf flakeType; + description = '' + inputs for this flake + used to set channel defaults and create registry + ''; + }; supportedSystems = mkOption { type = listOf str; default = lib.defaultSystems; @@ -192,31 +206,33 @@ let The systems supported by this flake ''; }; - channels = - let - default = { - nixpkgs = { - input = nixos; - }; - }; - in - mkOption { - type = attrsOf (submodule channelsModule); - inherit default; - apply = x: default // x; - description = '' - nixpkgs channels to create - ''; - }; - os = mkOption { - type = submodule [ includeHostsModule profilesModule ]; + channelsConfig = mkOption { + type = pathTo attrs; + default = { }; + description = '' + nixpkgs config for all channels + ''; + }; + channels = mkOption { + type = attrsOf (submodule channelsModule); + default = { }; + description = '' + nixpkgs channels to create + ''; + }; + nixos = mkOption { + type = submodule [ (includeHostsModule "nixos") profilesModule ]; default = { }; description = '' hosts, modules, suites, and profiles for nixos ''; }; home = mkOption { - type = submodule [ profilesModule modulesModule ]; + type = submodule [ + profilesModule + (exportModulesModule "home") + externalModulesModule + ]; default = { }; description = '' hosts, modules, suites, and profiles for home-manager From dceac02b36f418bc91f09760b3861dbee1c03848 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 16:50:01 -0700 Subject: [PATCH 40/91] implement mkFlake for new api and rebase on fup --- lib/flake.nix | 3 +- lib/mkFlake/default.nix | 121 ++++++++++++++++----------- lib/mkFlake/evalOldArgs.nix | 162 ------------------------------------ 3 files changed, 72 insertions(+), 214 deletions(-) delete mode 100644 lib/mkFlake/evalOldArgs.nix diff --git a/lib/flake.nix b/lib/flake.nix index 9025477a..17e069c2 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -35,7 +35,6 @@ 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 { @@ -83,7 +82,7 @@ mkFlakeDoc = pkgs.writeText "mkFlakeOptions.md" ( pkgs.nixosOptionsDoc { - inherit (lib.mkFlake.evalArgs { nixos = "nixos"; args = { }; }) options; + inherit (lib.mkFlake.evalArgs { args = { }; }) options; } ).optionsMDDoc; }; diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index d086283a..3d285c73 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,64 +1,85 @@ { lib, deploy }: let inherit (lib) os; + inherit (builtins) mapAttrs attrNames attrValues head isFunction; in -_: { self, inputs, nixos, ... } @ args: +_: { self, inputs, ... } @ args: let - cfg = ( - lib.mkFlake.evalOldArgs - { inherit self inputs args; } - ).config; - - multiPkgs = os.mkPkgs - { - inherit self inputs nixos; - inherit (cfg) extern overrides; - }; - - outputs = { - nixosConfigurations = os.mkHosts - { - inherit self inputs nixos multiPkgs; - inherit (cfg) extern suites overrides; - dir = cfg.hosts; - }; - - homeConfigurations = os.mkHomeConfigurations self.nixosConfigurations; - - nixosModules = cfg.modules; - - homeModules = cfg.userModules; - - overlay = cfg.packages; - inherit (cfg) overlays; - - deploy.nodes = os.mkNodes deploy self.nixosConfigurations; + config = lib.mkFlake.evalArgs { + args = lib.mkMerge [ args { _module.check = false; } ]; }; - systemOutputs = lib.eachDefaultSystem (system: - let - pkgs = multiPkgs.${system}; - pkgs-lib = lib.pkgs-lib.${system}; - # all packages that are defined in ./pkgs - legacyPackages = os.mkPackages { - inherit pkgs; - inherit (self) overlay overlays; - }; - in - { - checks = pkgs-lib.tests.mkChecks { + cfg = config.config; + + otherArguments = removeAttrs args (attrNames config.options); + + defaultModules = with lib.modules; [ + (hmDefaults { + inherit (cfg.home) suites; + modules = cfg.home.modules ++ cfg.home.externalModules; + }) + (globalDefaults { + inherit self inputs; + }) + ]; + + getDefaultChannel = channels: channels.${cfg.nixos.hostDefaults.channelName}; +in +lib.systemFlake (lib.recursiveUpdate + otherArguments + { + inherit self inputs; + inherit (cfg) channelsConfig supportedSystems; + + mkFlakeConfig = config; + + channels = mapAttrs + (name: channel: + channel // { + # pass channels if "overlay" has three arguments + overlaysBuilder = channels: lib.unifyOverlays channels channel.overlays; + } + ) cfg.channels; + + # the host arguments cannot exist for fup hostDefaults to work + # so evalArgs sets them to null by default and the null args are filtered out here + hosts = mapAttrs (_: host: lib.filterAttrs (_: arg: arg != null) host) cfg.nixos.hosts; + + hostDefaults = { + specialArgs.suites = cfg.nixos.suites; + modules = cfg.nixos.hostDefaults.modules + ++ cfg.nixos.hostDefaults.externalModules + ++ defaultModules; + builder = os.devosSystem { inherit self inputs; }; + inherit (cfg.nixos.hostDefaults) + channelName + system; + }; + + nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules; + + homeModules = lib.exporter.modulesFromList cfg.home.modules; + homeConfigurations = os.mkHomeConfigurations self.nixosConfigurations; + + deploy.nodes = os.mkNodes deploy self.nixosConfigurations; + + overlays = lib.exporter.overlaysFromChannelsExporter { inherit (self) pkgs inputs; }; + + packagesBuilder = lib.builder.packagesFromOverlaysBuilderConstructor self.overlays; + + checksBuilder = channels: + lib.pkgs-lib.tests.mkChecks { + pkgs = getDefaultChannel channels; inherit (self.deploy) nodes; hosts = self.nixosConfigurations; homes = self.homeConfigurations; }; - inherit legacyPackages; - packages = lib.filterPackages system legacyPackages; - - devShell = pkgs-lib.shell; - }); -in -outputs // systemOutputs - + devShellBuilder = channels: + lib.pkgs-lib.shell { + pkgs = getDefaultChannel channels; + }; + } +) diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix deleted file mode 100644 index c319d43a..00000000 --- a/lib/mkFlake/evalOldArgs.nix +++ /dev/null @@ -1,162 +0,0 @@ -{ lib }: - -{ self, inputs, args }: -let - argOpts = with lib; { config, options, ... }: - let - inherit (lib) 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 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 = "${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 = lib.pathsToImportedAttrs; - description = '' - list of modules to include in confgurations and export in 'nixosModules' output - ''; - }; - userModules = mkOption { - type = listOf moduleType; - default = [ ]; - apply = lib.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: lib.pathsToImportedAttrs (lib.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 -lib.evalModules { - modules = [ argOpts args ]; -} From c3d8805ad607935f033c737391978100d772bca0 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Wed, 21 Apr 2021 22:44:15 -0500 Subject: [PATCH 41/91] update devos template to use new api --- extern/default.nix | 25 -------------- extern/overrides.nix | 33 ------------------- flake.lock | 40 +++++++++++------------ flake.nix | 78 ++++++++++++++++++++++++++++++++------------ overrides.nix | 26 +++++++++++++++ 5 files changed, 103 insertions(+), 99 deletions(-) delete mode 100644 extern/default.nix delete mode 100644 extern/overrides.nix create mode 100644 overrides.nix diff --git a/extern/default.nix b/extern/default.nix deleted file mode 100644 index 19c1bae6..00000000 --- a/extern/default.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ inputs }: with inputs; -{ - modules = [ - home.nixosModules.home-manager - ci-agent.nixosModules.agent-profile - ]; - - overlays = [ - nur.overlay - pkgs.overlay - ]; - - # passed to all nixos modules - specialArgs = { - overrideModulesPath = "${override}/nixos/modules"; - hardware = nixos-hardware.nixosModules; - }; - - # added to home-manager - userModules = [ - ]; - - # passed to all home-manager modules - userSpecialArgs = { }; -} diff --git a/extern/overrides.nix b/extern/overrides.nix deleted file mode 100644 index 78e6ee85..00000000 --- a/extern/overrides.nix +++ /dev/null @@ -1,33 +0,0 @@ -# override defaults to nixpkgs/master -{ - # modules to pull from override, stable version is automatically disabled - modules = [ ]; - - # if a modules name changed in override, add the old name here - disabledModules = [ ]; - - # packages pulled from override - packages = pkgs: final: prev: { - inherit (pkgs) - cachix - dhall - discord - element-desktop - manix - nixpkgs-fmt - qutebrowser - signal-desktop - starship; - - haskellPackages = prev.haskellPackages.override { - overrides = hfinal: hprev: - let version = prev.lib.replaceChars [ "." ] [ "" ] prev.ghc.version; - in - { - # same for haskell packages, matching ghc versions - inherit (pkgs.haskell.packages."ghc${version}") - haskell-language-server; - }; - }; - }; -} diff --git a/flake.lock b/flake.lock index b862c3f7..90ffa98d 100644 --- a/flake.lock +++ b/flake.lock @@ -12,7 +12,7 @@ "nixos" ], "nixos-unstable": [ - "override" + "latest" ], "pre-commit-hooks-nix": "pre-commit-hooks-nix" }, @@ -33,7 +33,7 @@ "darwin": { "inputs": { "nixpkgs": [ - "override" + "latest" ] }, "locked": { @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-y0IZEAqpQpdGhxfc6REAT2PY2nEbikusUlXCRv264vI=", + "narHash": "sha256-MvrBYZG6sZqpa8mTg4RYeD9aezYbVppBnslRyH7qZys=", "path": "./lib", "type": "path" }, @@ -173,10 +173,24 @@ "type": "github" } }, + "latest": { + "locked": { + "lastModified": 1619400530, + "narHash": "sha256-7ZO7B+b9i1wFbHw62EFT+iwuBBpXeA/fcHlR63Z4J0w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e8dc8adab655eb27957859c62bef11484b53f639", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, "naersk": { "inputs": { "nixpkgs": [ - "override" + "latest" ] }, "locked": { @@ -197,7 +211,7 @@ "naersk_2": { "inputs": { "nixpkgs": [ - "override" + "latest" ] }, "locked": { @@ -274,20 +288,6 @@ "type": "indirect" } }, - "override": { - "locked": { - "lastModified": 1615926763, - "narHash": "sha256-yeq8A3EPNuQVlsxlEQrIRsklfJwJK0Us6jtcG/u8wNs=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "b702a56d417647de4090ac56c0f18bdc7e646610", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, "pkgs": { "inputs": { "nixpkgs": [ @@ -327,11 +327,11 @@ "devos": "devos", "flake-compat": "flake-compat_2", "home": "home", + "latest": "latest", "naersk": "naersk_2", "nixos": "nixos", "nixos-hardware": "nixos-hardware", "nur": "nur", - "override": "override", "pkgs": "pkgs" } }, diff --git a/flake.nix b/flake.nix index bad78f1f..5591fb04 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,7 @@ inputs = { nixos.url = "nixpkgs/nixos-unstable"; - override.url = "nixpkgs"; + latest.url = "nixpkgs"; devos.url = "path:./lib"; # TODO: outfactor into separate repo devos.inputs = { nixpkgs.follows = "nixos"; @@ -17,38 +17,74 @@ 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"; }; + inputs = { nix-darwin.follows = "darwin"; flake-compat.follows = "flake-compat"; nixos-20_09.follows = "nixos"; nixos-unstable.follows = "latest"; }; }; darwin.url = "github:LnL7/nix-darwin"; - darwin.inputs.nixpkgs.follows = "override"; + darwin.inputs.nixpkgs.follows = "latest"; flake-compat.url = "github:BBBSnowball/flake-compat/pr-1"; flake-compat.flake = false; home.url = "github:nix-community/home-manager"; home.inputs.nixpkgs.follows = "nixos"; naersk.url = "github:nmattia/naersk"; - naersk.inputs.nixpkgs.follows = "override"; + naersk.inputs.nixpkgs.follows = "latest"; nixos-hardware.url = "github:nixos/nixos-hardware"; pkgs.url = "path:./pkgs"; pkgs.inputs.nixpkgs.follows = "nixos"; }; - outputs = inputs@{ self, devos, nixos, nur, ... }: + outputs = inputs@{ self, pkgs, devos, nixos, ci-agent, home, nixos-hardware, nur, ... }: devos.lib.mkFlake { - inherit self inputs nixos; - hosts = ./hosts; - packages = import ./pkgs; - suites = import ./profiles/suites.nix; - extern = import ./extern; - overrides = import ./extern/overrides.nix; - 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"; - }; + inherit self inputs; + + channelsConfig = { allowUnfree = true; }; + + channels = { + nixos = { + overlays = nixos.lib.flatten [ + (devos.lib.pathsIn ./overlays) + pkgs.overlay + ./overrides.nix # from "latest" channel + nur.overlay + ]; + }; + latest = { }; + }; + + nixos = { + hostDefaults = { + system = "x86_64-linux"; + channelName = "nixos"; + modules = ./modules/module-list.nix; + externalModules = [ + ci-agent.nixosModules.agent-profile + home.nixosModules.home-manager + ]; + }; + hosts = { + NixOS = { + modules = ./hosts/NixOS.nix; + }; + }; + profiles = [ ./profiles ./users ]; + suites = { profiles, users, ... }: with profiles; { + base = [ core users.nixos users.root ]; + }; + }; + + home = { + modules = ./users/modules/module-list.nix; + externalModules = [ ]; + profiles = [ ./users/profiles ]; + suites = { profiles, ... }: with profiles; { + base = [ direnv git ]; + }; + }; + + #defaultTemplate = self.templates.flk; + templates.flk.path = ./.; + templates.flk.description = "flk template"; + + } + ; } diff --git a/overrides.nix b/overrides.nix new file mode 100644 index 00000000..bb3cf68b --- /dev/null +++ b/overrides.nix @@ -0,0 +1,26 @@ +channels: final: prev: { + + inherit (channels.latest) + cachix + dhall + discord + element-desktop + manix + nixpkgs-fmt + qutebrowser + signal-desktop + starship; + + + haskellPackages = prev.haskellPackages.override { + overrides = hfinal: hprev: + let version = prev.lib.replaceChars [ "." ] [ "" ] prev.ghc.version; + in + { + # same for haskell packages, matching ghc versions + inherit (channels.latest.haskell.packages."ghc${version}") + haskell-language-server; + }; + }; + +} From 9f31d5d6d1e5c204fcf5ce938a8ae95528dddf4f Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 12:20:16 -0700 Subject: [PATCH 42/91] mkFlake: use inputs argument not self.inputs --- lib/mkFlake/default.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 3d285c73..ebeb86c2 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -65,7 +65,10 @@ lib.systemFlake (lib.recursiveUpdate deploy.nodes = os.mkNodes deploy self.nixosConfigurations; - overlays = lib.exporter.overlaysFromChannelsExporter { inherit (self) pkgs inputs; }; + overlays = lib.exporter.overlaysFromChannelsExporter { + inherit inputs; + inherit (self) pkgs; + }; packagesBuilder = lib.builder.packagesFromOverlaysBuilderConstructor self.overlays; From 37820fc2148051117feaa684fb52238cde71d25f Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 12:29:18 -0700 Subject: [PATCH 43/91] explain overlay exporting inputs workaround --- lib/mkFlake/default.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index ebeb86c2..cd8d0377 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -66,6 +66,10 @@ lib.systemFlake (lib.recursiveUpdate deploy.nodes = os.mkNodes deploy self.nixosConfigurations; overlays = lib.exporter.overlaysFromChannelsExporter { + /* since we can't detect overlays owned by self + we have to filter out ones exported by the inputs + optimally we would want a solution for NixOS/nix#4740 + */ inherit inputs; inherit (self) pkgs; }; From b766c693abd5530c1dc4fd16cd229addca7c3219 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 13:21:40 -0700 Subject: [PATCH 44/91] add pkgs overlay, pkgs.overlay is just for srcs --- flake.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 5591fb04..1e23cedb 100644 --- a/flake.nix +++ b/flake.nix @@ -43,7 +43,8 @@ nixos = { overlays = nixos.lib.flatten [ (devos.lib.pathsIn ./overlays) - pkgs.overlay + ./pkgs/default.nix + pkgs.overlay # for `srcs` ./overrides.nix # from "latest" channel nur.overlay ]; From 2a7d9e71096746cd19b56cdbf61ba1c910fb6013 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 13:30:10 -0700 Subject: [PATCH 45/91] fix suites test to match new mkSuites --- lib/tests/lib.nix | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/tests/lib.nix b/lib/tests/lib.nix index 66264787..e992df67 100644 --- a/lib/tests/lib.nix +++ b/lib/tests/lib.nix @@ -71,23 +71,19 @@ lib.runTests { }; }; - 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 = [ ]; - }; + testSuites = { + expr = os.mkSuites { + suites = { profiles, ... }: with profiles; { + bar = [ foo ]; }; + profiles = [ (./profiles) ]; }; + expected = { + bar = [ (toString ./profiles/foo) ]; + allProfiles = [ + (toString ./profiles/foo) + (toString ./profiles/t) + ]; + }; + }; } From ffe4836e35e8b4a1ef2d99292c1ea4a3df6ad821 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 18:29:05 -0700 Subject: [PATCH 46/91] update doc to match new template format and logic --- doc/concepts/extern.md | 47 ++++++++++++++++++--------------------- doc/concepts/hosts.md | 38 ++++++++++++++++++------------- doc/concepts/overrides.md | 42 ++++++++++++++-------------------- doc/concepts/suites.md | 8 ++++++- doc/outputs/overlays.md | 2 +- doc/start/from-nixos.md | 12 ++++++++-- doc/tests.md | 2 +- 7 files changed, 80 insertions(+), 71 deletions(-) diff --git a/doc/concepts/extern.md b/doc/concepts/extern.md index 3b269122..171d8c58 100644 --- a/doc/concepts/extern.md +++ b/doc/concepts/extern.md @@ -1,45 +1,42 @@ # External Art When you need to use a module, overlay, or pass a value from one of your inputs -to the rest of your NixOS configuration, [extern][extern] is where you do it. +to the rest of your NixOS configuration, you can make use of a couple arguments. +It is encouraged to add external art directly in your `flake.nix` so the file +represents a complete dependency overview of your flake. -Modules and overlays are self explanatory, and the `specialArgs` attribute is -used to extend the arguments passed to all NixOS modules, allowing for -arbitrary values to be passed from flake inputs to the rest of your -configuration. +## Overlays +External overlays can directly be added to a channel's `overlays` list. -## Home Manager -There is also an `hmModules` attribute set for pulling home-manager modules in -from the outside world: - -### Declare: flake.nix: ```nix { - inputs.doom-emacs.url = "github:vlaci/nix-doom-emacs"; + channels.nixos.overlays = [ inputs.agenix.overlay ]; } ``` +These overlays will be automatically filtered by inspecting the `inputs` argument. -extern/default.nix: +## Modules +There is a dedicated `nixos.hostDefaults.externalModules` argument for external +modules. + +flake.nix: ```nix -with inputs; { - hmModules = { - doom-emacs = doom-emacs.hmModule; - }; + nixos.hostDefaults.externalModules = [ inputs.agenix.nixosModules.age ]; } ``` -### Use: -users/nixos/default.nix: +## Home Manager +Since there isn't a `hosts` concept for home-manager, externalModules is just a +top-level argument in the `home` namespace. + +flake.nix: ```nix -{ hmModules, ... }: { - home-manager.users.nixos = { - imports = [ hmModules.doom-emacs ] ; - - programs.doom-emacs.enable = true; - }; + home.externalModules = [ doom-emacs = doom-emacs.hmModule ]; } ``` -[extern]: https://github.com/divnix/devos/tree/core/extern/default.nix +> ##### Note: +> The optimal solution would be to automatically export modules that were created in +> your flake. But this is not possible due to NixOS/nix#4740. diff --git a/doc/concepts/hosts.md b/doc/concepts/hosts.md index 0a74dd12..770fa51b 100644 --- a/doc/concepts/hosts.md +++ b/doc/concepts/hosts.md @@ -1,19 +1,18 @@ # Hosts Nix flakes contain an output called `nixosConfigurations` declaring an -attribute set of valid NixOS systems. To simplify the management and creation -of these hosts, devos automatically imports every _.nix_ file inside this -directory to the mentioned attribute set, applying the projects defaults to -each. The only hard requirement is that the file contain a valid NixOS module. +attribute set of valid NixOS systems. To create hosts, you can use the +`nixos.hosts` argument and pass `modules` to each host. Host-specific modules +typically go in the `hosts` folder of the template. -As an example, a file `hosts/system.nix` will be available via the flake -output `nixosConfigurations.system`. You can have as many hosts as you want -and all of them will be automatically imported based on their name. +Each host should follow a certain channel to define the `pkgs` of that host. +You can use the `nixos.hostDefaults` to set defaults and global modules for all +hosts. For each host, the configuration automatically sets the `networking.hostName` -attribute to the name of the file minus the _.nix_ extension. This is for -convenience, since `nixos-rebuild` automatically searches for a configuration -matching the current systems hostname if one is not specified explicitly. +attribute to the name of the host. This is for convenience, since `nixos-rebuild` +automatically searches for a configuration matching the current systems hostname +if one is not specified explicitly. It is recommended that the host modules only contain configuration information specific to a particular piece of hardware. Anything reusable across machines @@ -22,12 +21,8 @@ is best saved for [profile modules](./profiles.md). This is a good place to import sets of profiles, called [suites](./suites.md), that you intend to use on your machine. -Additionally, this is the perfect place to import anything you might need from -the [nixos-hardware][nixos-hardware] repository. - -> ##### _Note:_ -> Set `nixpkgs.system` to the architecture of this host, default is "x86_64-linux". -> Keep in mind that not all packages are available for all architectures. +Additionally, you can pass modules from [nixos-hardware][nixos-hardware] in the +`modules` argument for relevant hosts. ## Example @@ -44,4 +39,15 @@ hosts/librem.nix: } ``` +flake.nix +```nix +{ + nixos.hosts.librem = { + system = "aarch64-linux"; + modules = ./hosts/librem.nix; + }; +} +``` + + [nixos-hardware]: https://github.com/NixOS/nixos-hardware diff --git a/doc/concepts/overrides.md b/doc/concepts/overrides.md index 28194cd1..78b50fd1 100644 --- a/doc/concepts/overrides.md +++ b/doc/concepts/overrides.md @@ -1,47 +1,39 @@ # Overrides -By default, the NixOS systems are based on unstable. While it is trivial to -change this to a stable release, or any other branch of nixpkgs by -changing the flake url, sometimes all we want is a single package from another -branch. +Each NixOS host follows one channel. But many times it is useful to get packages +or modules from different channels. -This is what the overrides are for. By default, they are pulled directly from -nixpkgs/master, but you can change the `override` flake input url to -nixos-unstable, or even a specific sha revision. - -They are defined in the `extern/overrides.nix` file. +This is what the overrides are for. You can make use of the `overrides.nix` to +override specific packages to be pulled from other channels. Any overlay may get +`channels` as their first argument. ## Example ### Packages The override packages are defined as a regular overlay with an extra arguement -`pkgs`. This refers to the packages built from the `override` flake. +`channels`. This refers to all channels defined in `flake.nix`. -Pulling the manix package from the override flake: +Pulling the manix package from the latest flake: ```nix -{ - packages = pkgs: final: prev: { - inherit (pkgs) manix; - }; +channels: final: prev: { + inherit (pkgs.latest) manix; } ``` ### Modules -You can also pull modules from override. Simply specify their path relative to -the nixpkgs [modules][nixpkgs-modules] directory. The old version will be added -to `disabledModules` and the new version imported into the configuration. +You can also pull modules from other channels. All modules have access to the +`modulesPath` for each channel as `ModulesPath`. And you can use +`disabledModules` to remove modules from the current channel. -Pulling the zsh module from the override flake: +Pulling the zsh module from the latest flake: ```nix -{ - modules = [ "programs/zsh/zsh.nix" ]; +{ latestModulesPath }: { + modules = [ "${latestModulesPath}/programs/zsh/zsh.nix" ]; + disabledModules = [ "programs/zsh/zsh.nix" ]; } ``` > ##### _Note:_ -> Sometimes a modules name will change from one branch to another. This is what -> the `disabledModules` list is for. If the module name changes, the old -> version will not automatically be disabled, so simply put it's old name in -> this list to disable it. +> Sometimes a modules name will change from one branch to another. [nixpkgs-modules]: https://github.com/NixOS/nixpkgs/tree/master/nixos/modules diff --git a/doc/concepts/suites.md b/doc/concepts/suites.md index e6a8bff7..5c0d5909 100644 --- a/doc/concepts/suites.md +++ b/doc/concepts/suites.md @@ -6,7 +6,13 @@ profiles. For good examples, check out the suites defined in the community In the future, we will use suites as a mechanism for deploying various machine types which don't depend on hardware, such as vm's and containers. -They are defined in `profiles/suites.nix`. +They are defined with the `suites` argument in either `home` or `nixos` namespace. +Suites should be passed as a function that take profiles as an argument. + +The profiles are passed based on the folder names and list passed to the relevant +`profiles` argument. In the template's flake.nix `profiles` is set as +`[ ./profiles ./users ]` and that corresponds to the `{ profiles, users }` argument +pattern. ## Definition ```nix diff --git a/doc/outputs/overlays.md b/doc/outputs/overlays.md index d71b4597..f463d1a7 100644 --- a/doc/outputs/overlays.md +++ b/doc/outputs/overlays.md @@ -4,7 +4,7 @@ we want to keep the process as simple and straightforward as possible. Any _.nix_ files declared in this directory will be assumed to be a valid overlay, and will be automatically imported into all [hosts](../concepts/hosts.md), and -exported via `overlays.` _as well as_ +exported via `overlays./` _as well as_ `packages..` (for valid systems), so all you have to do is write it. diff --git a/doc/start/from-nixos.md b/doc/start/from-nixos.md index bbb0e551..9b0b3f57 100644 --- a/doc/start/from-nixos.md +++ b/doc/start/from-nixos.md @@ -10,10 +10,18 @@ flk up This will make a new file `hosts/up-$(hostname).nix`, which you can edit to your liking. +You must then add a host to `nixos.hosts` in flake.nix: +```nix +{ + nixos.hosts = { + modules = hosts/NixOS.nix; + }; +} +``` + Make sure your `i18n.defaultLocale` and `time.timeZone` are set properly for your region. Keep in mind that `networking.hostName` with be automatically -set to the filename of your hosts file, so `hosts/my-host.nix` will have the -hostname `my-host`. +set to the name of your host; Now might be a good time to read the docs on [suites](../concepts/suites.md) and [profiles](../concepts/profiles.md) and add or create any that you need. diff --git a/doc/tests.md b/doc/tests.md index 033d75af..f6fd7fe9 100644 --- a/doc/tests.md +++ b/doc/tests.md @@ -7,7 +7,7 @@ configuration, and, optionally, run them in ## Lib Tests You can easily write tests for your own library functions in the -___tests/lib.nix___ file and they will be run on every `nix flake check` or +lib/___tests/lib.nix___ file and they will be run on every `nix flake check` or during a CI run. ## Unit Tests From a6344faa9afd17efb8b2069c2332ac302d98944e Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 19:30:55 -0700 Subject: [PATCH 47/91] update fup to fix infinite recursion error --- flake.lock | 8 ++++---- lib/flake.lock | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/flake.lock b/flake.lock index 90ffa98d..13482c4f 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-MvrBYZG6sZqpa8mTg4RYeD9aezYbVppBnslRyH7qZys=", + "narHash": "sha256-clwJnNLVOASak2CfkWu3Yztb1uWwtndY4VLDWEa9R3s=", "path": "./lib", "type": "path" }, @@ -355,11 +355,11 @@ "flake-utils": "flake-utils" }, "locked": { - "lastModified": 1619438935, - "narHash": "sha256-B8OGqX9QBMW5G8DYTRdY0cb62ETaV0YxBayCZMiaVqQ=", + "lastModified": 1619480667, + "narHash": "sha256-KBiMpZcCv7D3wQ51ow7Sq8Xl01hDiRp5f7Py93CeD40=", "owner": "gytis-ivaskevicius", "repo": "flake-utils-plus", - "rev": "80b53eeda3102bb5aed31ec818c6485e35caffc3", + "rev": "be032a4396ad4cd7ea9bb733db8e456ec339ac9c", "type": "github" }, "original": { diff --git a/lib/flake.lock b/lib/flake.lock index 6942e2a8..eda785b8 100644 --- a/lib/flake.lock +++ b/lib/flake.lock @@ -146,11 +146,11 @@ "flake-utils": "flake-utils" }, "locked": { - "lastModified": 1619438935, - "narHash": "sha256-B8OGqX9QBMW5G8DYTRdY0cb62ETaV0YxBayCZMiaVqQ=", + "lastModified": 1619480667, + "narHash": "sha256-KBiMpZcCv7D3wQ51ow7Sq8Xl01hDiRp5f7Py93CeD40=", "owner": "gytis-ivaskevicius", "repo": "flake-utils-plus", - "rev": "80b53eeda3102bb5aed31ec818c6485e35caffc3", + "rev": "be032a4396ad4cd7ea9bb733db8e456ec339ac9c", "type": "github" }, "original": { From b6c00e74e7c6e574ee72d40141a36adff2ebeccc Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 19:33:31 -0700 Subject: [PATCH 48/91] set add self and hosts module arguments --- lib/modules.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/modules.nix b/lib/modules.nix index 2cd965ff..6e2a3525 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -41,6 +41,12 @@ } ''; + _module.args = { + inherit self; + hosts = builtins.mapAttrs (_: host: host.config) + (removeAttrs self.nixosConfigurations [ config.networking.hostName ]); + }; + system.configurationRevision = lib.mkIf (self ? rev) self.rev; }; From e9675330a7b3717cf6abf090a34b5bf1ac23201a Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 19:34:18 -0700 Subject: [PATCH 49/91] add cachix to base suite to follow the new api --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 1e23cedb..aca677b9 100644 --- a/flake.nix +++ b/flake.nix @@ -69,7 +69,7 @@ }; profiles = [ ./profiles ./users ]; suites = { profiles, users, ... }: with profiles; { - base = [ core users.nixos users.root ]; + base = [ cachix core users.nixos users.root ]; }; }; From 278ae0e108633b70214d1176ed38883910f46e68 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 21:32:26 -0700 Subject: [PATCH 50/91] set _module.check in evalArgs instead of mkFlake this makes more sense since evalArgs is the module and it makes the code cleaner --- lib/mkFlake/default.nix | 2 +- lib/mkFlake/evalArgs.nix | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index cd8d0377..45d99bd2 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -8,7 +8,7 @@ _: { self, inputs, ... } @ args: let config = lib.mkFlake.evalArgs { - args = lib.mkMerge [ args { _module.check = false; } ]; + inherit args; }; cfg = config.config; diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 5884dcfb..1a15dc8e 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -187,6 +187,10 @@ let }; in { + # this does not get propagated to submodules + # to allow passing flake outputs directly to mkFlake + config._module.check = false; + options = with types; { self = mkOption { type = flakeType; From c41d3eed0662956c4ad3afd958ebea0be29fcd89 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 21:32:57 -0700 Subject: [PATCH 51/91] drop debugging related mkFlakeConfig output was only meant for debugging, not meant to be commited --- lib/mkFlake/default.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 45d99bd2..bcab7a13 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -33,8 +33,6 @@ lib.systemFlake (lib.recursiveUpdate inherit self inputs; inherit (cfg) channelsConfig supportedSystems; - mkFlakeConfig = config; - channels = mapAttrs (name: channel: channel // { From 064ba88cdf6ce391cdbe3e4df72363276dbb5ebd Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 21:38:27 -0700 Subject: [PATCH 52/91] improve, build, and add mkFlake options doc --- doc/mkFlakeOptions.md | 407 +++++++++++++++++++++++++++++++++++++++ lib/mkFlake/evalArgs.nix | 25 ++- 2 files changed, 425 insertions(+), 7 deletions(-) create mode 100644 doc/mkFlakeOptions.md diff --git a/doc/mkFlakeOptions.md b/doc/mkFlakeOptions.md new file mode 100644 index 00000000..42b1f60f --- /dev/null +++ b/doc/mkFlakeOptions.md @@ -0,0 +1,407 @@ +## channels +nixpkgs channels to create + + +*_Type_*: +attribute set of submodules + + +*_Default_* +``` +{} +``` + + + + +## channels.\.config +nixpkgs config for this channel + + +*_Type_*: +attribute set or path convertible to it + + +*_Default_* +``` +{} +``` + + + + +## channels.\.input +nixpkgs flake input to use for this channel + + +*_Type_*: +nix flake + + +*_Default_* +``` +"inputs.\\" +``` + + + + +## channels.\.overlays +overlays to apply to this channel +these will get exported under the 'overlays' flake output +as \/\ and any overlay pulled from ${inputs} +will be filtered out + + +*_Type_*: +list of valid Nixpkgs overlay or path convertible to its or path convertible to it + + +*_Default_* +``` +[] +``` + + + + +## channelsConfig +nixpkgs config for all channels + + +*_Type_*: +attribute set or path convertible to it + + +*_Default_* +``` +{} +``` + + + + +## home +hosts, modules, suites, and profiles for home-manager + + +*_Type_*: +submodule + + +*_Default_* +``` +{} +``` + + + + +## home.externalModules +modules to include that won't be exported +meant importing modules from external flakes + + +*_Type_*: +list of valid module or path convertible to its + + +*_Default_* +``` +[] +``` + + + + +## home.modules +modules to include in all hosts and export to homeModules output + + +*_Type_*: +list of paths or path convertible to it + + +*_Default_* +``` +[] +``` + + + + +## home.profiles +profile folders that can be collected into suites +the name of the argument passed to suites is based +on the folder name. +[ ./profiles ] => { profiles }: + + +*_Type_*: +list of paths + + +*_Default_* +``` +[] +``` + + + + +## home.suites +Function that takes profiles and returns suites for this config system +These can be accessed through the 'suites' special argument. + + +*_Type_*: +function that evaluates to a(n) attrs or path convertible to it + + +*_Default_* +``` +"" +``` + + + + +## inputs +inputs for this flake +used to set channel defaults and create registry + + +*_Type_*: +attribute set of nix flakes + + + + + + +## nixos +hosts, modules, suites, and profiles for nixos + + +*_Type_*: +submodule + + +*_Default_* +``` +{} +``` + + + + +## nixos.hostDefaults +Defaults for all hosts. +the modules passed under hostDefaults will be exported +to the 'nixosModules' flake output. +They will also be added to all hosts. + + +*_Type_*: +submodule + + +*_Default_* +``` +{} +``` + + + + +## nixos.hostDefaults.channelName +Channel this host should follow + + +*_Type_*: +a channel defined in `channels` + + +*_Default_* +``` +null +``` + + + + +## nixos.hostDefaults.externalModules +modules to include that won't be exported +meant importing modules from external flakes + + +*_Type_*: +list of valid module or path convertible to its + + +*_Default_* +``` +[] +``` + + + + +## nixos.hostDefaults.modules +modules to include in all hosts and export to nixosModules output + + +*_Type_*: +list of paths or path convertible to it + + +*_Default_* +``` +[] +``` + + + + +## nixos.hostDefaults.system +system for this host + + +*_Type_*: +system defined in `supportedSystems` + + +*_Default_* +``` +null +``` + + + + +## nixos.hosts +configurations to include in the nixosConfigurations output + + +*_Type_*: +attribute set of submodules + + +*_Default_* +``` +{} +``` + + + + +## nixos.hosts.\.channelName +Channel this host should follow + + +*_Type_*: +a channel defined in `channels` + + +*_Default_* +``` +null +``` + + + + +## nixos.hosts.\.modules +modules to include + + +*_Type_*: +list of valid module or path convertible to its or valid module or path convertible to it convertible to it + + +*_Default_* +``` +[] +``` + + + + +## nixos.hosts.\.system +system for this host + + +*_Type_*: +system defined in `supportedSystems` + + +*_Default_* +``` +null +``` + + + + +## nixos.profiles +profile folders that can be collected into suites +the name of the argument passed to suites is based +on the folder name. +[ ./profiles ] => { profiles }: + + +*_Type_*: +list of paths + + +*_Default_* +``` +[] +``` + + + + +## nixos.suites +Function that takes profiles and returns suites for this config system +These can be accessed through the 'suites' special argument. + + +*_Type_*: +function that evaluates to a(n) attrs or path convertible to it + + +*_Default_* +``` +"" +``` + + + + +## self +The flake to create the devos outputs for + +*_Type_*: +nix flake + + + + + + +## supportedSystems +The systems supported by this flake + + +*_Type_*: +list of strings + + +*_Default_* +``` +["aarch64-linux","i686-linux","x86_64-darwin","x86_64-linux"] +``` + + + diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 1a15dc8e..55b37950 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -56,7 +56,9 @@ let default = [ ]; description = escape [ "<" ">" ] '' overlays to apply to this channel - these will get exported under the 'overlays' flake output as / + these will get exported under the 'overlays' flake output + as / and any overlay pulled from ''\${inputs} + will be filtered out ''; }; config = mkOption { @@ -74,14 +76,18 @@ let options = with types; { # anything null in hosts gets filtered out by mkFlake system = mkOption { - type = nullOr systemType; + type = (nullOr systemType) // { + description = "system defined in `supportedSystems`"; + }; default = null; description = '' system for this host ''; }; channelName = mkOption { - type = nullOr (types.enum (builtins.attrNames config.channels)); + type = (nullOr (types.enum (builtins.attrNames config.channels))) // { + description = "a channel defined in `channels`"; + }; default = null; description = '' Channel this host should follow @@ -98,7 +104,8 @@ let type = with types; listOf moduleType; default = [ ]; description = '' - The configuration for this host + modules to include that won't be exported + meant importing modules from external flakes ''; }; }; @@ -168,7 +175,12 @@ let profiles = mkOption { type = listOf path; default = [ ]; - description = "path to profiles folder that can be collected into suites"; + description = '' + profile folders that can be collected into suites + the name of the argument passed to suites is based + on the folder name. + [ ./profiles ] => { profiles }: + ''; }; suites = mkOption { type = pathTo (functionTo attrs); @@ -178,8 +190,7 @@ let inherit (config) profiles; }; description = '' - Function with the input of 'profiles' that returns an attribute set - with the suites for this config system. + Function that takes profiles and returns suites for this config system These can be accessed through the 'suites' special argument. ''; }; From 466304c8cd6d45a62b0e0c82638ce13fc9badaa7 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 08:01:46 -0700 Subject: [PATCH 53/91] improve passing host and channel arguments to fup we need to filter out arguments that are added in the devos api also anything thats null in either hostDefaults and hosts has to be removed --- flake.lock | 8 ++++---- lib/flake.lock | 6 +++--- lib/mkFlake/default.nix | 32 ++++++++++++++++++-------------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/flake.lock b/flake.lock index 13482c4f..6d239faa 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-clwJnNLVOASak2CfkWu3Yztb1uWwtndY4VLDWEa9R3s=", + "narHash": "sha256-TOrVXGFk5rt1Wn14ja2spg44NuZnFM/V6qguQfO+8Kc=", "path": "./lib", "type": "path" }, @@ -355,11 +355,11 @@ "flake-utils": "flake-utils" }, "locked": { - "lastModified": 1619480667, - "narHash": "sha256-KBiMpZcCv7D3wQ51ow7Sq8Xl01hDiRp5f7Py93CeD40=", + "lastModified": 1619532520, + "narHash": "sha256-+xIFAW5J0AcxwAflAX1gg/C8kfaqeZbS4XAZusCrZPY=", "owner": "gytis-ivaskevicius", "repo": "flake-utils-plus", - "rev": "be032a4396ad4cd7ea9bb733db8e456ec339ac9c", + "rev": "8eb7f9206713a528174c20c5133521dc37e2bfb1", "type": "github" }, "original": { diff --git a/lib/flake.lock b/lib/flake.lock index eda785b8..ebf5e6d3 100644 --- a/lib/flake.lock +++ b/lib/flake.lock @@ -146,11 +146,11 @@ "flake-utils": "flake-utils" }, "locked": { - "lastModified": 1619480667, - "narHash": "sha256-KBiMpZcCv7D3wQ51ow7Sq8Xl01hDiRp5f7Py93CeD40=", + "lastModified": 1619532520, + "narHash": "sha256-+xIFAW5J0AcxwAflAX1gg/C8kfaqeZbS4XAZusCrZPY=", "owner": "gytis-ivaskevicius", "repo": "flake-utils-plus", - "rev": "be032a4396ad4cd7ea9bb733db8e456ec339ac9c", + "rev": "8eb7f9206713a528174c20c5133521dc37e2bfb1", "type": "github" }, "original": { diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index bcab7a13..7b12cf41 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -25,35 +25,39 @@ let }) ]; + stripChannel = channel: removeAttrs channel [ + # arguments in our channels api that shouldn't be passed to fup + "overlays" + ]; getDefaultChannel = channels: channels.${cfg.nixos.hostDefaults.channelName}; + + # evalArgs sets channelName and system to null by default + # but for proper default handling in fup, null args have to be removed + stripHost = args: removeAttrs (lib.filterAttrs (_: arg: arg != null) args) [ + # arguments in our hosts/hostDefaults api that shouldn't be passed to fup + "externalModules" + ]; + hosts = lib.mapAttrs (_: stripHost) cfg.nixos.hosts; + hostDefaults = stripHost cfg.nixos.hostDefaults; in lib.systemFlake (lib.recursiveUpdate otherArguments { - inherit self inputs; + inherit self inputs hosts; inherit (cfg) channelsConfig supportedSystems; channels = mapAttrs (name: channel: - channel // { + stripChannel (channel // { # pass channels if "overlay" has three arguments overlaysBuilder = channels: lib.unifyOverlays channels channel.overlays; - } + }) ) cfg.channels; - # the host arguments cannot exist for fup hostDefaults to work - # so evalArgs sets them to null by default and the null args are filtered out here - hosts = mapAttrs (_: host: lib.filterAttrs (_: arg: arg != null) host) cfg.nixos.hosts; - - hostDefaults = { + hostDefaults = lib.mergeAny hostDefaults { specialArgs.suites = cfg.nixos.suites; - modules = cfg.nixos.hostDefaults.modules - ++ cfg.nixos.hostDefaults.externalModules - ++ defaultModules; + modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules; builder = os.devosSystem { inherit self inputs; }; - inherit (cfg.nixos.hostDefaults) - channelName - system; }; nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules; From 7f3116c1ccb2aa4f6375fa4b45c9863a62656d4f Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 09:30:28 -0700 Subject: [PATCH 54/91] safeReadDir: conver path to string for reliability --- lib/attrs.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/attrs.nix b/lib/attrs.nix index 1ecc2544..d1bc7648 100644 --- a/lib/attrs.nix +++ b/lib/attrs.nix @@ -41,5 +41,6 @@ rec { in lib.filterAttrs filter packages; - safeReadDir = path: lib.optionalAttrs (builtins.pathExists path) (builtins.readDir path); + safeReadDir = path: + lib.optionalAttrs (builtins.pathExists (toString path)) (builtins.readDir (toString path)); } From f57840d723785bc22ad93f0ba17725a620ee9481 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 09:32:12 -0700 Subject: [PATCH 55/91] mkFlake/default.nix: formatting --- lib/mkFlake/default.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 7b12cf41..bf571ec4 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -52,7 +52,8 @@ lib.systemFlake (lib.recursiveUpdate # pass channels if "overlay" has three arguments overlaysBuilder = channels: lib.unifyOverlays channels channel.overlays; }) - ) cfg.channels; + ) + cfg.channels; hostDefaults = lib.mergeAny hostDefaults { specialArgs.suites = cfg.nixos.suites; @@ -68,10 +69,9 @@ lib.systemFlake (lib.recursiveUpdate deploy.nodes = os.mkNodes deploy self.nixosConfigurations; overlays = lib.exporter.overlaysFromChannelsExporter { - /* since we can't detect overlays owned by self - we have to filter out ones exported by the inputs - optimally we would want a solution for NixOS/nix#4740 - */ + # since we can't detect overlays owned by self + # we have to filter out ones exported by the inputs + # optimally we would want a solution for NixOS/nix#4740 inherit inputs; inherit (self) pkgs; }; From e67b49c2804902b7b4a3c3e74a59aa1667663f1e Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 09:35:44 -0700 Subject: [PATCH 56/91] auto-flatten coercedListOf and type fixes --- flake.nix | 2 +- lib/mkFlake/evalArgs.nix | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/flake.nix b/flake.nix index aca677b9..c2a87add 100644 --- a/flake.nix +++ b/flake.nix @@ -41,7 +41,7 @@ channels = { nixos = { - overlays = nixos.lib.flatten [ + overlays = [ (devos.lib.pathsIn ./overlays) ./pkgs/default.nix pkgs.overlay # for `srcs` diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 55b37950..fe49bc3b 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -21,6 +21,12 @@ let inherit (submodule { }) check; description = "valid module"; }); + + # to export modules we need paths to get the name + exportModuleType = with types; + (addCheck path (x: moduleType.check (import x))) // { + description = "path to a module"; + }; overlayType = pathTo (types.anything // { check = builtins.isFunction; description = "valid Nixpkgs overlay"; @@ -37,7 +43,7 @@ let pathToListOf = elemType: with types; pathTo (listOf elemType); coercedListOf = elemType: with types; - coercedTo elemType (x: flatten (singleton x)) (listOf elemType); + coercedTo anything (x: flatten (singleton x)) (listOf elemType); /* Submodules needed for API containers */ @@ -52,7 +58,7 @@ let ''; }; overlays = mkOption { - type = pathToListOf overlayType; + type = coercedListOf overlayType; default = [ ]; description = escape [ "<" ">" ] '' overlays to apply to this channel @@ -126,10 +132,7 @@ let exportModulesModule = name: { options = { modules = mkOption { - type = with types; pathToListOf - # check if the path evaluates to a proper module - # but this must be a path for the export to work - (addCheck path (x: moduleType.check (import x))); + type = with types; pathTo (coercedListOf exportModuleType); default = [ ]; description = '' modules to include in all hosts and export to ${name}Modules output From d5276195f77d1a821454a267bd8b774a8cf896b3 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 09:38:20 -0700 Subject: [PATCH 57/91] move overrides.nix to overlays also update overrides docs it is a pure devos overlay now, it makes sense to go in overlays --- doc/concepts/overrides.md | 19 ++++++++----------- flake.nix | 1 - overrides.nix => overlays/overrides.nix | 0 3 files changed, 8 insertions(+), 12 deletions(-) rename overrides.nix => overlays/overrides.nix (100%) diff --git a/doc/concepts/overrides.md b/doc/concepts/overrides.md index 78b50fd1..0eb1002e 100644 --- a/doc/concepts/overrides.md +++ b/doc/concepts/overrides.md @@ -2,30 +2,27 @@ Each NixOS host follows one channel. But many times it is useful to get packages or modules from different channels. -This is what the overrides are for. You can make use of the `overrides.nix` to -override specific packages to be pulled from other channels. Any overlay may get -`channels` as their first argument. +## Packages +You can make use of `overlays/overrides.nix` to override specific packages in the +default channel to be pulled from other channels. That file is simply an example +of how any overlay can get `channels` as their first argument. -## Example +You can add overlays to any channel to override packages from other channels. -### Packages -The override packages are defined as a regular overlay with an extra arguement -`channels`. This refers to all channels defined in `flake.nix`. - -Pulling the manix package from the latest flake: +Pulling the manix package from the `latest` channel: ```nix channels: final: prev: { inherit (pkgs.latest) manix; } ``` -### Modules +## Modules You can also pull modules from other channels. All modules have access to the `modulesPath` for each channel as `ModulesPath`. And you can use `disabledModules` to remove modules from the current channel. -Pulling the zsh module from the latest flake: +Pulling the zsh module from the `latest` channel: ```nix { latestModulesPath }: { modules = [ "${latestModulesPath}/programs/zsh/zsh.nix" ]; diff --git a/flake.nix b/flake.nix index c2a87add..5468f5a5 100644 --- a/flake.nix +++ b/flake.nix @@ -45,7 +45,6 @@ (devos.lib.pathsIn ./overlays) ./pkgs/default.nix pkgs.overlay # for `srcs` - ./overrides.nix # from "latest" channel nur.overlay ]; }; diff --git a/overrides.nix b/overlays/overrides.nix similarity index 100% rename from overrides.nix rename to overlays/overrides.nix From a7cd35e433c566c5961db1a0b35a775b0dd3d73f Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 09:47:31 -0700 Subject: [PATCH 58/91] update lib subflake lock --- flake.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.lock b/flake.lock index 6d239faa..7841db57 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-TOrVXGFk5rt1Wn14ja2spg44NuZnFM/V6qguQfO+8Kc=", + "narHash": "sha256-r+OPJF65PToVQK1ll2INAYmIV3zmnDzWBpGLx8m4aVo=", "path": "./lib", "type": "path" }, From df39cb692e7df07a8b7f6531303620888eadeca3 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 09:52:56 -0700 Subject: [PATCH 59/91] rebuild and update mkFlakeOptions.md --- doc/mkFlakeOptions.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/mkFlakeOptions.md b/doc/mkFlakeOptions.md index 42b1f60f..9b0e7262 100644 --- a/doc/mkFlakeOptions.md +++ b/doc/mkFlakeOptions.md @@ -54,7 +54,7 @@ will be filtered out *_Type_*: -list of valid Nixpkgs overlay or path convertible to its or path convertible to it +list of valid Nixpkgs overlay or path convertible to its or anything convertible to it *_Default_* @@ -119,7 +119,7 @@ modules to include in all hosts and export to homeModules output *_Type_*: -list of paths or path convertible to it +list of path to a modules or anything convertible to it or path convertible to it *_Default_* @@ -252,7 +252,7 @@ modules to include in all hosts and export to nixosModules output *_Type_*: -list of paths or path convertible to it +list of path to a modules or anything convertible to it or path convertible to it *_Default_* @@ -316,7 +316,7 @@ modules to include *_Type_*: -list of valid module or path convertible to its or valid module or path convertible to it convertible to it +list of valid module or path convertible to its or anything convertible to it *_Default_* From aa825b87a6a16a8a663e14f52155bc924d28bad1 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 10:26:45 -0700 Subject: [PATCH 60/91] auto import hosts in flake.nix this allows host-specific settings to be overriden with mkMerge --- doc/concepts/hosts.md | 56 ++++++++++++++++++++++++------------------- flake.lock | 2 +- flake.nix | 9 ++++--- lib/attrs.nix | 8 +++++++ lib/flake.nix | 5 ++-- 5 files changed, 48 insertions(+), 32 deletions(-) diff --git a/doc/concepts/hosts.md b/doc/concepts/hosts.md index 770fa51b..1fa90284 100644 --- a/doc/concepts/hosts.md +++ b/doc/concepts/hosts.md @@ -1,18 +1,24 @@ # Hosts Nix flakes contain an output called `nixosConfigurations` declaring an -attribute set of valid NixOS systems. To create hosts, you can use the -`nixos.hosts` argument and pass `modules` to each host. Host-specific modules -typically go in the `hosts` folder of the template. +attribute set of valid NixOS systems. To simplify the management and creation +of these hosts, devos automatically imports every _.nix_ file inside this +directory to the mentioned attribute set, applying the projects defaults to +each. The only hard requirement is that the file contain a valid NixOS module. -Each host should follow a certain channel to define the `pkgs` of that host. -You can use the `nixos.hostDefaults` to set defaults and global modules for all -hosts. +As an example, a file `hosts/system.nix` will be available via the flake +output `nixosConfigurations.system`. You can have as many hosts as you want +and all of them will be automatically imported based on their name. For each host, the configuration automatically sets the `networking.hostName` -attribute to the name of the host. This is for convenience, since `nixos-rebuild` -automatically searches for a configuration matching the current systems hostname -if one is not specified explicitly. +attribute to the name of the file minus the _.nix_ extension. This is for +convenience, since `nixos-rebuild` automatically searches for a configuration +matching the current systems hostname if one is not specified explicitly. + +You can set channels, systems, and add extra modules to each host by editing the +`nixos.hosts` argument in flake.nix. This is the perfect place to import +host specific modules from external sources, such as the +[nixos-hardware][nixos-hardware] repository. It is recommended that the host modules only contain configuration information specific to a particular piece of hardware. Anything reusable across machines @@ -21,16 +27,29 @@ is best saved for [profile modules](./profiles.md). This is a good place to import sets of profiles, called [suites](./suites.md), that you intend to use on your machine. -Additionally, you can pass modules from [nixos-hardware][nixos-hardware] in the -`modules` argument for relevant hosts. ## Example +flake.nix: +```nix +{ + nixos.hosts = mkMerge [ + (devos.lib.importHosts ./hosts) + { + librem = { + channelName = "latest"; + modules = [ hardware.purism-librem-13v3 ]; + }; + } + ]; +} +``` + hosts/librem.nix: ```nix -{ suites, hardware, ... }: +{ suites, ... }: { - imports = suites.laptop ++ [ hardware.purism-librem-13v3 ]; + imports = suites.laptop; boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; @@ -39,15 +58,4 @@ hosts/librem.nix: } ``` -flake.nix -```nix -{ - nixos.hosts.librem = { - system = "aarch64-linux"; - modules = ./hosts/librem.nix; - }; -} -``` - - [nixos-hardware]: https://github.com/NixOS/nixos-hardware diff --git a/flake.lock b/flake.lock index 7841db57..91c20fdd 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-r+OPJF65PToVQK1ll2INAYmIV3zmnDzWBpGLx8m4aVo=", + "narHash": "sha256-hpvEXcpq85cDKi0F5UUsuMVISKlk8hgVJiz5FF29RwA=", "path": "./lib", "type": "path" }, diff --git a/flake.nix b/flake.nix index 5468f5a5..d30cc3a9 100644 --- a/flake.nix +++ b/flake.nix @@ -61,11 +61,10 @@ home.nixosModules.home-manager ]; }; - hosts = { - NixOS = { - modules = ./hosts/NixOS.nix; - }; - }; + hosts = nixos.lib.mkMerge [ + (devos.lib.importHosts ./hosts) + { /* set host specific properties here */ } + ]; profiles = [ ./profiles ./users ]; suites = { profiles, users, ... }: with profiles; { base = [ cachix core users.nixos users.root ]; diff --git a/lib/attrs.nix b/lib/attrs.nix index d1bc7648..93f79583 100644 --- a/lib/attrs.nix +++ b/lib/attrs.nix @@ -30,6 +30,14 @@ rec { value = import path; }); + importHosts = dir: + lib.os.recImport { + inherit dir; + _import = base: { + modules = import "${toString dir}/${base}.nix"; + }; + }; + concatAttrs = lib.fold (attr: sum: lib.recursiveUpdate sum attr) { }; # Filter out packages that support given system and follow flake check requirements diff --git a/lib/flake.nix b/lib/flake.nix index 17e069c2..2513311d 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -48,7 +48,8 @@ safeReadDir pathsToImportedAttrs concatAttrs - filterPackages; + filterPackages + importHosts; inherit (lists) pathsIn collectProfiles unifyOverlays; inherit (strings) rgxToString; inherit modules; @@ -60,7 +61,7 @@ { lib = utils.lib // { inherit (lib) - mkFlake pathsIn; + mkFlake pathsIn importHosts; }; } From bb9bc02478a197b28faaac35fa97e9d21fabb16a Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 12:52:16 -0700 Subject: [PATCH 61/91] fix channels.*.input defaultText formatting --- doc/mkFlakeOptions.md | 2 +- lib/mkFlake/evalArgs.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/mkFlakeOptions.md b/doc/mkFlakeOptions.md index 9b0e7262..90719ba1 100644 --- a/doc/mkFlakeOptions.md +++ b/doc/mkFlakeOptions.md @@ -40,7 +40,7 @@ nix flake *_Default_* ``` -"inputs.\\" +"inputs." ``` diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index fe49bc3b..ee42e224 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -52,7 +52,7 @@ let input = mkOption { type = flakeType; default = cfg.inputs.${name}; - defaultText = escape [ "<" ">" ] "inputs."; + defaultText = "inputs."; description = '' nixpkgs flake input to use for this channel ''; From 5bc88ad2c21d1872ccb15eddb7da6945824ceccc Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 16:36:07 -0700 Subject: [PATCH 62/91] don't use lockfile to get flake-compat lock file format isn't very reliable with naming inputs --- flake.nix | 2 -- lib/compat/default.nix | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index d30cc3a9..1b469f48 100644 --- a/flake.nix +++ b/flake.nix @@ -21,8 +21,6 @@ }; darwin.url = "github:LnL7/nix-darwin"; darwin.inputs.nixpkgs.follows = "latest"; - flake-compat.url = "github:BBBSnowball/flake-compat/pr-1"; - flake-compat.flake = false; home.url = "github:nix-community/home-manager"; home.inputs.nixpkgs.follows = "nixos"; naersk.url = "github:nmattia/naersk"; diff --git a/lib/compat/default.nix b/lib/compat/default.nix index 0a63b0bc..9d0c2837 100644 --- a/lib/compat/default.nix +++ b/lib/compat/default.nix @@ -1,12 +1,10 @@ let - inherit (lock.nodes.flake-compat.locked) rev narHash; - - lock = builtins.fromJSON (builtins.readFile "${../..}/flake.lock"); + rev = "e7e5d481a0e15dcd459396e55327749989e04ce0"; flake = (import ( fetchTarball { url = "https://github.com/edolstra/flake-compat/archive/${rev}.tar.gz"; - sha256 = narHash; + sha256 = "0zd3x46fswh5n6faq4x2kkpy6p3c6j593xbdlbsl40ppkclwc80x"; } ) { From a5dcb5fae9d6afbc75488b4c5136aa599868574b Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 18:41:51 -0700 Subject: [PATCH 63/91] fix flake by removing flake-compat follows --- flake.lock | 30 +++++++++++++----------------- flake.nix | 2 +- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/flake.lock b/flake.lock index 91c20fdd..f7770ee8 100644 --- a/flake.lock +++ b/flake.lock @@ -2,9 +2,7 @@ "nodes": { "ci-agent": { "inputs": { - "flake-compat": [ - "flake-compat" - ], + "flake-compat": "flake-compat", "nix-darwin": [ "darwin" ], @@ -17,11 +15,11 @@ "pre-commit-hooks-nix": "pre-commit-hooks-nix" }, "locked": { - "lastModified": 1615131736, - "narHash": "sha256-z4Er9Cj3WpBDO/saLxqb7IypEvVP0/1AnO6rY5NB03Y=", + "lastModified": 1619088868, + "narHash": "sha256-l9db+HpNIkY41MonGE8z4pbkjBa5BdzJTG5AxV7V7Lw=", "owner": "hercules-ci", "repo": "hercules-ci-agent", - "rev": "a1513a51e8efb96e990a562e6e724e17f2789978", + "rev": "08f953a263518a3af0ca28cd887020ff3465bdf5", "type": "github" }, "original": { @@ -52,7 +50,7 @@ }, "deploy": { "inputs": { - "flake-compat": "flake-compat", + "flake-compat": "flake-compat_2", "naersk": "naersk", "nixpkgs": "nixpkgs", "utils": "utils" @@ -124,16 +122,15 @@ "flake-compat_2": { "flake": false, "locked": { - "lastModified": 1611461076, - "narHash": "sha256-ad++dTtMNeitUIKi1c66aTrVJOSf+mdZTrGrXzjDr6Q=", - "owner": "BBBSnowball", + "lastModified": 1606424373, + "narHash": "sha256-oq8d4//CJOrVj+EcOaSXvMebvuTkmBJuT5tzlfewUnQ=", + "owner": "edolstra", "repo": "flake-compat", - "rev": "a565cb46bee9fa856a6c15bc9c3bb947fbb784ec", + "rev": "99f1c2157fba4bfe6211a321fd0ee43199025dbf", "type": "github" }, "original": { - "owner": "BBBSnowball", - "ref": "pr-1", + "owner": "edolstra", "repo": "flake-compat", "type": "github" } @@ -307,11 +304,11 @@ "pre-commit-hooks-nix": { "flake": false, "locked": { - "lastModified": 1603721622, - "narHash": "sha256-tUgyf5eYK5+0A/dvLzbbm4W7icxbpORuFMXiFe5yz+I=", + "lastModified": 1617783930, + "narHash": "sha256-SigoU2LWM1fMggqfM9H8XEIvjOjBVQ/wj/zrn02J28c=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "efdbd6d28f7f44db3d9f8cf0e0b4cb9db0d259e1", + "rev": "2d169bb1b23f3b71a894a66ea81f45c788943248", "type": "github" }, "original": { @@ -325,7 +322,6 @@ "ci-agent": "ci-agent", "darwin": "darwin", "devos": "devos", - "flake-compat": "flake-compat_2", "home": "home", "latest": "latest", "naersk": "naersk_2", diff --git a/flake.nix b/flake.nix index 1b469f48..386bd327 100644 --- a/flake.nix +++ b/flake.nix @@ -17,7 +17,7 @@ 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 = "latest"; }; + inputs = { nix-darwin.follows = "darwin"; nixos-20_09.follows = "nixos"; nixos-unstable.follows = "latest"; }; }; darwin.url = "github:LnL7/nix-darwin"; darwin.inputs.nixpkgs.follows = "latest"; From 23ee58d2d0a26124ec16f54653e58f485c167e01 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Thu, 29 Apr 2021 11:53:45 -0700 Subject: [PATCH 64/91] use __dontExport property for lib and overrides --- doc/concepts/overrides.md | 5 +++++ flake.lock | 8 ++++---- lib/flake.lock | 6 +++--- lib/mkFlake/default.nix | 8 +++++++- overlays/overrides.nix | 2 ++ 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/doc/concepts/overrides.md b/doc/concepts/overrides.md index 0eb1002e..303108c0 100644 --- a/doc/concepts/overrides.md +++ b/doc/concepts/overrides.md @@ -12,10 +12,15 @@ You can add overlays to any channel to override packages from other channels. Pulling the manix package from the `latest` channel: ```nix channels: final: prev: { + __dontExport = true; inherit (pkgs.latest) manix; } ``` +It is recommended to set the `__dontExport` property for override specific +overlays. `overlays/overrides.nix` is the best place to consolidate all package +overrides and the property is already set for you. + ## Modules You can also pull modules from other channels. All modules have access to the diff --git a/flake.lock b/flake.lock index f7770ee8..27fecfbf 100644 --- a/flake.lock +++ b/flake.lock @@ -79,7 +79,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-hpvEXcpq85cDKi0F5UUsuMVISKlk8hgVJiz5FF29RwA=", + "narHash": "sha256-TQvd6TvSuT0sJCLlGsV65YjB+nIfDdDKZ1F94pCfkTw=", "path": "./lib", "type": "path" }, @@ -351,11 +351,11 @@ "flake-utils": "flake-utils" }, "locked": { - "lastModified": 1619532520, - "narHash": "sha256-+xIFAW5J0AcxwAflAX1gg/C8kfaqeZbS4XAZusCrZPY=", + "lastModified": 1619714004, + "narHash": "sha256-xoP81rWAM2cVpEFrQv9sUEIvNxGXAg4UH9kBt83a5u4=", "owner": "gytis-ivaskevicius", "repo": "flake-utils-plus", - "rev": "8eb7f9206713a528174c20c5133521dc37e2bfb1", + "rev": "0642ac572a87a0beb78a7c6ddce1267aa5817d05", "type": "github" }, "original": { diff --git a/lib/flake.lock b/lib/flake.lock index ebf5e6d3..8156254b 100644 --- a/lib/flake.lock +++ b/lib/flake.lock @@ -146,11 +146,11 @@ "flake-utils": "flake-utils" }, "locked": { - "lastModified": 1619532520, - "narHash": "sha256-+xIFAW5J0AcxwAflAX1gg/C8kfaqeZbS4XAZusCrZPY=", + "lastModified": 1619714004, + "narHash": "sha256-xoP81rWAM2cVpEFrQv9sUEIvNxGXAg4UH9kBt83a5u4=", "owner": "gytis-ivaskevicius", "repo": "flake-utils-plus", - "rev": "8eb7f9206713a528174c20c5133521dc37e2bfb1", + "rev": "0642ac572a87a0beb78a7c6ddce1267aa5817d05", "type": "github" }, "original": { diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index bf571ec4..e5862d39 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -40,7 +40,7 @@ let hosts = lib.mapAttrs (_: stripHost) cfg.nixos.hosts; hostDefaults = stripHost cfg.nixos.hostDefaults; in -lib.systemFlake (lib.recursiveUpdate +lib.systemFlake (lib.mergeAny otherArguments { inherit self inputs hosts; @@ -55,6 +55,12 @@ lib.systemFlake (lib.recursiveUpdate ) cfg.channels; + sharedOverlays = [ + (final: prev: { + __dontExport = true; + devlib = lib; + }) + ]; hostDefaults = lib.mergeAny hostDefaults { specialArgs.suites = cfg.nixos.suites; modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules; diff --git a/overlays/overrides.nix b/overlays/overrides.nix index bb3cf68b..59516b3d 100644 --- a/overlays/overrides.nix +++ b/overlays/overrides.nix @@ -1,5 +1,7 @@ channels: final: prev: { + __dontExport = true; # overrides clutter up actual creations + inherit (channels.latest) cachix dhall From e98e595704f2635f2b0fc9ffc999ae603ddaad24 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Wed, 28 Apr 2021 11:30:04 -0700 Subject: [PATCH 65/91] pass builderArgs to config and extract builds have mkHomeConfiguration create its own custom build within the function create a externalModule for customBuilds so its easy to add more --- flake.lock | 2 +- flake.nix | 1 + lib/devos/mkHomeConfigurations.nix | 7 ++++--- lib/mkFlake/default.nix | 5 ++++- lib/modules.nix | 14 +------------- lib/pkgs-lib/tests/default.nix | 6 ++---- modules/customBuilds.nix | 29 +++++++++++++++++++++++++++++ 7 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 modules/customBuilds.nix diff --git a/flake.lock b/flake.lock index 27fecfbf..484e3011 100644 --- a/flake.lock +++ b/flake.lock @@ -79,7 +79,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-TQvd6TvSuT0sJCLlGsV65YjB+nIfDdDKZ1F94pCfkTw=", + "narHash": "sha256-oTiKYoR210VwjomzfSn/pCJ3immdUDRUPbYTDGaPFn8=", "path": "./lib", "type": "path" }, diff --git a/flake.nix b/flake.nix index 386bd327..41a83a9f 100644 --- a/flake.nix +++ b/flake.nix @@ -57,6 +57,7 @@ externalModules = [ ci-agent.nixosModules.agent-profile home.nixosModules.home-manager + ./modules/customBuilds.nix ]; }; hosts = nixos.lib.mkMerge [ diff --git a/lib/devos/mkHomeConfigurations.nix b/lib/devos/mkHomeConfigurations.nix index 3a07ba82..95affc26 100644 --- a/lib/devos/mkHomeConfigurations.nix +++ b/lib/devos/mkHomeConfigurations.nix @@ -4,9 +4,10 @@ nixosConfigurations: with lib; let - mkHomes = host: config: - mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) - config.config.system.build.homes; + mkHomes = hostName: host: + mapAttrs' (user: v: nameValuePair "${user}@${hostName}" v.home) + # So this function is useful for non-devos hosts + (host.config.system.build.homes or host.config.home-manager.users); hmConfigs = mapAttrs mkHomes nixosConfigurations; diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index e5862d39..ed99db0f 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -64,7 +64,10 @@ lib.systemFlake (lib.mergeAny hostDefaults = lib.mergeAny hostDefaults { specialArgs.suites = cfg.nixos.suites; modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules; - builder = os.devosSystem { inherit self inputs; }; + builder = args: args.specialArgs.channel.input.lib.nixosSystem (lib.mergeAny args { + # So modules and functions can create their own version of the build + modules = [ { lib.builderArgs = args; } ]; + }); }; nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules; diff --git a/lib/modules.nix b/lib/modules.nix index 6e2a3525..60e29719 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -43,6 +43,7 @@ _module.args = { inherit self; + devlib = lib; hosts = builtins.mapAttrs (_: host: host.config) (removeAttrs self.nixosConfigurations [ config.networking.hostName ]); }; @@ -111,18 +112,5 @@ }; }; - hmConfig = - { config, ... }: { - home-manager.useUserPackages = lib.mkForce false; - home-manager.sharedModules = [ - { - home.sessionVariables = { - inherit (config.environment.sessionVariables) NIX_PATH; - }; - xdg.configFile."nix/registry.json".text = - config.environment.etc."nix/registry.json".text; - } - ]; - }; } diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index 854332fe..e08702ac 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -23,11 +23,9 @@ let nixosTesting = (import "${toString pkgs.path}/nixos/lib/testing-python.nix" { inherit (pkgs) system; - inherit (host.config.lib) specialArgs; + inherit (host.config.lib.builderArgs) specialArgs; inherit pkgs; - extraConfigurations = [ - host.config.lib.testModule - ]; + extraConfigurations = host._module.args.modules; }); in test: diff --git a/modules/customBuilds.nix b/modules/customBuilds.nix new file mode 100644 index 00000000..b9648dca --- /dev/null +++ b/modules/customBuilds.nix @@ -0,0 +1,29 @@ +{ lib, self, devlib, config, modules, channel, ... }: +let + mkBuild = buildModule: + channel.input.lib.nixosSystem (devlib.mergeAny config.lib.builderArgs { + modules = [ buildModule ]; + }); +in +{ + system.build = { + iso = (mkBuild (devlib.modules.isoConfig { + inherit self; + inherit (self) inputs; + fullHostConfig = config; + })).config.system.build.isoImage; + + homes = (mkBuild ({ config, ... }: { + home-manager.useUserPackages = lib.mkForce false; + home-manager.sharedModules = [ + { + home.sessionVariables = { + inherit (config.environment.sessionVariables) NIX_PATH; + }; + xdg.configFile."nix/registry.json".text = + config.environment.etc."nix/registry.json".text; + } + ]; + })).config.home-manager.users; + }; +} From e97e916521b2bbd3605350fe1a1e50dbbc8902b5 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 1 May 2021 17:46:30 -0700 Subject: [PATCH 66/91] lib: init generators section --- lib/generators.nix | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 lib/generators.nix diff --git a/lib/generators.nix b/lib/generators.nix new file mode 100644 index 00000000..86f9d4db --- /dev/null +++ b/lib/generators.nix @@ -0,0 +1,46 @@ +{ lib }: +{ + mkHomeConfigurations = nixosConfigurations: + with lib; + let + mkHomes = host: config: + mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) + config.config.system.build.homes; + + hmConfigs = mapAttrs mkHomes nixosConfigurations; + + in + foldl recursiveUpdate { } (attrValues hmConfigs); + + mkDeployNodes = + /** + Synopsis: mkNodes _nixosConfigurations_ + + Generate the `nodes` attribute expected by deploy-rs + where _nixosConfigurations_ are `nodes`. + **/ + + deploy: lib.mapAttrs (_: config: { + hostname = config.config.networking.hostName; + + profiles.system = { + user = "root"; + path = deploy.lib.x86_64-linux.activate.nixos config; + }; + }); + + mkSuites = { suites, profiles }: + let + profileSet = lib.genAttrs' profiles (path: { + name = baseNameOf path; + value = lib.mkProfileAttrs (toString path); + }); + + definedSuites = suites profileSet; + + allProfiles = lib.collectProfiles profileSet; + in + lib.mapAttrs (_: v: lib.profileMap v) definedSuites // { + inherit allProfiles; + }; +} From c93e9fda0fada3e4a48f416d1f38c5a57852e492 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 1 May 2021 17:46:54 -0700 Subject: [PATCH 67/91] lib: init importers section --- lib/importers.nix | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 lib/importers.nix diff --git a/lib/importers.nix b/lib/importers.nix new file mode 100644 index 00000000..ea07373d --- /dev/null +++ b/lib/importers.nix @@ -0,0 +1,64 @@ +{ lib }: +let + recImport = { dir, _import ? base: import "${dir}/${base}.nix" }: + lib.mapFilterAttrs + (_: v: v != null) + (n: v: + if n != "default.nix" && lib.hasSuffix ".nix" n && v == "regular" + then + let name = lib.removeSuffix ".nix" n; in lib.nameValuePair (name) (_import name) + else + lib.nameValuePair ("") (null)) + (lib.safeReadDir dir); + + mkProfileAttrs = + /** + Synopsis: mkProfileAttrs _path_ + + Recursively collect the subdirs of _path_ containing a default.nix into attrs. + This sets a contract, eliminating ambiguity for _default.nix_ living under the + profile directory. + + Example: + let profiles = mkProfileAttrs ./profiles; in + assert profiles ? core.default; 0 + **/ + dir: + let + imports = + let + files = lib.safeReadDir dir; + + p = n: v: + v == "directory" + && n != "profiles"; + in + lib.filterAttrs p files; + + f = n: _: + lib.optionalAttrs + (lib.pathExists "${dir}/${n}/default.nix") + { default = "${dir}/${n}"; } + // mkProfileAttrs "${dir}/${n}"; + in + lib.mapAttrs f imports; + +in +{ + inherit recImport mkProfileAttrs; + + pathsIn = dir: + let + fullPath = name: "${toString dir}/${name}"; + in + map fullPath (lib.attrNames (lib.safeReadDir dir)); + + importHosts = dir: + recImport { + inherit dir; + _import = base: { + modules = import "${toString dir}/${base}.nix"; + }; + }; +} + From e837aaa8755d45028ba48b12bbac3231e86bf39b Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 1 May 2021 17:47:43 -0700 Subject: [PATCH 68/91] lib: remove devos section --- lib/devos/default.nix | 30 ------------------- lib/devos/devosSystem.nix | 40 ------------------------- lib/devos/mkHosts.nix | 57 ------------------------------------ lib/devos/mkNodes.nix | 16 ---------- lib/devos/mkPackages.nix | 17 ----------- lib/devos/mkPkgs.nix | 25 ---------------- lib/devos/mkProfileAttrs.nix | 35 ---------------------- lib/devos/mkSuites.nix | 20 ------------- lib/devos/recImport.nix | 12 -------- 9 files changed, 252 deletions(-) delete mode 100644 lib/devos/default.nix delete mode 100644 lib/devos/devosSystem.nix delete mode 100644 lib/devos/mkHosts.nix delete mode 100644 lib/devos/mkNodes.nix delete mode 100644 lib/devos/mkPackages.nix delete mode 100644 lib/devos/mkPkgs.nix delete mode 100644 lib/devos/mkProfileAttrs.nix delete mode 100644 lib/devos/mkSuites.nix delete mode 100644 lib/devos/recImport.nix diff --git a/lib/devos/default.nix b/lib/devos/default.nix deleted file mode 100644 index 9a3118f5..00000000 --- a/lib/devos/default.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ lib, utils }: -{ - # pkgImport :: Nixpkgs -> Overlays -> System -> Pkgs - pkgImport = nixpkgs: overlays: system: - import nixpkgs { - inherit system overlays; - config = { allowUnfree = true; }; - }; - - profileMap = list: map (profile: profile.default) (lib.flatten list); - - mkNodes = import ./mkNodes.nix { inherit lib; }; - - mkHosts = import ./mkHosts.nix { inherit lib; }; - - mkSuites = import ./mkSuites.nix { inherit lib; }; - - mkProfileAttrs = import ./mkProfileAttrs.nix { inherit lib; }; - - mkPkgs = import ./mkPkgs.nix { inherit lib utils; }; - - recImport = import ./recImport.nix { inherit lib; }; - - devosSystem = import ./devosSystem.nix { inherit lib; }; - - mkHomeConfigurations = import ./mkHomeConfigurations.nix { inherit lib; }; - - mkPackages = import ./mkPackages.nix { inherit lib; }; -} - diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix deleted file mode 100644 index c48f68a5..00000000 --- a/lib/devos/devosSystem.nix +++ /dev/null @@ -1,40 +0,0 @@ -{ lib }: - -# dependencies to return a builder -{ self, inputs }: - -{ modules, specialArgs, ... } @ args: -let inherit (specialArgs.channel.input.lib) nixosSystem; in -nixosSystem - (args // { - modules = - let - fullHostConfig = (nixosSystem (args // { inherit modules; })).config; - - isoConfig = (nixosSystem - (args // { - modules = modules ++ [ - (lib.modules.iso { inherit self inputs fullHostConfig; }) - ]; - })).config; - - hmConfig = (nixosSystem - (args // { - modules = modules ++ [ - (lib.modules.hmConfig) - ]; - })).config; - in - modules ++ [{ - system.build = { - iso = isoConfig.system.build.isoImage; - homes = hmConfig.home-manager.users; - }; - lib = { - inherit specialArgs; - testModule = { - imports = modules; - }; - }; - }]; - }) diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix deleted file mode 100644 index 2fe4ed36..00000000 --- a/lib/devos/mkHosts.nix +++ /dev/null @@ -1,57 +0,0 @@ -{ lib }: - -{ self, nixos, inputs, dir, extern, suites, overrides, multiPkgs }: -let - defaultSystem = "x86_64-linux"; - - modules = with lib.modules; { - modOverrides = modOverrides { inherit overrides; }; - hmDefaults = hmDefaults { - inherit extern; - inherit (self) homeModules; - userSuites = suites.user; - }; - globalDefaults = globalDefaults { - inherit self nixos inputs multiPkgs; - }; - cachix = cachix { inherit self; }; - flakeModules = flakeModules { inherit self extern; }; - }; - - specialArgs = extern.specialArgs // { suites = suites.system; }; - - mkHostConfig = hostName: - let - local = { - require = [ - "${dir}/${hostName}.nix" - ]; - - networking = { inherit hostName; }; - - _module.args = { - self = self; - hosts = builtins.mapAttrs (_: host: host.config) - (removeAttrs hosts [ hostName ]); - }; - - lib = { inherit specialArgs; }; - lib.testModule = { - imports = builtins.attrValues modules; - }; - - }; - in - lib.os.devosSystem { - inherit self nixos inputs specialArgs; - system = defaultSystem; - modules = modules // { inherit local; }; - }; - - hosts = lib.os.recImport - { - inherit dir; - _import = mkHostConfig; - }; -in -hosts diff --git a/lib/devos/mkNodes.nix b/lib/devos/mkNodes.nix deleted file mode 100644 index 83906ce8..00000000 --- a/lib/devos/mkNodes.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ lib }: - -/** - Synopsis: mkNodes _nixosConfigurations_ - - Generate the `nodes` attribute expected by deploy-rs - where _nixosConfigurations_ are `nodes`. - **/ -deploy: lib.mapAttrs (_: config: { - hostname = config.config.networking.hostName; - - profiles.system = { - user = "root"; - path = deploy.lib.x86_64-linux.activate.nixos config; - }; -}) diff --git a/lib/devos/mkPackages.nix b/lib/devos/mkPackages.nix deleted file mode 100644 index d8992685..00000000 --- a/lib/devos/mkPackages.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ lib }: - -{ overlay, overlays, pkgs }: -let - packagesNames = lib.attrNames (overlay null null) - ++ lib.attrNames (lib.concatAttrs - (lib.attrValues - (lib.mapAttrs (_: v: v null null) overlays) - ) - ); -in -lib.fold - (key: sum: lib.recursiveUpdate sum { - ${key} = pkgs.${key}; - }) -{ } - packagesNames diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix deleted file mode 100644 index a7cf2366..00000000 --- a/lib/devos/mkPkgs.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ lib, utils }: - -{ self, nixos, inputs, extern, overrides }: -(utils.lib.eachDefaultSystem - (system: - let - overridePkgs = lib.os.pkgImport inputs.override [ ] system; - overridesOverlay = overrides.packages; - - overlays = [ - (final: prev: { - lib = prev.lib.extend (lfinal: lprev: { - inherit lib; - inherit (lib) nixosSystem; - }); - }) - (overridesOverlay overridePkgs) - self.overlay - ] - ++ extern.overlays - ++ (lib.attrValues self.overlays); - in - { pkgs = lib.os.pkgImport nixos overlays system; } - ) -).pkgs diff --git a/lib/devos/mkProfileAttrs.nix b/lib/devos/mkProfileAttrs.nix deleted file mode 100644 index cdfc32e7..00000000 --- a/lib/devos/mkProfileAttrs.nix +++ /dev/null @@ -1,35 +0,0 @@ -{ lib }: - -let mkProfileAttrs = - /** - Synopsis: mkProfileAttrs _path_ - - Recursively collect the subdirs of _path_ containing a default.nix into attrs. - This sets a contract, eliminating ambiguity for _default.nix_ living under the - profile directory. - - Example: - let profiles = mkProfileAttrs ./profiles; in - assert profiles ? core.default; 0 - **/ - dir: - let - imports = - let - files = lib.safeReadDir dir; - - p = n: v: - v == "directory" - && n != "profiles"; - in - lib.filterAttrs p files; - - f = n: _: - lib.optionalAttrs - (lib.pathExists "${dir}/${n}/default.nix") - { default = "${dir}/${n}"; } - // mkProfileAttrs "${dir}/${n}"; - in - lib.mapAttrs f imports; -in mkProfileAttrs - diff --git a/lib/devos/mkSuites.nix b/lib/devos/mkSuites.nix deleted file mode 100644 index 45d8a10f..00000000 --- a/lib/devos/mkSuites.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ lib }: - -{ suites, profiles } @ args: -let - inherit (lib) os; - - profileSet = lib.genAttrs' profiles (path: { - name = baseNameOf path; - value = os.mkProfileAttrs (toString path); - }); - - definedSuites = suites profileSet; - - allProfiles = lib.collectProfiles profileSet; -in -lib.mapAttrs (_: v: os.profileMap v) definedSuites // { - inherit allProfiles; -} - - diff --git a/lib/devos/recImport.nix b/lib/devos/recImport.nix deleted file mode 100644 index c96c9352..00000000 --- a/lib/devos/recImport.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ lib }: - -{ dir, _import ? base: import "${dir}/${base}.nix" }: -lib.mapFilterAttrs - (_: v: v != null) - (n: v: - if n != "default.nix" && lib.hasSuffix ".nix" n && v == "regular" - then - let name = lib.removeSuffix ".nix" n; in lib.nameValuePair (name) (_import name) - else - lib.nameValuePair ("") (null)) - (lib.safeReadDir dir) From 496348b8afa4fea898d5c21147d56b9314c11a25 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 2 May 2021 01:12:29 -0700 Subject: [PATCH 69/91] lib: update namespaces and cleanup exports --- lib/flake.nix | 54 +++++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/lib/flake.nix b/lib/flake.nix index 2513311d..fba02a87 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -10,31 +10,23 @@ outputs = inputs@{ self, nixpkgs, deploy, devshell, utils, ... }: let - lib = nixpkgs.lib.makeExtensible (self: - let - attrs = import ./attrs.nix { lib = nixpkgs.lib // self; }; - lists = import ./lists.nix { lib = nixpkgs.lib // self; }; - strings = import ./strings.nix { lib = nixpkgs.lib // self; }; - modules = import ./modules.nix { lib = nixpkgs.lib // self; }; - in - - utils.lib - - // - - { - os = import ./devos { - lib = nixpkgs.lib // self; - inherit utils; - }; + let combinedLib = nixpkgs.lib // self; in + with self; + utils.lib // { + attrs = import ./attrs.nix { lib = combinedLib; }; + lists = import ./lists.nix { lib = combinedLib; }; + strings = import ./strings.nix { lib = combinedLib; }; + modules = import ./modules.nix { lib = combinedLib; }; + importers = import ./importers.nix { lib = combinedLib; }; + generators = import ./generators.nix { lib = combinedLib; }; mkFlake = { __functor = import ./mkFlake { - lib = nixpkgs.lib // self; + lib = combinedLib; inherit deploy; }; - evalArgs = import ./mkFlake/evalArgs.nix { lib = nixpkgs.lib // self; }; + evalArgs = import ./mkFlake/evalArgs.nix { lib = combinedLib; }; }; pkgs-lib = import ./pkgs-lib { @@ -42,28 +34,26 @@ inherit deploy devshell; }; - inherit (attrs) - mapFilterAttrs - genAttrs' - safeReadDir - pathsToImportedAttrs - concatAttrs - filterPackages - importHosts; - inherit (lists) pathsIn collectProfiles unifyOverlays; + inherit (attrs) mapFilterAttrs genAttrs' safeReadDir concatAttrs; + inherit (lists) profileMap collectProfiles unifyOverlays; inherit (strings) rgxToString; - inherit modules; + inherit (importers) mkProfileAttrs pathsIn importHosts; + inherit (generators) mkSuites mkDeployNodes mkHomeConfigurations; } ); in { - lib = utils.lib // { + lib = with lib; utils.lib // { + inherit attrs lists modules importers generators; inherit (lib) - mkFlake pathsIn importHosts; + mkFlake + pathsIn + importHosts + mkDeployNodes + mkHomeConfigurations; }; - } // From 197d7929464757dbfcbbacbc1aef0586e9e20add Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 1 May 2021 17:49:04 -0700 Subject: [PATCH 70/91] update to new lib format --- flake.lock | 2 +- lib/attrs.nix | 35 ----------------------------------- lib/lists.nix | 20 +++++++++----------- lib/mkFlake/default.nix | 7 +++---- lib/mkFlake/evalArgs.nix | 4 +--- lib/tests/lib.nix | 21 +-------------------- 6 files changed, 15 insertions(+), 74 deletions(-) diff --git a/flake.lock b/flake.lock index 484e3011..795e0de2 100644 --- a/flake.lock +++ b/flake.lock @@ -79,7 +79,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-oTiKYoR210VwjomzfSn/pCJ3immdUDRUPbYTDGaPFn8=", + "narHash": "sha256-9JsKDtgLSmAkcaKRD4Ycttip1jpO9dVVaRwclWH0V8E=", "path": "./lib", "type": "path" }, diff --git a/lib/attrs.nix b/lib/attrs.nix index 93f79583..1061c0e2 100644 --- a/lib/attrs.nix +++ b/lib/attrs.nix @@ -12,43 +12,8 @@ rec { # Generate an attribute set by mapping a function over a list of values. genAttrs' = values: f: lib.listToAttrs (map f values); - # Convert a list of file paths to attribute set where - # the key is the folder or filename stripped of nix - # extension and imported content of the file as value. - # - pathsToImportedAttrs = paths: - let - paths' = lib.filter - (path: lib.hasSuffix ".nix" path - || lib.pathExists "${path}/default.nix") - paths; - in - genAttrs' paths' (path: { - name = lib.removeSuffix ".nix" - # Safe as long this is just used as a name - (builtins.unsafeDiscardStringContext (baseNameOf path)); - value = import path; - }); - - importHosts = dir: - lib.os.recImport { - inherit dir; - _import = base: { - modules = import "${toString dir}/${base}.nix"; - }; - }; - concatAttrs = lib.fold (attr: sum: lib.recursiveUpdate sum attr) { }; - # Filter out packages that support given system and follow flake check requirements - filterPackages = system: packages: - let - # Everything that nix flake check requires for the packages output - filter = (n: v: with v; let platforms = meta.hydraPlatforms or meta.platforms or [ ]; in - lib.isDerivation v && !meta.broken && builtins.elem system platforms); - in - lib.filterAttrs filter packages; - safeReadDir = path: lib.optionalAttrs (builtins.pathExists (toString path)) (builtins.readDir (toString path)); } diff --git a/lib/lists.nix b/lib/lists.nix index 5e9c57b2..4bef865e 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -3,19 +3,17 @@ collectProfiles = set: let collectNestedProfiles = set: - lib.mapAttrsToList (n: v: - if builtins.isAttrs v then - [ v.default or null ] ++ collectNestedProfiles v - else null - ) set; + lib.mapAttrsToList + (n: v: + if builtins.isAttrs v then + [ v.default or null ] ++ collectNestedProfiles v + else null + ) + set; in - builtins.filter (x: x != null) (lib.flatten (collectNestedProfiles set)); + builtins.filter (x: x != null) (lib.flatten (collectNestedProfiles set)); - pathsIn = dir: - let - fullPath = name: "${toString dir}/${name}"; - in - map fullPath (lib.attrNames (lib.safeReadDir dir)); + profileMap = list: map (profile: profile.default) (lib.flatten list); unifyOverlays = channels: map (o: if builtins.isFunction (o null null) then o channels else o); } diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index ed99db0f..5bd6419d 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,6 +1,5 @@ { lib, deploy }: let - inherit (lib) os; inherit (builtins) mapAttrs attrNames attrValues head isFunction; in @@ -66,16 +65,16 @@ lib.systemFlake (lib.mergeAny modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules; builder = args: args.specialArgs.channel.input.lib.nixosSystem (lib.mergeAny args { # So modules and functions can create their own version of the build - modules = [ { lib.builderArgs = args; } ]; + modules = [{ lib.builderArgs = args; }]; }); }; nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules; homeModules = lib.exporter.modulesFromList cfg.home.modules; - homeConfigurations = os.mkHomeConfigurations self.nixosConfigurations; + homeConfigurations = lib.mkHomeConfigurations self.nixosConfigurations; - deploy.nodes = os.mkNodes deploy self.nixosConfigurations; + deploy.nodes = lib.mkDeployNodes deploy self.nixosConfigurations; overlays = lib.exporter.overlaysFromChannelsExporter { # since we can't detect overlays owned by self diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index ee42e224..bf366274 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -4,8 +4,6 @@ let argOpts = with lib; { config, ... }: let - inherit (lib) os; - cfg = config; inherit (config) self; @@ -188,7 +186,7 @@ let suites = mkOption { type = pathTo (functionTo attrs); default = _: { }; - apply = suites: os.mkSuites { + apply = suites: lib.mkSuites { inherit suites; inherit (config) profiles; }; diff --git a/lib/tests/lib.nix b/lib/tests/lib.nix index e992df67..78536e75 100644 --- a/lib/tests/lib.nix +++ b/lib/tests/lib.nix @@ -37,25 +37,6 @@ lib.runTests { ]; }; - testPathsToImportedAttrs = { - expr = - pathsToImportedAttrs [ - (toString ./testPathsToImportedAttrs/dir) - ./testPathsToImportedAttrs/foo.nix - ./testPathsToImportedAttrs/bar.nix - ./testPathsToImportedAttrs/t.nix - ./testPathsToImportedAttrs/f.nix - ]; - - expected = { - dir = { a = 5; }; - foo = { bar = 1; }; - bar = { foo = 2; }; - t = true; - f = false; - }; - }; - testRgxToString = lib.testAllTrue [ (rgxToString ".+x" "vxk" == "vx") (rgxToString "^fo" "foo" == "fo") @@ -72,7 +53,7 @@ lib.runTests { }; testSuites = { - expr = os.mkSuites { + expr = mkSuites { suites = { profiles, ... }: with profiles; { bar = [ foo ]; }; From deb47dbfae5f7ca93a7f7c0a08cddf6e352060a1 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 2 May 2021 11:15:44 -0700 Subject: [PATCH 71/91] move otherArguments to right side of merge for overlay list ordering, otherArguments should have priority --- flake.lock | 2 +- lib/mkFlake/default.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.lock b/flake.lock index 795e0de2..6ee3c399 100644 --- a/flake.lock +++ b/flake.lock @@ -79,7 +79,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-9JsKDtgLSmAkcaKRD4Ycttip1jpO9dVVaRwclWH0V8E=", + "narHash": "sha256-AnasH9JbhPD+sR30YP+1IvNoO0S4hUcSraJwvXIaIpo=", "path": "./lib", "type": "path" }, diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 5bd6419d..3fecd615 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -40,7 +40,6 @@ let hostDefaults = stripHost cfg.nixos.hostDefaults; in lib.systemFlake (lib.mergeAny - otherArguments { inherit self inputs hosts; inherit (cfg) channelsConfig supportedSystems; @@ -99,4 +98,5 @@ lib.systemFlake (lib.mergeAny pkgs = getDefaultChannel channels; }; } + otherArguments # for overlays list order ) From 7bf605d08c0cb6a0534b39823ac30a5a7b0976c5 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 2 May 2021 21:05:21 -0700 Subject: [PATCH 72/91] lib/modules: pull devlib module arg from pkgs So any overlays affecting devlib also affect the module argument --- flake.lock | 2 +- lib/modules.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.lock b/flake.lock index 6ee3c399..e516cd4b 100644 --- a/flake.lock +++ b/flake.lock @@ -79,7 +79,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-AnasH9JbhPD+sR30YP+1IvNoO0S4hUcSraJwvXIaIpo=", + "narHash": "sha256-jG9Y7IiZkB+xKuqsVr2wr0zfV2TNziIIRmv0MHqzis0=", "path": "./lib", "type": "path" }, diff --git a/lib/modules.nix b/lib/modules.nix index 60e29719..6deb7f39 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -43,7 +43,7 @@ _module.args = { inherit self; - devlib = lib; + devlib = pkgs.devlib; hosts = builtins.mapAttrs (_: host: host.config) (removeAttrs self.nixosConfigurations [ config.networking.hostName ]); }; From b8f7cdbe638699b95278e8bec56add4e63777e74 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 2 May 2021 10:35:29 -0700 Subject: [PATCH 73/91] improve home-manager and deploy-rs integration move both to be setup in template only set home-manager options if they exist --- flake.lock | 2 +- flake.nix | 4 ++++ lib/flake.nix | 13 +++++++------ lib/generators.nix | 22 +++++++++++++--------- lib/mkFlake/default.nix | 5 +---- lib/modules.nix | 17 ++++++++++------- 6 files changed, 36 insertions(+), 27 deletions(-) diff --git a/flake.lock b/flake.lock index e516cd4b..3a701807 100644 --- a/flake.lock +++ b/flake.lock @@ -79,7 +79,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-jG9Y7IiZkB+xKuqsVr2wr0zfV2TNziIIRmv0MHqzis0=", + "narHash": "sha256-/htTDxf3/n8lcL7Gnoi3+uamuY/KnlSMWDQ76dzQpac=", "path": "./lib", "type": "path" }, diff --git a/flake.nix b/flake.nix index 41a83a9f..a7811996 100644 --- a/flake.nix +++ b/flake.nix @@ -79,6 +79,10 @@ }; }; + homeConfigurations = devos.lib.mkHomeConfigurations self.nixosConfigurations; + + deploy.nodes = devos.lib.mkDeployNodes self.nixosConfigurations { }; + #defaultTemplate = self.templates.flk; templates.flk.path = ./.; templates.flk.description = "flk template"; diff --git a/lib/flake.nix b/lib/flake.nix index fba02a87..5fd79366 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -19,18 +19,19 @@ strings = import ./strings.nix { lib = combinedLib; }; modules = import ./modules.nix { lib = combinedLib; }; importers = import ./importers.nix { lib = combinedLib; }; - generators = import ./generators.nix { lib = combinedLib; }; + + generators = import ./generators.nix { + lib = combinedLib; + inherit deploy; + }; mkFlake = { - __functor = import ./mkFlake { - lib = combinedLib; - inherit deploy; - }; + __functor = import ./mkFlake { lib = combinedLib; }; evalArgs = import ./mkFlake/evalArgs.nix { lib = combinedLib; }; }; pkgs-lib = import ./pkgs-lib { - lib = nixpkgs.lib // self; + lib = combinedLib; inherit deploy devshell; }; diff --git a/lib/generators.nix b/lib/generators.nix index 86f9d4db..f403fbc2 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -1,4 +1,4 @@ -{ lib }: +{ lib, deploy }: { mkHomeConfigurations = nixosConfigurations: with lib; @@ -12,7 +12,7 @@ in foldl recursiveUpdate { } (attrValues hmConfigs); - mkDeployNodes = + mkDeployNodes = hosts: extraConfig: /** Synopsis: mkNodes _nixosConfigurations_ @@ -20,14 +20,18 @@ where _nixosConfigurations_ are `nodes`. **/ - deploy: lib.mapAttrs (_: config: { - hostname = config.config.networking.hostName; + lib.mapAttrs + (_: config: lib.recursiveUpdate + { + hostname = config.config.networking.hostName; - profiles.system = { - user = "root"; - path = deploy.lib.x86_64-linux.activate.nixos config; - }; - }); + profiles.system = { + user = "root"; + path = deploy.lib.x86_64-linux.activate.nixos config; + }; + } + extraConfig) + hosts; mkSuites = { suites, profiles }: let diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 3fecd615..e2d0b73c 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,4 +1,4 @@ -{ lib, deploy }: +{ lib }: let inherit (builtins) mapAttrs attrNames attrValues head isFunction; in @@ -71,9 +71,6 @@ lib.systemFlake (lib.mergeAny nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules; homeModules = lib.exporter.modulesFromList cfg.home.modules; - homeConfigurations = lib.mkHomeConfigurations self.nixosConfigurations; - - deploy.nodes = lib.mkDeployNodes deploy self.nixosConfigurations; overlays = lib.exporter.overlaysFromChannelsExporter { # since we can't detect overlays owned by self diff --git a/lib/modules.nix b/lib/modules.nix index 6deb7f39..d5641962 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -1,14 +1,17 @@ { lib }: { - hmDefaults = { suites, modules }: { - home-manager = { - useGlobalPkgs = true; - useUserPackages = true; + hmDefaults = { suites, modules }: + { options, ... }: { + config = lib.optionalAttrs (options ? home-manager) { + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; - extraSpecialArgs = { inherit suites; }; - sharedModules = modules; + extraSpecialArgs = { inherit suites; }; + sharedModules = modules; + }; + }; }; - }; globalDefaults = { self, inputs }: let From 8dabd0f56919eea94d8c034805bb562e97da0021 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 4 May 2021 21:48:49 -0700 Subject: [PATCH 74/91] switch to devlib repo and remove in-tree lib --- flake.lock | 18 +- flake.nix | 27 +- lib/attrs.nix | 19 -- lib/default.nix | 2 + lib/devos/mkHomeConfigurations.nix | 15 - lib/flake.lock | 166 ----------- lib/flake.nix | 84 ------ lib/generators.nix | 50 ---- lib/importers.nix | 64 ----- lib/lists.nix | 19 -- lib/mkFlake/default.nix | 99 ------- lib/mkFlake/evalArgs.nix | 262 ------------------ lib/modules.nix | 119 -------- lib/pkgs-lib/default.nix | 6 - lib/pkgs-lib/shell/default.nix | 55 ---- lib/pkgs-lib/shell/devshell.toml | 29 -- lib/pkgs-lib/shell/flk.nix | 23 -- lib/pkgs-lib/shell/flk.sh | 98 ------- lib/pkgs-lib/shell/pre-commit.sh | 29 -- lib/pkgs-lib/tests/default.nix | 56 ---- lib/pkgs-lib/tests/lib.nix | 93 ------- lib/strings.nix | 20 -- lib/tests/default.nix | 27 -- lib/tests/lib.nix | 70 ----- lib/tests/profiles/foo/default.nix | 3 - lib/tests/profiles/t/default.nix | 1 - lib/tests/testPathsIn/bar | 0 lib/tests/testPathsIn/baz | 0 lib/tests/testPathsIn/foo | 0 lib/tests/testPathsToImportedAttrs/bar.nix | 1 - .../testPathsToImportedAttrs/dir/default.nix | 1 - lib/tests/testPathsToImportedAttrs/f.nix | 1 - lib/tests/testPathsToImportedAttrs/foo.nix | 1 - lib/tests/testPathsToImportedAttrs/t.nix | 1 - 34 files changed, 27 insertions(+), 1432 deletions(-) delete mode 100644 lib/attrs.nix create mode 100644 lib/default.nix delete mode 100644 lib/devos/mkHomeConfigurations.nix delete mode 100644 lib/flake.lock delete mode 100644 lib/flake.nix delete mode 100644 lib/generators.nix delete mode 100644 lib/importers.nix delete mode 100644 lib/lists.nix delete mode 100644 lib/mkFlake/default.nix delete mode 100644 lib/mkFlake/evalArgs.nix delete mode 100644 lib/modules.nix delete mode 100644 lib/pkgs-lib/default.nix delete mode 100644 lib/pkgs-lib/shell/default.nix delete mode 100644 lib/pkgs-lib/shell/devshell.toml delete mode 100644 lib/pkgs-lib/shell/flk.nix delete mode 100755 lib/pkgs-lib/shell/flk.sh delete mode 100755 lib/pkgs-lib/shell/pre-commit.sh delete mode 100644 lib/pkgs-lib/tests/default.nix delete mode 100644 lib/pkgs-lib/tests/lib.nix delete mode 100644 lib/strings.nix delete mode 100644 lib/tests/default.nix delete mode 100644 lib/tests/lib.nix delete mode 100644 lib/tests/profiles/foo/default.nix delete mode 100644 lib/tests/profiles/t/default.nix delete mode 100644 lib/tests/testPathsIn/bar delete mode 100644 lib/tests/testPathsIn/baz delete mode 100644 lib/tests/testPathsIn/foo delete mode 100644 lib/tests/testPathsToImportedAttrs/bar.nix delete mode 100644 lib/tests/testPathsToImportedAttrs/dir/default.nix delete mode 100644 lib/tests/testPathsToImportedAttrs/f.nix delete mode 100644 lib/tests/testPathsToImportedAttrs/foo.nix delete mode 100644 lib/tests/testPathsToImportedAttrs/t.nix diff --git a/flake.lock b/flake.lock index 3a701807..db2f9144 100644 --- a/flake.lock +++ b/flake.lock @@ -69,7 +69,7 @@ "type": "github" } }, - "devos": { + "devlib": { "inputs": { "deploy": "deploy", "devshell": "devshell", @@ -79,13 +79,17 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-/htTDxf3/n8lcL7Gnoi3+uamuY/KnlSMWDQ76dzQpac=", - "path": "./lib", - "type": "path" + "lastModified": 1620188794, + "narHash": "sha256-BDwtrbUkrSnBQJBXuaJg9QBu3MYL0iuJPE8P30o0x7I=", + "owner": "divnix", + "repo": "devlib", + "rev": "ffda6add9eb984d986cf5b6a838a52334317302f", + "type": "github" }, "original": { - "path": "./lib", - "type": "path" + "owner": "divnix", + "repo": "devlib", + "type": "github" } }, "devshell": { @@ -321,7 +325,7 @@ "inputs": { "ci-agent": "ci-agent", "darwin": "darwin", - "devos": "devos", + "devlib": "devlib", "home": "home", "latest": "latest", "naersk": "naersk_2", diff --git a/flake.nix b/flake.nix index a7811996..8dc8e7e7 100644 --- a/flake.nix +++ b/flake.nix @@ -5,14 +5,9 @@ { nixos.url = "nixpkgs/nixos-unstable"; latest.url = "nixpkgs"; - devos.url = "path:./lib"; # TODO: outfactor into separate repo - devos.inputs = { + devlib.url = "github:divnix/devlib"; + devlib.inputs = { nixpkgs.follows = "nixos"; - # deploy.inputs = { - # flake-compat.follows = "flake-compat"; - # naersk.follows = "naersk"; - # nixpkgs.follows = "nixos"; - # }; }; ci-agent = { @@ -31,8 +26,8 @@ pkgs.inputs.nixpkgs.follows = "nixos"; }; - outputs = inputs@{ self, pkgs, devos, nixos, ci-agent, home, nixos-hardware, nur, ... }: - devos.lib.mkFlake { + outputs = inputs@{ self, pkgs, devlib, nixos, ci-agent, home, nixos-hardware, nur, ... }: + devlib.lib.mkFlake { inherit self inputs; channelsConfig = { allowUnfree = true; }; @@ -40,7 +35,7 @@ channels = { nixos = { overlays = [ - (devos.lib.pathsIn ./overlays) + (devlib.lib.pathsIn ./overlays) ./pkgs/default.nix pkgs.overlay # for `srcs` nur.overlay @@ -49,6 +44,12 @@ latest = { }; }; + sharedOverlays = [ + (final: prev: { + ourlib = prev.devlib.extend (import ./lib); + }) + ]; + nixos = { hostDefaults = { system = "x86_64-linux"; @@ -61,7 +62,7 @@ ]; }; hosts = nixos.lib.mkMerge [ - (devos.lib.importHosts ./hosts) + (devlib.lib.importHosts ./hosts) { /* set host specific properties here */ } ]; profiles = [ ./profiles ./users ]; @@ -79,9 +80,9 @@ }; }; - homeConfigurations = devos.lib.mkHomeConfigurations self.nixosConfigurations; + homeConfigurations = devlib.lib.mkHomeConfigurations self.nixosConfigurations; - deploy.nodes = devos.lib.mkDeployNodes self.nixosConfigurations { }; + deploy.nodes = devlib.lib.mkDeployNodes self.nixosConfigurations { }; #defaultTemplate = self.templates.flk; templates.flk.path = ./.; diff --git a/lib/attrs.nix b/lib/attrs.nix deleted file mode 100644 index 1061c0e2..00000000 --- a/lib/attrs.nix +++ /dev/null @@ -1,19 +0,0 @@ -{ lib }: -rec { - # mapFilterAttrs :: - # (name -> value -> bool ) - # (name -> value -> { name = any; value = any; }) - # attrs - mapFilterAttrs = seive: f: attrs: - lib.filterAttrs - seive - (lib.mapAttrs' f attrs); - - # Generate an attribute set by mapping a function over a list of values. - genAttrs' = values: f: lib.listToAttrs (map f values); - - concatAttrs = lib.fold (attr: sum: lib.recursiveUpdate sum attr) { }; - - safeReadDir = path: - lib.optionalAttrs (builtins.pathExists (toString path)) (builtins.readDir (toString path)); -} diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 00000000..c4da46cc --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,2 @@ +lfinal: lprev: { +} diff --git a/lib/devos/mkHomeConfigurations.nix b/lib/devos/mkHomeConfigurations.nix deleted file mode 100644 index 95affc26..00000000 --- a/lib/devos/mkHomeConfigurations.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ lib }: - -nixosConfigurations: - -with lib; -let - mkHomes = hostName: host: - mapAttrs' (user: v: nameValuePair "${user}@${hostName}" v.home) - # So this function is useful for non-devos hosts - (host.config.system.build.homes or host.config.home-manager.users); - - hmConfigs = mapAttrs mkHomes nixosConfigurations; - -in -foldl recursiveUpdate { } (attrValues hmConfigs) diff --git a/lib/flake.lock b/lib/flake.lock deleted file mode 100644 index 8156254b..00000000 --- a/lib/flake.lock +++ /dev/null @@ -1,166 +0,0 @@ -{ - "nodes": { - "deploy": { - "inputs": { - "flake-compat": "flake-compat", - "naersk": "naersk", - "nixpkgs": "nixpkgs", - "utils": "utils" - }, - "locked": { - "lastModified": 1616406726, - "narHash": "sha256-n9zmgxR03QNrvs9/fHewqE0j3SjL7Y+cglBCFu3U3rg=", - "owner": "serokell", - "repo": "deploy-rs", - "rev": "9e405fbc5ab5bacbd271fd78c6b6b6877c4d9f8d", - "type": "github" - }, - "original": { - "owner": "serokell", - "repo": "deploy-rs", - "type": "github" - } - }, - "devshell": { - "locked": { - "lastModified": 1618523768, - "narHash": "sha256-Gev9da35pHUey3kGz/zrJFc/9ICs++vPCho7qB1mqd8=", - "owner": "numtide", - "repo": "devshell", - "rev": "709fe4d04a9101c9d224ad83f73416dce71baf21", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, - "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-utils": { - "locked": { - "lastModified": 1619345332, - "narHash": "sha256-qHnQkEp1uklKTpx3MvKtY6xzgcqXDsz5nLilbbuL+3A=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "2ebf2558e5bf978c7fb8ea927dfaed8fefab2e28", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "naersk": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "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" - } - }, - "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" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1619244632, - "narHash": "sha256-IDcbMRnyKO9WlQ5xzIlM3HfWAUKTy+3xSd+CvDGiLgE=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "5cecebfb2f76da7b93f19967e99b3ff4fb4d2850", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, - "root": { - "inputs": { - "deploy": "deploy", - "devshell": "devshell", - "nixpkgs": "nixpkgs_2", - "utils": "utils_2" - } - }, - "utils": { - "locked": { - "lastModified": 1610051610, - "narHash": "sha256-U9rPz/usA1/Aohhk7Cmc2gBrEEKRzcW4nwPWMPwja4Y=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "3982c9903e93927c2164caa727cd3f6a0e6d14cc", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "utils_2": { - "inputs": { - "flake-utils": "flake-utils" - }, - "locked": { - "lastModified": 1619714004, - "narHash": "sha256-xoP81rWAM2cVpEFrQv9sUEIvNxGXAg4UH9kBt83a5u4=", - "owner": "gytis-ivaskevicius", - "repo": "flake-utils-plus", - "rev": "0642ac572a87a0beb78a7c6ddce1267aa5817d05", - "type": "github" - }, - "original": { - "owner": "gytis-ivaskevicius", - "ref": "staging", - "repo": "flake-utils-plus", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/lib/flake.nix b/lib/flake.nix deleted file mode 100644 index 5fd79366..00000000 --- a/lib/flake.nix +++ /dev/null @@ -1,84 +0,0 @@ -{ - description = "DevOS environment configuriguration library."; - - inputs = - { - deploy.url = "github:serokell/deploy-rs"; - devshell.url = "github:numtide/devshell"; - utils.url = "github:gytis-ivaskevicius/flake-utils-plus/staging"; - }; - - outputs = inputs@{ self, nixpkgs, deploy, devshell, utils, ... }: - let - lib = nixpkgs.lib.makeExtensible (self: - let combinedLib = nixpkgs.lib // self; in - with self; - utils.lib // { - attrs = import ./attrs.nix { lib = combinedLib; }; - lists = import ./lists.nix { lib = combinedLib; }; - strings = import ./strings.nix { lib = combinedLib; }; - modules = import ./modules.nix { lib = combinedLib; }; - importers = import ./importers.nix { lib = combinedLib; }; - - generators = import ./generators.nix { - lib = combinedLib; - inherit deploy; - }; - - mkFlake = { - __functor = import ./mkFlake { lib = combinedLib; }; - evalArgs = import ./mkFlake/evalArgs.nix { lib = combinedLib; }; - }; - - pkgs-lib = import ./pkgs-lib { - lib = combinedLib; - inherit deploy devshell; - }; - - inherit (attrs) mapFilterAttrs genAttrs' safeReadDir concatAttrs; - inherit (lists) profileMap collectProfiles unifyOverlays; - inherit (strings) rgxToString; - inherit (importers) mkProfileAttrs pathsIn importHosts; - inherit (generators) mkSuites mkDeployNodes mkHomeConfigurations; - } - ); - - in - - { - lib = with lib; utils.lib // { - inherit attrs lists modules importers generators; - inherit (lib) - mkFlake - pathsIn - importHosts - mkDeployNodes - mkHomeConfigurations; - }; - } - - // - - utils.lib.eachDefaultSystem (system: - let - pkgs = import nixpkgs { inherit system; }; - in - { - checks = { - tests = import ./tests { - inherit pkgs; - lib = nixpkgs.lib // lib; - }; - }; - packages = { - mkFlakeDoc = pkgs.writeText "mkFlakeOptions.md" - ( - pkgs.nixosOptionsDoc { - inherit (lib.mkFlake.evalArgs { args = { }; }) options; - } - ).optionsMDDoc; - }; - } - ); - -} diff --git a/lib/generators.nix b/lib/generators.nix deleted file mode 100644 index f403fbc2..00000000 --- a/lib/generators.nix +++ /dev/null @@ -1,50 +0,0 @@ -{ lib, deploy }: -{ - mkHomeConfigurations = nixosConfigurations: - with lib; - let - mkHomes = host: config: - mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) - config.config.system.build.homes; - - hmConfigs = mapAttrs mkHomes nixosConfigurations; - - in - foldl recursiveUpdate { } (attrValues hmConfigs); - - mkDeployNodes = hosts: extraConfig: - /** - Synopsis: mkNodes _nixosConfigurations_ - - Generate the `nodes` attribute expected by deploy-rs - where _nixosConfigurations_ are `nodes`. - **/ - - lib.mapAttrs - (_: config: lib.recursiveUpdate - { - hostname = config.config.networking.hostName; - - profiles.system = { - user = "root"; - path = deploy.lib.x86_64-linux.activate.nixos config; - }; - } - extraConfig) - hosts; - - mkSuites = { suites, profiles }: - let - profileSet = lib.genAttrs' profiles (path: { - name = baseNameOf path; - value = lib.mkProfileAttrs (toString path); - }); - - definedSuites = suites profileSet; - - allProfiles = lib.collectProfiles profileSet; - in - lib.mapAttrs (_: v: lib.profileMap v) definedSuites // { - inherit allProfiles; - }; -} diff --git a/lib/importers.nix b/lib/importers.nix deleted file mode 100644 index ea07373d..00000000 --- a/lib/importers.nix +++ /dev/null @@ -1,64 +0,0 @@ -{ lib }: -let - recImport = { dir, _import ? base: import "${dir}/${base}.nix" }: - lib.mapFilterAttrs - (_: v: v != null) - (n: v: - if n != "default.nix" && lib.hasSuffix ".nix" n && v == "regular" - then - let name = lib.removeSuffix ".nix" n; in lib.nameValuePair (name) (_import name) - else - lib.nameValuePair ("") (null)) - (lib.safeReadDir dir); - - mkProfileAttrs = - /** - Synopsis: mkProfileAttrs _path_ - - Recursively collect the subdirs of _path_ containing a default.nix into attrs. - This sets a contract, eliminating ambiguity for _default.nix_ living under the - profile directory. - - Example: - let profiles = mkProfileAttrs ./profiles; in - assert profiles ? core.default; 0 - **/ - dir: - let - imports = - let - files = lib.safeReadDir dir; - - p = n: v: - v == "directory" - && n != "profiles"; - in - lib.filterAttrs p files; - - f = n: _: - lib.optionalAttrs - (lib.pathExists "${dir}/${n}/default.nix") - { default = "${dir}/${n}"; } - // mkProfileAttrs "${dir}/${n}"; - in - lib.mapAttrs f imports; - -in -{ - inherit recImport mkProfileAttrs; - - pathsIn = dir: - let - fullPath = name: "${toString dir}/${name}"; - in - map fullPath (lib.attrNames (lib.safeReadDir dir)); - - importHosts = dir: - recImport { - inherit dir; - _import = base: { - modules = import "${toString dir}/${base}.nix"; - }; - }; -} - diff --git a/lib/lists.nix b/lib/lists.nix deleted file mode 100644 index 4bef865e..00000000 --- a/lib/lists.nix +++ /dev/null @@ -1,19 +0,0 @@ -{ lib }: -{ - collectProfiles = set: - let - collectNestedProfiles = set: - lib.mapAttrsToList - (n: v: - if builtins.isAttrs v then - [ v.default or null ] ++ collectNestedProfiles v - else null - ) - set; - in - builtins.filter (x: x != null) (lib.flatten (collectNestedProfiles set)); - - profileMap = list: map (profile: profile.default) (lib.flatten list); - - unifyOverlays = channels: map (o: if builtins.isFunction (o null null) then o channels else o); -} diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix deleted file mode 100644 index e2d0b73c..00000000 --- a/lib/mkFlake/default.nix +++ /dev/null @@ -1,99 +0,0 @@ -{ lib }: -let - inherit (builtins) mapAttrs attrNames attrValues head isFunction; -in - -_: { self, inputs, ... } @ args: -let - - config = lib.mkFlake.evalArgs { - inherit args; - }; - - cfg = config.config; - - otherArguments = removeAttrs args (attrNames config.options); - - defaultModules = with lib.modules; [ - (hmDefaults { - inherit (cfg.home) suites; - modules = cfg.home.modules ++ cfg.home.externalModules; - }) - (globalDefaults { - inherit self inputs; - }) - ]; - - stripChannel = channel: removeAttrs channel [ - # arguments in our channels api that shouldn't be passed to fup - "overlays" - ]; - getDefaultChannel = channels: channels.${cfg.nixos.hostDefaults.channelName}; - - # evalArgs sets channelName and system to null by default - # but for proper default handling in fup, null args have to be removed - stripHost = args: removeAttrs (lib.filterAttrs (_: arg: arg != null) args) [ - # arguments in our hosts/hostDefaults api that shouldn't be passed to fup - "externalModules" - ]; - hosts = lib.mapAttrs (_: stripHost) cfg.nixos.hosts; - hostDefaults = stripHost cfg.nixos.hostDefaults; -in -lib.systemFlake (lib.mergeAny - { - inherit self inputs hosts; - inherit (cfg) channelsConfig supportedSystems; - - channels = mapAttrs - (name: channel: - stripChannel (channel // { - # pass channels if "overlay" has three arguments - overlaysBuilder = channels: lib.unifyOverlays channels channel.overlays; - }) - ) - cfg.channels; - - sharedOverlays = [ - (final: prev: { - __dontExport = true; - devlib = lib; - }) - ]; - hostDefaults = lib.mergeAny hostDefaults { - specialArgs.suites = cfg.nixos.suites; - modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules; - builder = args: args.specialArgs.channel.input.lib.nixosSystem (lib.mergeAny args { - # So modules and functions can create their own version of the build - modules = [{ lib.builderArgs = args; }]; - }); - }; - - nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules; - - homeModules = lib.exporter.modulesFromList cfg.home.modules; - - overlays = lib.exporter.overlaysFromChannelsExporter { - # since we can't detect overlays owned by self - # we have to filter out ones exported by the inputs - # optimally we would want a solution for NixOS/nix#4740 - inherit inputs; - inherit (self) pkgs; - }; - - packagesBuilder = lib.builder.packagesFromOverlaysBuilderConstructor self.overlays; - - checksBuilder = channels: - lib.pkgs-lib.tests.mkChecks { - pkgs = getDefaultChannel channels; - inherit (self.deploy) nodes; - hosts = self.nixosConfigurations; - homes = self.homeConfigurations; - }; - - devShellBuilder = channels: - lib.pkgs-lib.shell { - pkgs = getDefaultChannel channels; - }; - } - otherArguments # for overlays list order -) diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix deleted file mode 100644 index bf366274..00000000 --- a/lib/mkFlake/evalArgs.nix +++ /dev/null @@ -1,262 +0,0 @@ -{ lib }: - -{ args }: -let - argOpts = with lib; { config, ... }: - let - cfg = config; - inherit (config) self; - - maybeImport = obj: - if (builtins.typeOf obj == "path") || (builtins.typeOf obj == "string") then - import obj - else - obj; - - /* Custom types needed for arguments */ - - moduleType = with types; pathTo (anything // { - inherit (submodule { }) check; - description = "valid module"; - }); - - # to export modules we need paths to get the name - exportModuleType = with types; - (addCheck path (x: moduleType.check (import x))) // { - description = "path to a module"; - }; - overlayType = pathTo (types.anything // { - check = builtins.isFunction; - description = "valid Nixpkgs overlay"; - }); - systemType = types.enum config.supportedSystems; - flakeType = with types; (addCheck attrs lib.isStorePath) // { - description = "nix flake"; - }; - - # Apply maybeImport during merge and before check - # To simplify apply keys and improve type checking - pathTo = elemType: with types; coercedTo path maybeImport elemType; - - pathToListOf = elemType: with types; pathTo (listOf elemType); - - coercedListOf = elemType: with types; - coercedTo anything (x: flatten (singleton x)) (listOf elemType); - - /* Submodules needed for API containers */ - - channelsModule = { name, ... }: { - options = with types; { - input = mkOption { - type = flakeType; - default = cfg.inputs.${name}; - defaultText = "inputs."; - description = '' - nixpkgs flake input to use for this channel - ''; - }; - overlays = mkOption { - type = coercedListOf overlayType; - default = [ ]; - description = escape [ "<" ">" ] '' - overlays to apply to this channel - these will get exported under the 'overlays' flake output - as / and any overlay pulled from ''\${inputs} - will be filtered out - ''; - }; - config = mkOption { - type = pathTo attrs; - default = { }; - apply = lib.recursiveUpdate cfg.channelsConfig; - description = '' - nixpkgs config for this channel - ''; - }; - }; - }; - - hostModule = { - options = with types; { - # anything null in hosts gets filtered out by mkFlake - system = mkOption { - type = (nullOr systemType) // { - description = "system defined in `supportedSystems`"; - }; - default = null; - description = '' - system for this host - ''; - }; - channelName = mkOption { - type = (nullOr (types.enum (builtins.attrNames config.channels))) // { - description = "a channel defined in `channels`"; - }; - default = null; - description = '' - Channel this host should follow - ''; - }; - }; - }; - - # This is only needed for hostDefaults - # modules in each host don't get exported - externalModulesModule = { - options = { - externalModules = mkOption { - type = with types; listOf moduleType; - default = [ ]; - description = '' - modules to include that won't be exported - meant importing modules from external flakes - ''; - }; - }; - }; - - modulesModule = { - options = { - modules = mkOption { - type = with types; coercedListOf moduleType; - default = [ ]; - description = '' - modules to include - ''; - }; - }; - }; - - exportModulesModule = name: { - options = { - modules = mkOption { - type = with types; pathTo (coercedListOf exportModuleType); - default = [ ]; - description = '' - modules to include in all hosts and export to ${name}Modules output - ''; - }; - }; - }; - - - - # Home-manager's configs get exported automatically from nixos.hosts - # So there is no need for a host options in the home namespace - # This is only needed for nixos - includeHostsModule = name: { - options = with types; { - hostDefaults = mkOption { - type = submodule [ - hostModule - externalModulesModule - (exportModulesModule name) - ]; - default = { }; - description = '' - Defaults for all hosts. - the modules passed under hostDefaults will be exported - to the '${name}Modules' flake output. - They will also be added to all hosts. - ''; - }; - hosts = mkOption { - type = attrsOf (submodule [ hostModule modulesModule ]); - default = { }; - description = '' - configurations to include in the ${name}Configurations output - ''; - }; - }; - }; - - # profiles and suites - which are profile collections - profilesModule = { config, ... }: { - options = with types; { - profiles = mkOption { - type = listOf path; - default = [ ]; - description = '' - profile folders that can be collected into suites - the name of the argument passed to suites is based - on the folder name. - [ ./profiles ] => { profiles }: - ''; - }; - suites = mkOption { - type = pathTo (functionTo attrs); - default = _: { }; - apply = suites: lib.mkSuites { - inherit suites; - inherit (config) profiles; - }; - description = '' - Function that takes profiles and returns suites for this config system - These can be accessed through the 'suites' special argument. - ''; - }; - }; - }; - in - { - # this does not get propagated to submodules - # to allow passing flake outputs directly to mkFlake - config._module.check = false; - - options = with types; { - self = mkOption { - type = flakeType; - description = "The flake to create the devos outputs for"; - }; - inputs = mkOption { - type = attrsOf flakeType; - description = '' - inputs for this flake - used to set channel defaults and create registry - ''; - }; - supportedSystems = mkOption { - type = listOf str; - default = lib.defaultSystems; - description = '' - The systems supported by this flake - ''; - }; - channelsConfig = mkOption { - type = pathTo attrs; - default = { }; - description = '' - nixpkgs config for all channels - ''; - }; - channels = mkOption { - type = attrsOf (submodule channelsModule); - default = { }; - description = '' - nixpkgs channels to create - ''; - }; - nixos = mkOption { - type = submodule [ (includeHostsModule "nixos") profilesModule ]; - default = { }; - description = '' - hosts, modules, suites, and profiles for nixos - ''; - }; - home = mkOption { - type = submodule [ - profilesModule - (exportModulesModule "home") - externalModulesModule - ]; - default = { }; - description = '' - hosts, modules, suites, and profiles for home-manager - ''; - }; - }; - }; -in -lib.evalModules { - modules = [ argOpts args ]; -} diff --git a/lib/modules.nix b/lib/modules.nix deleted file mode 100644 index d5641962..00000000 --- a/lib/modules.nix +++ /dev/null @@ -1,119 +0,0 @@ -{ lib }: -{ - hmDefaults = { suites, modules }: - { options, ... }: { - config = lib.optionalAttrs (options ? home-manager) { - home-manager = { - useGlobalPkgs = true; - useUserPackages = true; - - extraSpecialArgs = { inherit suites; }; - sharedModules = modules; - }; - }; - }; - - globalDefaults = { self, inputs }: - let - experimentalFeatures = [ - "flakes" - "nix-command" - "ca-references" - "ca-derivations" - ]; - in - { channel, config, pkgs, ... }: { - users.mutableUsers = lib.mkDefault false; - - hardware.enableRedistributableFirmware = lib.mkDefault true; - - nix.nixPath = [ - "nixpkgs=${channel.input}" - "nixos-config=${self}/lib/compat/nixos" - "home-manager=${inputs.home}" - ]; - - nix.registry = { - devos.flake = self; - nixos.flake = channel.input; - }; - - nix.extraOptions = '' - experimental-features = ${lib.concatStringsSep " " - experimentalFeatures - } - ''; - - _module.args = { - inherit self; - devlib = pkgs.devlib; - hosts = builtins.mapAttrs (_: host: host.config) - (removeAttrs self.nixosConfigurations [ config.networking.hostName ]); - }; - - system.configurationRevision = lib.mkIf (self ? rev) self.rev; - }; - - isoConfig = { self, inputs, fullHostConfig }: - { config, modulesPath, suites, ... }: { - - imports = [ "${modulesPath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ]; - # avoid unwanted systemd service startups - # all strings in disabledModules get appended to modulesPath - # so convert each to list which can be coerced to string - disabledModules = map lib.singleton suites.allProfiles; - - nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs; - - isoImage.isoBaseName = "nixos-" + config.networking.hostName; - isoImage.contents = [{ - source = self; - target = "/devos/"; - }]; - isoImage.storeContents = [ - self.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 - ]; - # still pull in tools of deactivated profiles - environment.systemPackages = fullHostConfig.environment.systemPackages; - - # confilcts with networking.wireless which might be slightly - # more useful on a stick - networking.networkmanager.enable = lib.mkForce false; - # confilcts with networking.wireless - networking.wireless.iwd.enable = lib.mkForce false; - - # Set up a link-local boostrap network - # See also: https://github.com/NixOS/nixpkgs/issues/75515#issuecomment-571661659 - networking.usePredictableInterfaceNames = lib.mkForce true; # so prefix matching works - networking.useNetworkd = lib.mkForce true; - networking.useDHCP = lib.mkForce false; - networking.dhcpcd.enable = lib.mkForce false; - systemd.network = { - # https://www.freedesktop.org/software/systemd/man/systemd.network.html - networks."boostrap-link-local" = { - matchConfig = { - Name = "en* wl* ww*"; - }; - networkConfig = { - Description = "Link-local host bootstrap network"; - MulticastDNS = true; - LinkLocalAddressing = "ipv6"; - DHCP = "yes"; - }; - address = [ - # fall back well-known link-local for situations where MulticastDNS is not available - "fe80::47" # 47: n=14 i=9 x=24; n+i+x - ]; - extraConfig = '' - # Unique, yet stable. Based off the MAC address. - IPv6LinkLocalAddressGenerationMode = "eui64" - ''; - }; - }; - }; - -} - diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix deleted file mode 100644 index bcaee771..00000000 --- a/lib/pkgs-lib/default.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ lib, deploy, devshell }: -{ - tests = import ./tests { inherit lib deploy; }; - shell = import ./shell { inherit lib devshell deploy; }; -} - diff --git a/lib/pkgs-lib/shell/default.nix b/lib/pkgs-lib/shell/default.nix deleted file mode 100644 index 5b73b54c..00000000 --- a/lib/pkgs-lib/shell/default.nix +++ /dev/null @@ -1,55 +0,0 @@ -{ lib, devshell, deploy }: - -{ pkgs }: -let - overlays = [ - devshell.overlay - - (final: prev: { - deploy-rs = - deploy.packages.${prev.system}.deploy-rs; - }) - ]; - - pkgs' = import pkgs.path { - inherit (pkgs) system; - inherit overlays; - }; - - flk = pkgs'.callPackage ./flk.nix { }; - - installPkgs = (lib.nixosSystem { - inherit (pkgs') system; - modules = [ ]; - }).config.system.build; -in -pkgs'.devshell.mkShell { - imports = [ (pkgs'.devshell.importTOML ./devshell.toml) ]; - - packages = with installPkgs; [ - nixos-install - nixos-generate-config - nixos-enter - ]; - - git.hooks = { - pre-commit.text = lib.fileContents ./pre-commit.sh; - }; - - commands = with pkgs'; [ - { package = flk; } - { - name = "nix"; - help = pkgs'.nixFlakes.meta.description; - command = '' - ${pkgs'.nixFlakes}/bin/nix --experimental-features "nix-command flakes ca-references" "${"\${@}"}" - ''; - } - ] - ++ lib.optional (system != "i686-linux") { package = cachix; } - ++ lib.optional (system == "x86_64-linux") { - name = "deploy"; - package = deploy-rs; - help = "A simple multi-profile Nix-flake deploy tool."; - }; -} diff --git a/lib/pkgs-lib/shell/devshell.toml b/lib/pkgs-lib/shell/devshell.toml deleted file mode 100644 index f261fdc3..00000000 --- a/lib/pkgs-lib/shell/devshell.toml +++ /dev/null @@ -1,29 +0,0 @@ -imports = [ "git.hooks" ] - -[devshell] -packages = [ - "git-crypt" -] - -[[commands]] -package = "git" -category = "vcs" - -[[commands]] -package = "nixpkgs-fmt" -category = "linters" - -[[commands]] -package = "editorconfig-checker" -category = "linters" - -[[commands]] -package = "python3Packages.grip" -category = "documentation" - -[[commands]] -package = "mdbook" -category = "documentation" - -[git.hooks] -enable = true diff --git a/lib/pkgs-lib/shell/flk.nix b/lib/pkgs-lib/shell/flk.nix deleted file mode 100644 index ff9c59e7..00000000 --- a/lib/pkgs-lib/shell/flk.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ stdenv }: -let - name = "flk"; -in -stdenv.mkDerivation { - inherit name; - - src = ./flk.sh; - - dontUnpack = true; - dontBuild = true; - - installPhase = '' - mkdir -p $out/bin - install $src $out/bin/${name} - ''; - - checkPhase = '' - ${stdenv.shell} -n -O extglob $out/bin/${name} - ''; - - meta.description = "Build, deploy, and install NixOS"; -} diff --git a/lib/pkgs-lib/shell/flk.sh b/lib/pkgs-lib/shell/flk.sh deleted file mode 100755 index 2d460458..00000000 --- a/lib/pkgs-lib/shell/flk.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env bash - -[[ -d "$DEVSHELL_ROOT" ]] || - { - echo "This script must be run from devos's devshell" >&2 - exit 1 - } - -shopt -s extglob - -HOSTNAME="$(hostname)" - -usage () { - printf "%b\n" \ - "\e[4mUsage\e[0m: $(basename $0) COMMAND [ARGS]\n" \ - "\e[4mCommands\e[0m:" - - printf " %-30s %s\n\n" \ - "up" "Generate $DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix" \ - "update [INPUT]" "Update and commit the lock file, or specific input" \ - "get (core|community) [DEST]" "Copy the desired template to DEST" \ - "iso HOST" "Generate an ISO image of HOST" \ - "install HOST [ARGS]" "Shortcut for nixos-install" \ - "home HOST USER [switch]" "Home-manager config of USER from HOST" \ - "HOST (switch|boot|test)" "Shortcut for nixos-rebuild" -} - -case "$1" in - ""|"-h"|"help"|*(-)"help") - usage - ;; - - "up") - mkdir -p "$DEVSHELL_ROOT/up" - - nixos-generate-config --dir "$DEVSHELL_ROOT/up/$HOSTNAME" - - printf "%s\n" \ - "{ suites, ... }:" \ - "{" \ - " imports = [" \ - " ../up/$HOSTNAME/configuration.nix" \ - " ] ++ suites.core;" \ - "}" > "$DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix" - - git add -f \ - "$DEVSHELL_ROOT/up/$HOSTNAME" \ - "$DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix" - ;; - - "update") - if [[ -n "$2" ]]; then - if [[ -n "$3" ]]; then - (cd $2; nix flake list-inputs --update-input "$3") - else - (cd $2; nix flake update) - fi - nix flake list-inputs --update-input "$2" "$DEVSHELL_ROOT" - else - nix flake update "$DEVSHELL_ROOT" - fi - ;; - - "get") - if [[ "$2" == "core" || "$2" == "community" ]]; then - nix flake new -t "github:divnix/devos/$2" "${3:-flk}" - else - echo "flk get (core|community) [DEST]" - exit 1 - fi - ;; - - "iso") - nix build \ - "$DEVSHELL_ROOT#nixosConfigurations.$2.config.system.build.iso" \ - "${@:3}" - ;; - - "install") - sudo nixos-install --flake "$DEVSHELL_ROOT#$2" "${@:3}" - ;; - - "home") - ref="$DEVSHELL_ROOT/#homeConfigurations.$3@$2.activationPackage" - - if [[ "$4" == "switch" ]]; then - nix build "$ref" && result/activate && - unlink result - - else - nix build "$ref" "${@:4}" - fi - ;; - - *) - sudo nixos-rebuild --flake "$DEVSHELL_ROOT#$1" "${@:2}" - ;; -esac diff --git a/lib/pkgs-lib/shell/pre-commit.sh b/lib/pkgs-lib/shell/pre-commit.sh deleted file mode 100755 index 985d3b40..00000000 --- a/lib/pkgs-lib/shell/pre-commit.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -if git rev-parse --verify HEAD >/dev/null 2>&1 -then - against=HEAD -else - # Initial commit: diff against an empty tree object - against=$(${git}/bin/git hash-object -t tree /dev/null) -fi - -diff="git diff-index --name-only --cached $against --diff-filter d" - -nix_files=($($diff -- '*.nix')) -all_files=($($diff)) - -# Format staged nix files. -if [[ -n "${nix_files[@]}" ]]; then - nixpkgs-fmt "${nix_files[@]}" \ - && git add "${nix_files[@]}" -fi - -# check editorconfig -editorconfig-checker -- "${all_files[@]}" -if [[ $? != '0' ]]; then - printf "%b\n" \ - "\nCode is not aligned with .editorconfig" \ - "Review the output and commit your fixes" >&2 - exit 1 -fi diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix deleted file mode 100644 index e08702ac..00000000 --- a/lib/pkgs-lib/tests/default.nix +++ /dev/null @@ -1,56 +0,0 @@ -{ lib, deploy }: -let - mkChecks = { pkgs, hosts, nodes, homes ? { } }: - let - deployHosts = lib.filterAttrs - (n: _: hosts.${n}.config.nixpkgs.system == pkgs.system) - nodes; - deployChecks = deploy.lib.${pkgs.system}.deployChecks { nodes = deployHosts; }; - tests = - lib.optionalAttrs (deployHosts != { }) - { - profilesTest = profilesTest { - inherit pkgs; - host = hosts.${(builtins.head (builtins.attrNames deployHosts))}; - }; - } // lib.mapAttrs (n: v: v.activationPackage) homes; - - in - lib.recursiveUpdate tests deployChecks; - - mkTest = { pkgs, host }: - let - nixosTesting = - (import "${toString pkgs.path}/nixos/lib/testing-python.nix" { - inherit (pkgs) system; - inherit (host.config.lib.builderArgs) specialArgs; - inherit pkgs; - extraConfigurations = host._module.args.modules; - }); - in - test: - let - loadedTest = - if builtins.typeOf test == "path" - then import test - else test; - calledTest = - if pkgs.lib.isFunction loadedTest - then pkgs.callPackage loadedTest { } - else loadedTest; - in - nixosTesting.makeTest calledTest; - - profilesTest = args@{ host, ... }: mkTest args { - name = "profiles"; - - machine = { suites, ... }: { - imports = suites.allProfiles; - }; - - testScript = '' - ${host.config.networking.hostName}.systemctl("is-system-running --wait") - ''; - }; -in -{ inherit mkTest profilesTest mkChecks; } diff --git a/lib/pkgs-lib/tests/lib.nix b/lib/pkgs-lib/tests/lib.nix deleted file mode 100644 index 586eac31..00000000 --- a/lib/pkgs-lib/tests/lib.nix +++ /dev/null @@ -1,93 +0,0 @@ -{ pkgs, lib, ... }: -with lib; -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/strings.nix b/lib/strings.nix deleted file mode 100644 index d411bab8..00000000 --- a/lib/strings.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ lib }: -{ - # returns matching part of _regex_ _string_; null indicates failure. - rgxToString = regex: string: - let - match = - let - head = lib.substring 0 1 regex; - sec = lib.substring 1 2 regex; - in - if head == "^" - || head == "." - || (sec == "*" || sec == "+" || sec == "?") - then builtins.match "(${regex}).*" string - else builtins.match ".*(${regex}).*" string; - in - if lib.isList match - then lib.head match - else null; -} diff --git a/lib/tests/default.nix b/lib/tests/default.nix deleted file mode 100644 index ab4d516b..00000000 --- a/lib/tests/default.nix +++ /dev/null @@ -1,27 +0,0 @@ -{ pkgs, lib }: - -pkgs.runCommandNoCC "devos-lib-tests" -{ - buildInputs = [ - pkgs.nix - ( - let tests = import ./lib.nix { inherit pkgs lib; }; 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 deleted file mode 100644 index 78536e75..00000000 --- a/lib/tests/lib.nix +++ /dev/null @@ -1,70 +0,0 @@ -{ pkgs, lib }: -with lib; -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 - ]; - }; - - 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 = { - expr = mkSuites { - suites = { profiles, ... }: with profiles; { - bar = [ foo ]; - }; - profiles = [ (./profiles) ]; - }; - expected = { - bar = [ (toString ./profiles/foo) ]; - allProfiles = [ - (toString ./profiles/foo) - (toString ./profiles/t) - ]; - }; - }; -} diff --git a/lib/tests/profiles/foo/default.nix b/lib/tests/profiles/foo/default.nix deleted file mode 100644 index 2181e561..00000000 --- a/lib/tests/profiles/foo/default.nix +++ /dev/null @@ -1,3 +0,0 @@ -{ - bar = 5; -} diff --git a/lib/tests/profiles/t/default.nix b/lib/tests/profiles/t/default.nix deleted file mode 100644 index 8b137891..00000000 --- a/lib/tests/profiles/t/default.nix +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib/tests/testPathsIn/bar b/lib/tests/testPathsIn/bar deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/tests/testPathsIn/baz b/lib/tests/testPathsIn/baz deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/tests/testPathsIn/foo b/lib/tests/testPathsIn/foo deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/tests/testPathsToImportedAttrs/bar.nix b/lib/tests/testPathsToImportedAttrs/bar.nix deleted file mode 100644 index 0e5233df..00000000 --- a/lib/tests/testPathsToImportedAttrs/bar.nix +++ /dev/null @@ -1 +0,0 @@ -{ foo = 2; } diff --git a/lib/tests/testPathsToImportedAttrs/dir/default.nix b/lib/tests/testPathsToImportedAttrs/dir/default.nix deleted file mode 100644 index 01cb9264..00000000 --- a/lib/tests/testPathsToImportedAttrs/dir/default.nix +++ /dev/null @@ -1 +0,0 @@ -{ a = 5; } diff --git a/lib/tests/testPathsToImportedAttrs/f.nix b/lib/tests/testPathsToImportedAttrs/f.nix deleted file mode 100644 index c4d456a0..00000000 --- a/lib/tests/testPathsToImportedAttrs/f.nix +++ /dev/null @@ -1 +0,0 @@ -true && false diff --git a/lib/tests/testPathsToImportedAttrs/foo.nix b/lib/tests/testPathsToImportedAttrs/foo.nix deleted file mode 100644 index 2f11bd33..00000000 --- a/lib/tests/testPathsToImportedAttrs/foo.nix +++ /dev/null @@ -1 +0,0 @@ -{ bar = 1; } diff --git a/lib/tests/testPathsToImportedAttrs/t.nix b/lib/tests/testPathsToImportedAttrs/t.nix deleted file mode 100644 index 3be59dcd..00000000 --- a/lib/tests/testPathsToImportedAttrs/t.nix +++ /dev/null @@ -1 +0,0 @@ -true || false From f4cd79194afdb9f965d9cc5521705d920e1e62f8 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 4 May 2021 21:49:16 -0700 Subject: [PATCH 75/91] add in-tree local lib, ourlib --- flake.nix | 5 ++++- lib/default.nix | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 8dc8e7e7..90f84fcb 100644 --- a/flake.nix +++ b/flake.nix @@ -44,9 +44,11 @@ latest = { }; }; + lib = import ./lib { lib = devlib.lib // nixos.lib; }; + sharedOverlays = [ (final: prev: { - ourlib = prev.devlib.extend (import ./lib); + ourlib = self.lib; }) ]; @@ -56,6 +58,7 @@ channelName = "nixos"; modules = ./modules/module-list.nix; externalModules = [ + { _module.args.ourlib = self.lib; } ci-agent.nixosModules.agent-profile home.nixosModules.home-manager ./modules/customBuilds.nix diff --git a/lib/default.nix b/lib/default.nix index c4da46cc..2356e1f0 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,2 +1,2 @@ -lfinal: lprev: { -} +{ lib }: +lib.makeExtensible (self: { }) From 6e906e87bc07b593ea66066a807b744f54035e77 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 10 May 2021 12:17:41 -0700 Subject: [PATCH 76/91] doc/extern: improve overlay filtering explanation Co-authored-by: David Arnold --- doc/concepts/extern.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/concepts/extern.md b/doc/concepts/extern.md index 171d8c58..ba249188 100644 --- a/doc/concepts/extern.md +++ b/doc/concepts/extern.md @@ -13,7 +13,7 @@ flake.nix: channels.nixos.overlays = [ inputs.agenix.overlay ]; } ``` -These overlays will be automatically filtered by inspecting the `inputs` argument. +Upon exporting overlays, these overlays will be automatically filtered out by inspecting the `inputs` argument. ## Modules There is a dedicated `nixos.hostDefaults.externalModules` argument for external From 8f20bb069a082fb9ec7c6c1c64768b3db8e28df7 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 10 May 2021 12:19:31 -0700 Subject: [PATCH 77/91] doc/extern: elaborate external modules filtering Co-authored-by: David Arnold --- doc/concepts/extern.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/concepts/extern.md b/doc/concepts/extern.md index ba249188..45d8dcb5 100644 --- a/doc/concepts/extern.md +++ b/doc/concepts/extern.md @@ -38,5 +38,5 @@ flake.nix: ``` > ##### Note: -> The optimal solution would be to automatically export modules that were created in +> To avoid declaring "external" modules separately, which is obvious since they come from `inputs`, the optimal solution would be to automatically export modules that were created in > your flake. But this is not possible due to NixOS/nix#4740. From 725e459655d6695a7a2d998e9e8ad13a13a98a74 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 10 May 2021 12:22:16 -0700 Subject: [PATCH 78/91] doc/start: fix grammar Co-authored-by: David Arnold --- doc/start/from-nixos.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/start/from-nixos.md b/doc/start/from-nixos.md index a25fb99e..0e1d48cb 100644 --- a/doc/start/from-nixos.md +++ b/doc/start/from-nixos.md @@ -20,7 +20,7 @@ You must then add a host to `nixos.hosts` in flake.nix: ``` Make sure your `i18n.defaultLocale` and `time.timeZone` are set properly for -your region. Keep in mind that `networking.hostName` with be automatically +your region. Keep in mind that `networking.hostName` will be automatically set to the name of your host; Now might be a good time to read the docs on [suites](../concepts/suites.md) and @@ -52,4 +52,3 @@ This calls `nixos-rebuild` with sudo to build and install your configuration. > simply `sudo nixos-rebuild switch` from anywhere on the system, but it is > not required. - From 8a590c9fefa893dd738bc3161052ac9ea5c72c80 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 11 May 2021 11:40:37 -0700 Subject: [PATCH 79/91] core: use self for nixos-option compat path --- profiles/core/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/profiles/core/default.nix b/profiles/core/default.nix index aa3290c6..41b5136e 100644 --- a/profiles/core/default.nix +++ b/profiles/core/default.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ self, config, lib, pkgs, ... }: let inherit (lib) fileContents; in { @@ -76,7 +76,7 @@ in ''; # fix nixos-option - nixos-option = "nixos-option -I nixpkgs=${toString ../../lib/compat}"; + nixos-option = "nixos-option -I nixpkgs=${self}/lib/compat"; # sudo s = ifSudo "sudo -E "; From 0d7eb1c48840c99c24512833d157168201f2b2e3 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 11 May 2021 11:44:05 -0700 Subject: [PATCH 80/91] doc/lib: explain ourlib usage --- doc/lib.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/lib.md b/doc/lib.md index ed19b1a3..ee402ebc 100644 --- a/doc/lib.md +++ b/doc/lib.md @@ -3,8 +3,7 @@ The lib directory mirrors the upstream concepts of [`nixpkgs:./lib`][nixpkgs-lib [`nixpkgs:./nixos/lib`][nixpkgs-nixos-lib] and [`nixpkgs:./pkgs/pkgs-lib`][nixpkgs-pkgs-lib], but also occasionally [`nixpkgs:./pkgs/build-support`][nixpkgs-pkgs-build-support]. -It comes with functions necesary to declutter `devos` itself, but you are -welcome to extend it to your needs. +All functions defined in lib can be accessed in modules and packages as `ourlib`. For example: From a081a922a5f1816e1f3bb0d4d0a3851d5961f89c Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 11 May 2021 23:41:34 -0700 Subject: [PATCH 81/91] flake: update devlib input drop ca experimental features and filterPackages improvements --- flake.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index db2f9144..4a98d121 100644 --- a/flake.lock +++ b/flake.lock @@ -79,11 +79,11 @@ "utils": "utils_2" }, "locked": { - "lastModified": 1620188794, - "narHash": "sha256-BDwtrbUkrSnBQJBXuaJg9QBu3MYL0iuJPE8P30o0x7I=", + "lastModified": 1620801549, + "narHash": "sha256-8a5eqj6neVdRiBzF6xWEqwGWhlGBSgE65q9E6B+DDkA=", "owner": "divnix", "repo": "devlib", - "rev": "ffda6add9eb984d986cf5b6a838a52334317302f", + "rev": "738b9bd0b587b0dfb92206c1beb68f43adfdc234", "type": "github" }, "original": { @@ -141,11 +141,11 @@ }, "flake-utils": { "locked": { - "lastModified": 1619345332, - "narHash": "sha256-qHnQkEp1uklKTpx3MvKtY6xzgcqXDsz5nLilbbuL+3A=", + "lastModified": 1620759905, + "narHash": "sha256-WiyWawrgmyN0EdmiHyG2V+fqReiVi8bM9cRdMaKQOFg=", "owner": "numtide", "repo": "flake-utils", - "rev": "2ebf2558e5bf978c7fb8ea927dfaed8fefab2e28", + "rev": "b543720b25df6ffdfcf9227afafc5b8c1fabfae8", "type": "github" }, "original": { @@ -355,11 +355,11 @@ "flake-utils": "flake-utils" }, "locked": { - "lastModified": 1619714004, - "narHash": "sha256-xoP81rWAM2cVpEFrQv9sUEIvNxGXAg4UH9kBt83a5u4=", + "lastModified": 1620801141, + "narHash": "sha256-XPJ+/nP/s218E11R+4LJyvkrQXvdT3D6TzNjfWVYZnI=", "owner": "gytis-ivaskevicius", "repo": "flake-utils-plus", - "rev": "0642ac572a87a0beb78a7c6ddce1267aa5817d05", + "rev": "1a742047f3f7c97b22768ba7738ac5a01052099e", "type": "github" }, "original": { From 858e8546fe799ac42a23bec5701dbb93f23cc6fb Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Wed, 12 May 2021 08:17:40 -0700 Subject: [PATCH 82/91] flake: update devlib input includes ability to customize shell from template --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 4a98d121..b530dc77 100644 --- a/flake.lock +++ b/flake.lock @@ -79,11 +79,11 @@ "utils": "utils_2" }, "locked": { - "lastModified": 1620801549, - "narHash": "sha256-8a5eqj6neVdRiBzF6xWEqwGWhlGBSgE65q9E6B+DDkA=", + "lastModified": 1620832565, + "narHash": "sha256-6K+ZPoIQwaVP1hYER3PUxDxs4TTEilfQ+VoJWnEfd3Q=", "owner": "divnix", "repo": "devlib", - "rev": "738b9bd0b587b0dfb92206c1beb68f43adfdc234", + "rev": "454b01d875bb8a31bb3d669366462e7fd978b963", "type": "github" }, "original": { From 2b73d3bf53b35256faa30ad7dc3431ecbb78d634 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Wed, 12 May 2021 11:43:27 -0700 Subject: [PATCH 83/91] customBuilds: add TODO to drop builderArgs --- modules/customBuilds.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/customBuilds.nix b/modules/customBuilds.nix index b9648dca..59ae524e 100644 --- a/modules/customBuilds.nix +++ b/modules/customBuilds.nix @@ -1,6 +1,7 @@ { lib, self, devlib, config, modules, channel, ... }: let mkBuild = buildModule: + # TODO: get specialArgs as a module argument and drop builderArgs usage channel.input.lib.nixosSystem (devlib.mergeAny config.lib.builderArgs { modules = [ buildModule ]; }); From 3ee831f8529f123c66f94901accedff8ab5428e1 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Wed, 12 May 2021 12:29:00 -0700 Subject: [PATCH 84/91] flake.nix: explicitly append overlays from path Co-authored-by: David Arnold --- flake.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 90f84fcb..07055346 100644 --- a/flake.nix +++ b/flake.nix @@ -34,8 +34,9 @@ channels = { nixos = { - overlays = [ - (devlib.lib.pathsIn ./overlays) + overlays = + (devlib.lib.importers.pathsIn ./overlays) ++ + [ ./pkgs/default.nix pkgs.overlay # for `srcs` nur.overlay From 67f545123c994c96fe0752d7964e621c9178f2b7 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Wed, 12 May 2021 12:31:43 -0700 Subject: [PATCH 85/91] flake: format and update to devlib api changes --- flake.lock | 6 +++--- flake.nix | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/flake.lock b/flake.lock index b530dc77..c0807047 100644 --- a/flake.lock +++ b/flake.lock @@ -79,11 +79,11 @@ "utils": "utils_2" }, "locked": { - "lastModified": 1620832565, - "narHash": "sha256-6K+ZPoIQwaVP1hYER3PUxDxs4TTEilfQ+VoJWnEfd3Q=", + "lastModified": 1620845932, + "narHash": "sha256-ShC2IuJD1MHC0DtQWeUuWpD1HDL7cuK3oBWQmVqjmdk=", "owner": "divnix", "repo": "devlib", - "rev": "454b01d875bb8a31bb3d669366462e7fd978b963", + "rev": "5a04146dc08f0a15a4489babe584162fdde1ca1f", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 07055346..d8fd366a 100644 --- a/flake.nix +++ b/flake.nix @@ -37,10 +37,10 @@ overlays = (devlib.lib.importers.pathsIn ./overlays) ++ [ - ./pkgs/default.nix - pkgs.overlay # for `srcs` - nur.overlay - ]; + ./pkgs/default.nix + pkgs.overlay # for `srcs` + nur.overlay + ]; }; latest = { }; }; @@ -66,7 +66,7 @@ ]; }; hosts = nixos.lib.mkMerge [ - (devlib.lib.importHosts ./hosts) + (devlib.lib.importers.importHosts ./hosts) { /* set host specific properties here */ } ]; profiles = [ ./profiles ./users ]; From c89dfed81c37bde4ebe5db96f3b8db83f8eea672 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Wed, 12 May 2021 19:18:11 -0700 Subject: [PATCH 86/91] don't import cachix in suites its already imported in the core profile --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index d8fd366a..02ef12ae 100644 --- a/flake.nix +++ b/flake.nix @@ -71,7 +71,7 @@ ]; profiles = [ ./profiles ./users ]; suites = { profiles, users, ... }: with profiles; { - base = [ cachix core users.nixos users.root ]; + base = [ core users.nixos users.root ]; }; }; From 7793ab42da34c77d14f58226190c5949de133738 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Thu, 13 May 2021 16:59:52 -0700 Subject: [PATCH 87/91] flake: update devlib input includes nixos option improvements and importHosts change --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index c0807047..3e6b0f39 100644 --- a/flake.lock +++ b/flake.lock @@ -79,11 +79,11 @@ "utils": "utils_2" }, "locked": { - "lastModified": 1620845932, - "narHash": "sha256-ShC2IuJD1MHC0DtQWeUuWpD1HDL7cuK3oBWQmVqjmdk=", + "lastModified": 1620950194, + "narHash": "sha256-3fh8kUxZ/by7QP7vop+C+X6nj/YzYHnld9epGbRWKQ0=", "owner": "divnix", "repo": "devlib", - "rev": "5a04146dc08f0a15a4489babe584162fdde1ca1f", + "rev": "213afcefb2db0bb5fd3fad871303c43b158d8204", "type": "github" }, "original": { From ccc0fc97fe168e13d8c9cb7374f91e2b326a63d8 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Thu, 13 May 2021 17:03:51 -0700 Subject: [PATCH 88/91] flake.nix: use `imports` for auto-import of hosts This makes the auto-importing of hosts obvious and explicitly indicates how the options would end up getting merged. --- flake.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 02ef12ae..59d91552 100644 --- a/flake.nix +++ b/flake.nix @@ -65,10 +65,12 @@ ./modules/customBuilds.nix ]; }; - hosts = nixos.lib.mkMerge [ - (devlib.lib.importers.importHosts ./hosts) - { /* set host specific properties here */ } - ]; + + imports = [ (devlib.lib.importers.importHosts ./hosts) ]; + hosts = { + /* set host specific properties here */ + NixOS = { }; + }; profiles = [ ./profiles ./users ]; suites = { profiles, users, ... }: with profiles; { base = [ core users.nixos users.root ]; From 923ce7feff875706adb1d336fb959fbdb06b3f14 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 14 May 2021 10:17:53 -0700 Subject: [PATCH 89/91] tree: rename devlib -> digga --- flake.lock | 77 +++++++++++++++++++++++++++------------- flake.nix | 19 +++++----- modules/customBuilds.nix | 6 ++-- 3 files changed, 64 insertions(+), 38 deletions(-) diff --git a/flake.lock b/flake.lock index 3e6b0f39..a4e7fd6d 100644 --- a/flake.lock +++ b/flake.lock @@ -69,29 +69,6 @@ "type": "github" } }, - "devlib": { - "inputs": { - "deploy": "deploy", - "devshell": "devshell", - "nixpkgs": [ - "nixos" - ], - "utils": "utils_2" - }, - "locked": { - "lastModified": 1620950194, - "narHash": "sha256-3fh8kUxZ/by7QP7vop+C+X6nj/YzYHnld9epGbRWKQ0=", - "owner": "divnix", - "repo": "devlib", - "rev": "213afcefb2db0bb5fd3fad871303c43b158d8204", - "type": "github" - }, - "original": { - "owner": "divnix", - "repo": "devlib", - "type": "github" - } - }, "devshell": { "locked": { "lastModified": 1618523768, @@ -107,6 +84,28 @@ "type": "github" } }, + "digga": { + "inputs": { + "deploy": "deploy", + "devshell": "devshell", + "nixlib": "nixlib", + "nixpkgs": "nixpkgs_2", + "utils": "utils_2" + }, + "locked": { + "lastModified": 1621012625, + "narHash": "sha256-xRBbDpQDUz3mSwL2WoePz6c3zIUtZ2ML3qW0B9CVspU=", + "owner": "divnix", + "repo": "digga", + "rev": "b0de71f4924e513e21d21a0ec60a2cb180f2187c", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "digga", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { @@ -229,6 +228,21 @@ "type": "github" } }, + "nixlib": { + "locked": { + "lastModified": 1620519687, + "narHash": "sha256-+6Dd72b2CASuXm2W7KRxZIE7AOy/dj4mU28vaF+zxcs=", + "owner": "divnix", + "repo": "nixpkgs.lib", + "rev": "c7b6169809c5f74dd0c34f3d69e9d12ba4d448de", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "nixpkgs.lib", + "type": "github" + } + }, "nixos": { "locked": { "lastModified": 1615797423, @@ -275,6 +289,21 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1620962350, + "narHash": "sha256-9ASW4d4/Z8HmRvuJI8rxbEOTbXTBpQ8y+CmFYBwtXzE=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5d4a430472cafada97888cc80672fab255231f57", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, "nur": { "locked": { "lastModified": 1615921934, @@ -325,7 +354,7 @@ "inputs": { "ci-agent": "ci-agent", "darwin": "darwin", - "devlib": "devlib", + "digga": "digga", "home": "home", "latest": "latest", "naersk": "naersk_2", diff --git a/flake.nix b/flake.nix index 59d91552..212df343 100644 --- a/flake.nix +++ b/flake.nix @@ -5,10 +5,7 @@ { nixos.url = "nixpkgs/nixos-unstable"; latest.url = "nixpkgs"; - devlib.url = "github:divnix/devlib"; - devlib.inputs = { - nixpkgs.follows = "nixos"; - }; + digga.url = "github:divnix/digga"; ci-agent = { url = "github:hercules-ci/hercules-ci-agent"; @@ -26,8 +23,8 @@ pkgs.inputs.nixpkgs.follows = "nixos"; }; - outputs = inputs@{ self, pkgs, devlib, nixos, ci-agent, home, nixos-hardware, nur, ... }: - devlib.lib.mkFlake { + outputs = inputs@{ self, pkgs, digga, nixos, ci-agent, home, nixos-hardware, nur, ... }: + digga.lib.mkFlake { inherit self inputs; channelsConfig = { allowUnfree = true; }; @@ -35,7 +32,7 @@ channels = { nixos = { overlays = - (devlib.lib.importers.pathsIn ./overlays) ++ + (digga.lib.importers.pathsIn ./overlays) ++ [ ./pkgs/default.nix pkgs.overlay # for `srcs` @@ -45,7 +42,7 @@ latest = { }; }; - lib = import ./lib { lib = devlib.lib // nixos.lib; }; + lib = import ./lib { lib = digga.lib // nixos.lib; }; sharedOverlays = [ (final: prev: { @@ -66,7 +63,7 @@ ]; }; - imports = [ (devlib.lib.importers.importHosts ./hosts) ]; + imports = [ (digga.lib.importers.importHosts ./hosts) ]; hosts = { /* set host specific properties here */ NixOS = { }; @@ -86,9 +83,9 @@ }; }; - homeConfigurations = devlib.lib.mkHomeConfigurations self.nixosConfigurations; + homeConfigurations = digga.lib.mkHomeConfigurations self.nixosConfigurations; - deploy.nodes = devlib.lib.mkDeployNodes self.nixosConfigurations { }; + deploy.nodes = digga.lib.mkDeployNodes self.nixosConfigurations { }; #defaultTemplate = self.templates.flk; templates.flk.path = ./.; diff --git a/modules/customBuilds.nix b/modules/customBuilds.nix index 59ae524e..875d23a0 100644 --- a/modules/customBuilds.nix +++ b/modules/customBuilds.nix @@ -1,14 +1,14 @@ -{ lib, self, devlib, config, modules, channel, ... }: +{ lib, self, diggaLib, config, modules, channel, ... }: let mkBuild = buildModule: # TODO: get specialArgs as a module argument and drop builderArgs usage - channel.input.lib.nixosSystem (devlib.mergeAny config.lib.builderArgs { + channel.input.lib.nixosSystem (diggaLib.mergeAny config.lib.builderArgs { modules = [ buildModule ]; }); in { system.build = { - iso = (mkBuild (devlib.modules.isoConfig { + iso = (mkBuild (diggaLib.modules.isoConfig { inherit self; inherit (self) inputs; fullHostConfig = config; From dd6c481791cf38f5feb408253e40490ccd7d7716 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 14 May 2021 11:01:44 -0700 Subject: [PATCH 90/91] flake: format ourlib for consistency with digga --- flake.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 212df343..ffce39c9 100644 --- a/flake.nix +++ b/flake.nix @@ -46,7 +46,9 @@ sharedOverlays = [ (final: prev: { - ourlib = self.lib; + lib = prev.lib.extend (lfinal: lprev: { + our = self.lib; + }); }) ]; @@ -56,7 +58,7 @@ channelName = "nixos"; modules = ./modules/module-list.nix; externalModules = [ - { _module.args.ourlib = self.lib; } + { _module.args.ourLib = self.lib; } ci-agent.nixosModules.agent-profile home.nixosModules.home-manager ./modules/customBuilds.nix From 2f474e37f72121679a720445385aea677a7adadc Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 14 May 2021 16:49:12 -0700 Subject: [PATCH 91/91] flake: update to latest digga api allows overlays to also be used with `imports` and renames importHosts --- flake.lock | 6 +++--- flake.nix | 15 +++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/flake.lock b/flake.lock index a4e7fd6d..2195b9a2 100644 --- a/flake.lock +++ b/flake.lock @@ -93,11 +93,11 @@ "utils": "utils_2" }, "locked": { - "lastModified": 1621012625, - "narHash": "sha256-xRBbDpQDUz3mSwL2WoePz6c3zIUtZ2ML3qW0B9CVspU=", + "lastModified": 1621027569, + "narHash": "sha256-ugwMMfZagrWnt6yw+k1YGbydoMQ0OTYJ3WJ1kncsKCg=", "owner": "divnix", "repo": "digga", - "rev": "b0de71f4924e513e21d21a0ec60a2cb180f2187c", + "rev": "c162f5f46206346f431f3905642a8a9f17d42217", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index ffce39c9..6b6860f5 100644 --- a/flake.nix +++ b/flake.nix @@ -31,13 +31,12 @@ channels = { nixos = { - overlays = - (digga.lib.importers.pathsIn ./overlays) ++ - [ - ./pkgs/default.nix - pkgs.overlay # for `srcs` - nur.overlay - ]; + imports = [ (digga.lib.importers.overlays ./overlays) ]; + overlays = [ + ./pkgs/default.nix + pkgs.overlay # for `srcs` + nur.overlay + ]; }; latest = { }; }; @@ -65,7 +64,7 @@ ]; }; - imports = [ (digga.lib.importers.importHosts ./hosts) ]; + imports = [ (digga.lib.importers.hosts ./hosts) ]; hosts = { /* set host specific properties here */ NixOS = { };