depot/ops/nixos/installcd/default.nix

82 lines
2 KiB
Nix

# SPDX-FileCopyrightText: 2024 Luke Granger-Brown <depot@lukegb.com>
#
# SPDX-License-Identifier: Apache-2.0
{ depot, lib, pkgs, config, ... }:
let
inherit (depot.ops) secrets;
systems = [ "netcup-nue01" "netcup-ams01" ];
depot-install = pkgs.writeShellApplication {
name = "depot-install";
text = ''
# SPDX-FileCopyrightText: 2024 Luke Granger-Brown <depot@lukegb.com>
#
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
if [ $EUID -ne 0 ]; then
exec sudo "$0" "$@"
fi
targethostname="$1"
readonly targethostname
${lib.concatMapStringsSep "\n" (x: ''
if [[ "$targethostname" == "${x}" ]]; then
system="${depot.ops.nixos.systems.${x}}"
fi
'') systems}
if [[ -z "''${system+.}" ]]; then
echo "no system found :( - pick one of ${lib.concatStringsSep " " systems}" >&2
exit 1
fi
if [[ -z "''${DONT_DISKO+.}" ]]; then
"disko-$targethostname"
fi
exec nixos-install \
--root /mnt \
--system "$system" \
--option builders "" \
--option substituters "" \
--option download-attempts 0 \
--option connect-timeout 1 \
--no-root-passwd --no-channel-copy
'';
};
diskos = pkgs.stdenvNoCC.mkDerivation {
name = "diskos";
dontUnpack = true;
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir $out/bin -p
${lib.concatMapStringsSep "\n" (x: ''
ln -s "${depot.ops.nixos.systemConfigs.${x}.config.system.build.diskoScript}" "$out/bin/disko-${x}"
'') systems}
runHook postInstall
'';
};
in {
imports = [
../../../third_party/nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix
];
isoImage.isoName = lib.mkForce "nixos-${depot.version}-${pkgs.stdenv.hostPlatform.system}.iso";
environment.systemPackages = [
depot-install
diskos
];
system.disableInstallerTools = false;
system.stateVersion = "24.11";
}