From 8ab865a85390a7746c0d759d63a0f60e3f87ac61 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 23 Mar 2021 12:05:30 -0700 Subject: [PATCH 1/6] lib/mkProfileAttrs: don't change to path store paths can't be appended to a path --- lib/devos/mkProfileAttrs.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/devos/mkProfileAttrs.nix b/lib/devos/mkProfileAttrs.nix index b502629b..214df261 100644 --- a/lib/devos/mkProfileAttrs.nix +++ b/lib/devos/mkProfileAttrs.nix @@ -27,7 +27,7 @@ let mkProfileAttrs = f = n: _: lib.optionalAttrs (lib.pathExists "${dir}/${n}/default.nix") - { default = /. + "${dir}/${n}"; } + { default = "${dir}/${n}"; } // mkProfileAttrs "${dir}/${n}"; in lib.mapAttrs f imports; From 7ebd6b57301deb391565e22060292af2600244b5 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 20 Mar 2021 09:36:14 -0700 Subject: [PATCH 2/6] move suites implementation logic to lib as mkSuites --- lib/devos/default.nix | 2 ++ lib/devos/mkSuites.nix | 24 ++++++++++++++++++++++++ suites/default.nix | 33 ++++----------------------------- 3 files changed, 30 insertions(+), 29 deletions(-) create mode 100644 lib/devos/mkSuites.nix diff --git a/lib/devos/default.nix b/lib/devos/default.nix index bf109ba3..ce48824c 100644 --- a/lib/devos/default.nix +++ b/lib/devos/default.nix @@ -11,6 +11,8 @@ mkNodes = dev.callLibs ./mkNodes.nix; + mkSuites = dev.callLibs ./mkSuites.nix; + mkProfileAttrs = dev.callLibs ./mkProfileAttrs.nix; mkPkgs = dev.callLibs ./mkPkgs.nix; diff --git a/lib/devos/mkSuites.nix b/lib/devos/mkSuites.nix new file mode 100644 index 00000000..a3a32944 --- /dev/null +++ b/lib/devos/mkSuites.nix @@ -0,0 +1,24 @@ +{ lib, dev, ... }: + +{ users, profiles, userProfiles, suites } @ args: +let + inherit (dev) os; + + definedSuites = suites { + inherit (args) users profiles userProfiles; + }; + + allProfiles = + let defaults = lib.collect (x: x ? default) profiles; + in map (x: x.default) defaults; + + allUsers = + let defaults = lib.collect (x: x ? default) users; + in map (x: x.default) defaults; + + createSuites = _: suites: lib.mapAttrs (_: v: os.profileMap v) suites // { + inherit allProfiles allUsers; + }; + +in +lib.mapAttrs createSuites definedSuites diff --git a/suites/default.nix b/suites/default.nix index e1b7d668..4a65b55d 100644 --- a/suites/default.nix +++ b/suites/default.nix @@ -1,35 +1,10 @@ -{ lib }: -let - inherit (lib) dev; +{ users, profiles, userProfiles, ... }: - profiles = dev.os.mkProfileAttrs (toString ../profiles); - userProfiles = dev.os.mkProfileAttrs (toString ../users/profiles); - users = dev.os.mkProfileAttrs (toString ../users); - - allProfiles = - let defaults = lib.collect (x: x ? default) profiles; - in map (x: x.default) defaults; - - allUsers = - let defaults = lib.collect (x: x ? default) users; - in map (x: x.default) defaults; - - - suites = with profiles; rec { +{ + system = with profiles; rec { base = [ users.nixos users.root ]; }; - - # available as 'suites' within the home-manager configuration - userSuites = with userProfiles; rec { + user = with userProfiles; rec { base = [ direnv git ]; }; - -in -{ - system = lib.mapAttrs (_: v: dev.os.profileMap v) suites // { - inherit allProfiles allUsers; - }; - user = lib.mapAttrs (_: v: dev.os.profileMap v) userSuites // { - allProfiles = userProfiles; - }; } From ec7eff63eb859325750297a8d525fe5883f51bda Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 20 Mar 2021 09:37:03 -0700 Subject: [PATCH 3/6] move hosts implementation logic to lib as mkHosts --- lib/devos/default.nix | 2 ++ hosts/default.nix => lib/devos/mkHosts.nix | 30 ++++++++-------------- 2 files changed, 12 insertions(+), 20 deletions(-) rename hosts/default.nix => lib/devos/mkHosts.nix (85%) diff --git a/lib/devos/default.nix b/lib/devos/default.nix index ce48824c..e580ef00 100644 --- a/lib/devos/default.nix +++ b/lib/devos/default.nix @@ -11,6 +11,8 @@ mkNodes = dev.callLibs ./mkNodes.nix; + mkHosts = dev.callLibs ./mkHosts.nix; + mkSuites = dev.callLibs ./mkSuites.nix; mkProfileAttrs = dev.callLibs ./mkProfileAttrs.nix; diff --git a/hosts/default.nix b/lib/devos/mkHosts.nix similarity index 85% rename from hosts/default.nix rename to lib/devos/mkHosts.nix index 2a874e86..1d1bfce0 100644 --- a/hosts/default.nix +++ b/lib/devos/mkHosts.nix @@ -1,17 +1,8 @@ -{ extern -, home -, lib -, nixos -, override -, multiPkgs -, self -, defaultSystem -, ... -}: -let - inherit (lib) dev; +{ lib, dev, nixos, inputs, self, ... }: - suites = import ../suites { inherit lib; }; +{ dir, extern, suites, overrides, multiPkgs, ... }: +let + defaultSystem = "x86_64-linux"; experimentalFeatures = [ "flakes" @@ -21,10 +12,9 @@ let ]; modules = { - core = ../profiles/core; + core = "${self}/profiles/core"; modOverrides = { config, overrideModulesPath, ... }: let - overrides = import ../overrides; inherit (overrides) modules disabledModules; in { @@ -48,7 +38,7 @@ let nix.nixPath = [ "nixpkgs=${nixos}" "nixos-config=${self}/compat/nixos" - "home-manager=${home}" + "home-manager=${inputs.home}" ]; nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; @@ -56,7 +46,7 @@ let nix.registry = { devos.flake = self; nixos.flake = nixos; - override.flake = override; + override.flake = inputs.override; }; nix.extraOptions = '' @@ -71,7 +61,7 @@ let # Everything in `./modules/list.nix`. flakeModules = { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; - cachix = ../cachix.nix; + cachix = ../../cachix.nix; }; specialArgs = extern.specialArgs // { suites = suites.system; }; @@ -80,7 +70,7 @@ let let local = { require = [ - "${toString ./.}/${hostName}.nix" + "${dir}/${hostName}.nix" ]; networking = { inherit hostName; }; @@ -106,7 +96,7 @@ let hosts = dev.os.recImport { - dir = ./.; + inherit dir; _import = mkHostConfig; }; in From 92700888b7a0089fb21a2d2c5cfe5a3f18f01f48 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 26 Mar 2021 08:38:42 -0700 Subject: [PATCH 4/6] flake: update to use mkSuites and mkHosts --- flake.nix | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/flake.nix b/flake.nix index 6c6e0a75..2af75209 100644 --- a/flake.nix +++ b/flake.nix @@ -40,15 +40,19 @@ inherit extern overrides; }; + suites = os.mkSuites { + suites = import ./suites; + users = os.mkProfileAttrs "${self}/users"; + profiles = os.mkProfileAttrs "${self}/profiles"; + userProfiles = os.mkProfileAttrs "${self}/users/profiles"; + }; + outputs = { - nixosConfigurations = - import ./hosts (nixos.lib.recursiveUpdate inputs { - inherit multiPkgs extern; - defaultSystem = "x86_64-linux"; - lib = nixos.lib.extend (final: prev: { - dev = self.lib; - }); - }); + nixosConfigurations = os.mkHosts { + dir = "${self}/hosts"; + overrides = import ./overrides; + inherit multiPkgs suites extern; + }; homeConfigurations = os.mkHomeConfigurations; From 259ec11d92633b417602c89082de49af77da260f Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 28 Mar 2021 15:05:47 -0700 Subject: [PATCH 5/6] tests: init testSuites to test suites and profile processing --- tests/lib.nix | 20 ++++++++++++++++++++ tests/profiles/foo/default.nix | 3 +++ tests/profiles/t/default.nix | 0 3 files changed, 23 insertions(+) create mode 100644 tests/profiles/foo/default.nix create mode 100644 tests/profiles/t/default.nix diff --git a/tests/lib.nix b/tests/lib.nix index 65559f8d..3b181ccb 100644 --- a/tests/lib.nix +++ b/tests/lib.nix @@ -66,4 +66,24 @@ lib.runTests { (rgxToString "a?" "a" == "a") (rgxToString "hat" "foohatbar" == "hat") ]; + + 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/tests/profiles/foo/default.nix b/tests/profiles/foo/default.nix new file mode 100644 index 00000000..2181e561 --- /dev/null +++ b/tests/profiles/foo/default.nix @@ -0,0 +1,3 @@ +{ + bar = 5; +} diff --git a/tests/profiles/t/default.nix b/tests/profiles/t/default.nix new file mode 100644 index 00000000..e69de29b From 7650526407a2fe5f8ee326c090d74c3047b728fd Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 29 Mar 2021 09:54:02 -0700 Subject: [PATCH 6/6] isoConfig: fix disabling profiles convert each to a list which doesn't get appended to modulesPath --- lib/devos/devosSystem.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index 99c217b3..b0f53fd8 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -18,7 +18,10 @@ lib.nixosSystem (args // { ({ config, suites, ... }: { # avoid unwanted systemd service startups - disabledModules = lib.remove modules.core suites.allProfiles; + # 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); nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs;