Dustin Frisch
1 month ago
No known key found for this signature in database
GPG Key ID: B4C3BF012D9B26BE
5 changed files with 105 additions and 141 deletions
-
81installer.nix
-
86installer/default.nix
-
19installer/installer.nix
-
22machines/nfs/dhcp.nix
-
38machines/nfs/netinstaller.nix
@ -0,0 +1,81 @@ |
|||
{ pkgs, lib, modulesPath, config, ... }: |
|||
|
|||
with lib; |
|||
|
|||
let |
|||
auto-installer = pkgs.writers.writeBash "auto-installer" '' |
|||
set -o errexit |
|||
set -o nounset |
|||
set -o pipefail |
|||
|
|||
set -x |
|||
|
|||
if [[ "$(cat /proc/cmdline)" =~ nixos\.install=([^ ]+) ]]; then |
|||
INSTALL="''${BASH_REMATCH[1]}" |
|||
else |
|||
echo "No install derivation found" >&2 |
|||
exit 1 |
|||
fi |
|||
|
|||
${pkgs.retry}/bin/retry \ |
|||
--times 10 \ |
|||
--delay 15 \ |
|||
-- ${pkgs.nix}/bin/nix-store \ |
|||
--realize \ |
|||
--add-root /tmp/installer \ |
|||
"$INSTALL" |
|||
|
|||
exec /tmp/installer |
|||
''; |
|||
|
|||
in |
|||
{ |
|||
imports = [ |
|||
"${modulesPath}/installer/netboot/netboot-minimal.nix" |
|||
|
|||
./shared/network.nix |
|||
./shared/cache.nix |
|||
./shared/users.nix |
|||
]; |
|||
|
|||
_module.args = { |
|||
name = "installer"; |
|||
}; |
|||
|
|||
networking.useDHCP = mkForce true; |
|||
|
|||
services.getty.autologinUser = lib.mkForce "root"; |
|||
|
|||
systemd.services."auto-install" = { |
|||
description = "Automated NixOS installer"; |
|||
|
|||
wants = [ "network-online.target" ]; |
|||
after = [ "network-online.target" ]; |
|||
|
|||
conflicts = [ "getty@tty1.service" ]; |
|||
|
|||
wantedBy = [ "multi-user.target" ]; |
|||
|
|||
path = with pkgs; [ bash nix ]; |
|||
|
|||
unitConfig = { |
|||
AssertKernelCommandLine = "nixos.install"; |
|||
|
|||
FailureAction = "force-reboot"; |
|||
}; |
|||
|
|||
serviceConfig = { |
|||
Type = "oneshot"; |
|||
|
|||
ExecStart = auto-installer; |
|||
|
|||
StandardInput = "none"; |
|||
StandardOutput = "journal+console"; |
|||
StandardError = "journal+console"; |
|||
}; |
|||
}; |
|||
|
|||
# Expose the installer script |
|||
system.build.installer = installer; |
|||
} |
|||
|
@ -1,86 +0,0 @@ |
|||
{ pkgs, lib, modulesPath, config, target, ... }: |
|||
|
|||
with lib; |
|||
|
|||
let |
|||
installer = pkgs.callPackage ./installer.nix { inherit target; }; |
|||
|
|||
auto-installer = |
|||
let |
|||
# This removes the direct dependency from the installer to the target image. |
|||
# The install script is realized later during runtime using the cache. |
|||
# To make this work, the cache must provide the real installer script. |
|||
installer-path = builtins.unsafeDiscardStringContext (toString installer); |
|||
|
|||
in |
|||
pkgs.writers.writeBash "auto-installer" '' |
|||
set -o errexit |
|||
set -o nounset |
|||
set -o pipefail |
|||
|
|||
set -x |
|||
|
|||
${pkgs.retry}/bin/retry \ |
|||
--times 10 \ |
|||
--delay 15 \ |
|||
-- ${pkgs.nix}/bin/nix-store \ |
|||
--realize \ |
|||
--add-root /tmp/installer \ |
|||
"${installer-path}" |
|||
|
|||
/tmp/installer |
|||
|
|||
reboot |
|||
''; |
|||
|
|||
in |
|||
{ |
|||
imports = [ |
|||
"${modulesPath}/installer/netboot/netboot-minimal.nix" |
|||
|
|||
../shared/users.nix |
|||
../shared/network.nix |
|||
../shared/cache.nix |
|||
]; |
|||
|
|||
_module.args = { |
|||
name = "installer"; |
|||
}; |
|||
|
|||
networking.useDHCP = mkForce true; |
|||
|
|||
services.getty.autologinUser = lib.mkForce "root"; |
|||
|
|||
systemd.services."auto-install" = { |
|||
description = "Automated NixOS installer"; |
|||
|
|||
wants = [ "network-online.target" ]; |
|||
after = [ "network-online.target" ]; |
|||
|
|||
conflicts = [ "getty@tty1.service" ]; |
|||
|
|||
wantedBy = [ "multi-user.target" ]; |
|||
|
|||
path = with pkgs; [ bash nix ]; |
|||
|
|||
unitConfig = { |
|||
FailureAction = "force-reboot"; |
|||
}; |
|||
|
|||
serviceConfig = { |
|||
Type = "oneshot"; |
|||
|
|||
ExecStart = auto-installer; |
|||
|
|||
StandardInput = "none"; |
|||
StandardOutput = "journal+console"; |
|||
StandardError = "journal+console"; |
|||
}; |
|||
}; |
|||
|
|||
# Expose the installer script |
|||
system.build.installer = installer; |
|||
|
|||
system.stateVersion = config.system.nixos.release; |
|||
} |
|||
|
@ -1,19 +0,0 @@ |
|||
{ writers, target, ... }: |
|||
|
|||
writers.writeBash "installer" '' |
|||
set -o errexit |
|||
set -o nounset |
|||
set -o pipefail |
|||
|
|||
set -x |
|||
|
|||
"${target.config.system.build.diskoScript}" |
|||
|
|||
"${target.config.system.build.nixos-install}/bin/nixos-install" \ |
|||
--root /mnt \ |
|||
--system "${target.config.system.build.toplevel}" \ |
|||
--no-channel-copy \ |
|||
--no-root-password \ |
|||
--verbose |
|||
'' |
|||
|
Reference in new issue
xxxxxxxxxx