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.
hostSpecificModule = host: metadata: let
modules = metadata.modules or [];
host = metadata._name or host;
in
{ lib, ... }: {
imports = modules ++ [
@ -421,18 +422,17 @@
images =
forAllSystems (system:
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
lib.mapAttrs'
(host: metadata:
let
name = metadata._name;
nixpkgs-channel = metadata.nixpkgs-channel or "nixpkgs";
pkgs = import inputs.${nixpkgs-channel} {};
format = metadata.format or "iso";
in
lib.nameValuePair name (mkImage {
inherit format pkgs;
inherit nixpkgs-channel format;
extraModules = [ (hostSpecificModule host metadata) ];
}))
images');

View File

@ -39,12 +39,23 @@ in
};
# A thin wrapper around the nixos-generators `nixosGenerate` function.
mkImage = { pkgs ? null, extraModules ? [ ], format ? "iso" }:
inputs.nixos-generators.nixosGenerate {
inherit pkgs format;
lib = pkgs.lib.extend extendLib;
modules = extraModules;
mkImage = { nixpkgs-channel ? "nixpkgs", extraModules ? [ ], format ? "iso" }: let
nixpkgs = inputs.${nixpkgs-channel};
# A modified version of `nixosSystem` from nixpkgs flake similar to the
# 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,
# users) to have its own system attribute and its name.