From df02e465133be72aafbb083c16d80188cc8f1b13 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 17 Apr 2021 20:32:02 +0200 Subject: support for building installers --- flake.nix | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix index 3c1507dd..e2567e84 100644 --- a/flake.nix +++ b/flake.nix @@ -41,7 +41,7 @@ accountName' = splitString "@" accountName; in elemAt accountName' 1; - mkNixosConfiguration = dir: path: hostName: nixosSystem rec { + mkNixosConfiguration = addProfiles: dir: path: hostName: nixosSystem rec { specialArgs = { flake = self; flakeInputs = inputs; @@ -60,7 +60,7 @@ }; accountModules = attrValues (filterAttrs accountMatchesHost self.nixosModules.accounts); accountMatchesHost = n: _v: accountHostName n == hostName; - in attrValues (filterAttrs (n: _v: !(elem n ["systemProfiles" "users" "userProfiles" "accounts"])) self.nixosModules) ++ [ argsModule ] ++ defaultProfiles ++ [ local ] ++ accountModules; + in attrValues (filterAttrs (n: _v: !(elem n ["systemProfiles" "users" "userProfiles" "accounts"])) self.nixosModules) ++ [ argsModule ] ++ defaultProfiles ++ addProfiles ++ [ local ] ++ accountModules; }; mkSystemProfile = dir: path: profileName: { @@ -110,6 +110,19 @@ 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; }; + + installerProfiles = system: + let nixpkgs-path = nixpkgs.legacyPackages.${system}.path; + in mapAttrs (name: {path, output}: { profile = mkSystemProfile nixpkgs-path path "installer-${name}"; inherit output; }) + { cd-dvd = { path = "nixos/modules/installer/cd-dvd/installation-cd-minimal.nix"; output = out: out.config.system.build.isoImage; }; + 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; }); }; + }; + + 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 { nixosModules = @@ -120,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 = recImport rec { dir = ./hosts; _import = mkNixosConfiguration [] dir; }; homeManagerModules = recImport rec { dir = ./home-modules; }; @@ -142,5 +155,5 @@ path = ./.; description = "GKleen's flakey nixos configuration"; }; - }; + } // installers; } -- cgit v1.2.3