config: update image generation step

It doesn't allow setting up system modularly so we'll have to do this
on our own which is easy enough since it's already done once.
This commit is contained in:
Gabriel Arazas 2023-12-24 18:11:57 +08:00
parent d55865beb0
commit c1d8be29b0
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
2 changed files with 19 additions and 8 deletions

View File

@ -315,6 +315,7 @@
# A function that generates a Nix module from host metadata. # A function that generates a Nix module from host metadata.
hostSpecificModule = host: metadata: let hostSpecificModule = host: metadata: let
modules = metadata.modules or []; modules = metadata.modules or [];
host = metadata._name or host;
in in
{ lib, ... }: { { lib, ... }: {
imports = modules ++ [ imports = modules ++ [
@ -421,18 +422,17 @@
images = images =
forAllSystems (system: forAllSystems (system:
let let
images' = lib.filterAttrs (host: metadata: system == metadata._system) (listImagesWithSystems images); images' = lib.filterAttrs (host: metadata: (system == metadata._system) && (metadata.format != null)) (listImagesWithSystems images);
in in
lib.mapAttrs' lib.mapAttrs'
(host: metadata: (host: metadata:
let let
name = metadata._name; name = metadata._name;
nixpkgs-channel = metadata.nixpkgs-channel or "nixpkgs"; nixpkgs-channel = metadata.nixpkgs-channel or "nixpkgs";
pkgs = import inputs.${nixpkgs-channel} {};
format = metadata.format or "iso"; format = metadata.format or "iso";
in in
lib.nameValuePair name (mkImage { lib.nameValuePair name (mkImage {
inherit format pkgs; inherit nixpkgs-channel format;
extraModules = [ (hostSpecificModule host metadata) ]; extraModules = [ (hostSpecificModule host metadata) ];
})) }))
images'); images');

View File

@ -39,12 +39,23 @@ in
}; };
# A thin wrapper around the nixos-generators `nixosGenerate` function. # A thin wrapper around the nixos-generators `nixosGenerate` function.
mkImage = { pkgs ? null, extraModules ? [ ], format ? "iso" }: mkImage = { nixpkgs-channel ? "nixpkgs", extraModules ? [ ], format ? "iso" }: let
inputs.nixos-generators.nixosGenerate { nixpkgs = inputs.${nixpkgs-channel};
inherit pkgs format;
lib = pkgs.lib.extend extendLib; # A modified version of `nixosSystem` from nixpkgs flake similar to the
modules = extraModules; # one found in mkHost.
nixosSystem = args: import "${nixpkgs}/nixos/lib/eval-config.nix" args;
image = nixosSystem {
lib = nixpkgs.lib.extend extendLib;
modules = extraModules ++ [ inputs.nixos-generators.nixosModules.${format} ];
# We're also setting this up modularly so we'll have to pass these as
# null.
system = null;
}; };
in
image.config.system.build.${image.config.formatAttr};
# A function to modify the given table of declarative setups (i.e., hosts, # A function to modify the given table of declarative setups (i.e., hosts,
# users) to have its own system attribute and its name. # users) to have its own system attribute and its name.