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.lock | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 21 ++++++++++++++---- installer.nix | 1 + 3 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 flake.lock create mode 100644 installer.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..2a0a02da --- /dev/null +++ b/flake.lock @@ -0,0 +1,71 @@ +{ + "nodes": { + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1618469593, + "narHash": "sha256-fNdt+Q3irnT3pId7PKSSVeR8/9inBrAEg4gpItoRowU=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "ebbbd4f2b50703409543941e7445138dc1e7392e", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "master", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1618681372, + "narHash": "sha256-fjiabnBl20D/jc3bU3K16jP21bf5l2fG1rHij0LoHVk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c27aea5e879748c79acf3b6681194fcf184e3eba", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "master", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager", + "nixpkgs": "nixpkgs", + "sops-nix": "sops-nix" + } + }, + "sops-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1618226608, + "narHash": "sha256-Hq/lcu48RhE3U6gYYkuT7v6hLHeu1PrasiaBiGkCX+w=", + "owner": "Mic92", + "repo": "sops-nix", + "rev": "ade2f5c17184df9d4c42d36da18a6ed903b4c02d", + "type": "github" + }, + "original": { + "owner": "Mic92", + "ref": "master", + "repo": "sops-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} 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; } diff --git a/installer.nix b/installer.nix new file mode 100644 index 00000000..64629674 --- /dev/null +++ b/installer.nix @@ -0,0 +1 @@ +{...}: {} -- cgit v1.2.3