2024-10-01 10:02:01 +02:00
|
|
|
/**
|
|
|
|
Convert a NixOS configuration to one for a minimal installer ISO
|
|
|
|
|
|
|
|
WARNING: Running this installer will format the target disk!
|
|
|
|
*/
|
2024-11-07 18:36:43 +01:00
|
|
|
|
2024-11-08 17:03:07 +01:00
|
|
|
{ nixpkgs,
|
|
|
|
hostKeys ? {}
|
|
|
|
}:
|
2024-11-07 18:36:43 +01:00
|
|
|
machine:
|
|
|
|
|
|
|
|
let
|
2024-11-08 17:03:07 +01:00
|
|
|
inherit (builtins) concatStringsSep attrValues mapAttrs;
|
|
|
|
|
2024-11-07 18:36:43 +01:00
|
|
|
installer = { config, pkgs, lib, ... }:
|
|
|
|
let
|
|
|
|
bootstrap = pkgs.writeShellApplication {
|
|
|
|
name = "bootstrap";
|
|
|
|
runtimeInputs = with pkgs; [ nixos-install-tools ];
|
|
|
|
text = ''
|
|
|
|
${machine.config.system.build.diskoScript}
|
2024-11-08 17:03:07 +01:00
|
|
|
nixos-install --no-root-password --no-channel-copy --system ${machine.config.system.build.toplevel}
|
|
|
|
${
|
|
|
|
concatStringsSep "\n" (
|
|
|
|
attrValues (
|
|
|
|
mapAttrs
|
|
|
|
(kind: keys: ''
|
|
|
|
cp ${keys.private} /mnt/etc/ssh/ssh_host_${kind}_key
|
|
|
|
chmod 600 /mnt/etc/ssh/ssh_host_${kind}_key
|
|
|
|
cp ${keys.public} /mnt/etc/ssh/ssh_host_${kind}_key.pub
|
|
|
|
chmod 644 /mnt/etc/ssh/ssh_host_${kind}_key.pub
|
|
|
|
'')
|
|
|
|
hostKeys
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
poweroff
|
2024-11-07 18:36:43 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
2024-10-01 10:02:01 +02:00
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
"${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix"
|
|
|
|
];
|
|
|
|
nixpkgs.hostPlatform = "x86_64-linux";
|
|
|
|
services.getty.autologinUser = lib.mkForce "root";
|
2024-11-07 18:36:43 +01:00
|
|
|
programs.bash.loginShellInit = nixpkgs.lib.getExe bootstrap;
|
2024-10-01 10:02:01 +02:00
|
|
|
|
|
|
|
isoImage = {
|
|
|
|
compressImage = false;
|
2024-10-01 13:29:06 +02:00
|
|
|
squashfsCompression = "lz4";
|
2024-10-01 10:02:01 +02:00
|
|
|
isoName = lib.mkForce "installer.iso";
|
2024-10-01 13:29:06 +02:00
|
|
|
## ^^ FIXME: Use a more interesting name or keep the default name and
|
|
|
|
## use `isoImage.isoName` in the tests.
|
2024-10-01 10:02:01 +02:00
|
|
|
};
|
|
|
|
};
|
2024-11-07 18:36:43 +01:00
|
|
|
in
|
|
|
|
(nixpkgs.lib.nixosSystem { modules = [installer]; }).config.system.build.isoImage
|