From 989d80d2da3d7a71b1a7af9d6cab9a162ae04229 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 15 May 2021 22:13:55 +0200 Subject: fix root account on installers --- flake.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index e2567e84..ea3d0747 100644 --- a/flake.nix +++ b/flake.nix @@ -26,11 +26,11 @@ outputs = { self, nixpkgs, home-manager, sops-nix }@inputs: let - inherit (builtins) attrNames attrValues elemAt toJSON; + inherit (builtins) attrNames attrValues elemAt toJSON isNull pathExists; inherit (nixpkgs) lib; utils = import ./utils { inherit lib; }; inherit (utils) recImport overrideModule; - inherit (lib) nixosSystem mkIf splitString filterAttrs listToAttrs mapAttrsToList nameValuePair concatMap composeManyExtensions mapAttrs mapAttrs' recursiveUpdate genAttrs unique elem; + inherit (lib) nixosSystem mkIf splitString filterAttrs listToAttrs mapAttrsToList nameValuePair concatMap composeManyExtensions mapAttrs mapAttrs' recursiveUpdate genAttrs unique elem optionalAttrs; accountUserName = accountName: let @@ -118,11 +118,11 @@ netboot = { path = "nixos/modules/installer/netboot/netboot-minimal.nix"; output = out: (self.legacyPackages.${system}.symlinkJoin { name = "netboot"; paths = with out.config.system.build; [ netbootRamdisk kernel netbootIpxeScript ]; preferLocalBuild = true; }); }; }; + installerConfig = if pathExists ./installer.nix then "installer.nix" else (if pathExists ./installer then "installer" else null); installers = let mkInstallers = system: mapAttrs (mkInstaller system) (installerProfiles system); mkInstaller = system: name: {profile, output}: output (mkNixosConfiguration [profile { config = { nixpkgs.system = system; }; }] ./. installerConfig "installer"); - installerConfig = if builtins.pathExists ./installer.nix then "installer.nix" else (if builtins.pathExists ./installer then "installer" else null); - in if !(builtins.isNull installerConfig) then { installers = forAllSystems (system: _systemPkgs: mkInstallers system); } else {}; + in if !(isNull installerConfig) then { installers = forAllSystems (system: _systemPkgs: mkInstallers system); } else {}; in { nixosModules = @@ -133,7 +133,7 @@ accounts = recursiveUpdate rootAccounts (recImport rec { dir = ./accounts; _import = mkAccountModule dir; }); rootAccounts = mapAttrs' (hostName: _value: nameValuePair "root@${hostName}" ({...}: { imports = [ self.nixosModules.users.root or ({...}: { imports = defaultUserProfiles "root"; }) ]; })) self.nixosConfigurations; in modulesAttrs // { inherit systemProfiles users userProfiles accounts; }; - nixosConfigurations = recImport rec { dir = ./hosts; _import = mkNixosConfiguration [] dir; }; + nixosConfigurations = optionalAttrs (!(isNull installerConfig)) { installer = installerConfig; } // recImport rec { dir = ./hosts; _import = mkNixosConfiguration [] dir; }; homeManagerModules = recImport rec { dir = ./home-modules; }; -- cgit v1.2.3 From 3e5346ccfd542e9abb928a7eca2e831b9c30df2e Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 15 May 2021 22:15:06 +0200 Subject: better name nixImport --- flake.nix | 18 +++++++++--------- utils/default.nix | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index ea3d0747..d8684703 100644 --- a/flake.nix +++ b/flake.nix @@ -29,7 +29,7 @@ inherit (builtins) attrNames attrValues elemAt toJSON isNull pathExists; inherit (nixpkgs) lib; utils = import ./utils { inherit lib; }; - inherit (utils) recImport overrideModule; + inherit (utils) nixImport overrideModule; inherit (lib) nixosSystem mkIf splitString filterAttrs listToAttrs mapAttrsToList nameValuePair concatMap composeManyExtensions mapAttrs mapAttrs' recursiveUpdate genAttrs unique elem optionalAttrs; accountUserName = accountName: @@ -109,7 +109,7 @@ activateNixosConfigurations = forAllSystems (system: _pkgs: mapAttrs' (hostName: nixosConfig: nameValuePair "${hostName}-activate" { type = "app"; program = "${nixosConfig.config.system.build.toplevel}/bin/switch-to-configuration"; }) self.nixosConfigurations); - overlayPaths = recImport rec { dir = ./overlays; _import = (path: _name: dir + "/${path}"); } // { pkgs = ./pkgs; }; + overlayPaths = nixImport rec { dir = ./overlays; _import = (path: _name: dir + "/${path}"); } // { pkgs = ./pkgs; }; installerProfiles = system: let nixpkgs-path = nixpkgs.legacyPackages.${system}.path; @@ -126,16 +126,16 @@ in { nixosModules = - let modulesAttrs = recImport { dir = ./modules; }; - systemProfiles = recImport rec { dir = ./system-profiles; _import = mkSystemProfile dir; }; - users = recImport rec { dir = ./users; _import = mkUserModule dir; }; - userProfiles = forAllUsers (userName: recImport rec { dir = ./user-profiles; _import = mkUserProfile userName dir; }); - accounts = recursiveUpdate rootAccounts (recImport rec { dir = ./accounts; _import = mkAccountModule dir; }); + let modulesAttrs = nixImport { dir = ./modules; }; + systemProfiles = nixImport rec { dir = ./system-profiles; _import = mkSystemProfile dir; }; + users = nixImport rec { dir = ./users; _import = mkUserModule dir; }; + userProfiles = forAllUsers (userName: nixImport rec { dir = ./user-profiles; _import = mkUserProfile userName dir; }); + accounts = recursiveUpdate rootAccounts (nixImport rec { dir = ./accounts; _import = mkAccountModule dir; }); rootAccounts = mapAttrs' (hostName: _value: nameValuePair "root@${hostName}" ({...}: { imports = [ self.nixosModules.users.root or ({...}: { imports = defaultUserProfiles "root"; }) ]; })) self.nixosConfigurations; in modulesAttrs // { inherit systemProfiles users userProfiles accounts; }; - nixosConfigurations = optionalAttrs (!(isNull installerConfig)) { installer = installerConfig; } // recImport rec { dir = ./hosts; _import = mkNixosConfiguration [] dir; }; + nixosConfigurations = optionalAttrs (!(isNull installerConfig)) { installer = installerConfig; } // nixImport rec { dir = ./hosts; _import = mkNixosConfiguration [] dir; }; - homeManagerModules = recImport rec { dir = ./home-modules; }; + homeManagerModules = nixImport rec { dir = ./home-modules; }; overlay = import overlayPaths.pkgs; overlays = mapAttrs (_name: path: import path) overlayPaths; diff --git a/utils/default.nix b/utils/default.nix index d00357af..48add212 100644 --- a/utils/default.nix +++ b/utils/default.nix @@ -3,7 +3,7 @@ rec { inherit (builtins) readDir; inherit (lib) filterAttrs hasSuffix removeSuffix mapAttrs' nameValuePair isFunction functionArgs setFunctionArgs id; mapFilterAttrs = seive: f: attrs: filterAttrs seive (mapAttrs' f attrs); - recImport = { dir, _import ? name: _base: import "${toString dir}/${name}" }: + nixImport = { dir, _import ? name: _base: import "${toString dir}/${name}" }: mapFilterAttrs (_: v: v != null) (n: v: -- cgit v1.2.3