-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinstaller.nix
113 lines (89 loc) · 4.11 KB
/
installer.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{ config, pkgs, lib, modulesPath, ... }:
let
# can't use pkgs.nixos because we're setting nixpkgs config settings
# (at least allowUnfree) in install config.
evaluatedSystem = import (pkgs.path + "/nixos/lib/eval-config.nix") {
system = "x86_64-linux";
modules = [ ./configuration/configuration.nix ];
};
in
{
imports = [
"${modulesPath}/installer/cd-dvd/installation-cd-minimal.nix"
];
isoImage.isoName = lib.mkForce "nixcademy-auto-installer-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}.iso";
services.getty.helpLine = ''
███╗ ██╗██╗██╗ ██╗ ██████╗ █████╗ ██████╗ ███████╗███╗ ███╗██╗ ██╗
████╗ ██║██║╚██╗██╔╝██╔════╝██╔══██╗██╔══██╗██╔════╝████╗ ████║╚██╗ ██╔╝
██╔██╗ ██║██║ ╚███╔╝ ██║ ███████║██║ ██║█████╗ ██╔████╔██║ ╚████╔╝
██║╚██╗██║██║ ██╔██╗ ██║ ██╔══██║██║ ██║██╔══╝ ██║╚██╔╝██║ ╚██╔╝
██║ ╚████║██║██╔╝ ██╗╚██████╗██║ ██║██████╔╝███████╗██║ ╚═╝ ██║ ██║
╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝
Automatic Installer Go brrrrr
'';
nixpkgs.config.allowUnfree = true;
hardware.enableAllFirmware = true;
services.journald.console = "/dev/tty1";
nix.settings.substituters = lib.mkForce [];
systemd.services.install = {
description = "Bootstrap a NixOS installation";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" "polkit.service" ];
path = [ "/run/current-system/sw/" ];
script = with pkgs; ''
# this is just for debugging purposes, can be removed when it all works
echo 'journalctl -fb -n100 -uinstall' >> ~nixos/.bash_history
set -euxo pipefail
wait-for() {
for _ in seq 10; do
if $@; then
break
fi
sleep 1
done
}
dev=/dev/sda
[ -b /dev/nvme0n1 ] && dev=/dev/nvme0n1
[ -b /dev/vda ] && dev=/dev/vda
# the cryptic type stands for "EFI system partition"
${utillinux}/bin/sfdisk --wipe=always "$dev" <<-END
label: gpt
name=BOOT, size=512MiB, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B
name=SWAP, size=8GiB, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F
name=NIXOS
END
sync
wait-for [ -b /dev/disk/by-partlabel/BOOT ]
wait-for mkfs.fat -F 32 -n boot /dev/disk/by-partlabel/BOOT
wait-for [ -b /dev/disk/by-partlabel/SWAP ]
wait-for mkswap -L swap /dev/disk/by-partlabel/SWAP
wait-for [ -b /dev/disk/by-partlabel/NIXOS ]
mkfs.ext4 -L nixos /dev/disk/by-partlabel/NIXOS
sync
wait-for [ -b /dev/disk/by-label/swap ]
swapon /dev/disk/by-label/swap
wait-for [ -b /dev/disk/by-label/nixos ]
mount /dev/disk/by-label/nixos /mnt
mkdir /mnt/boot
wait-for mount /dev/disk/by-label/boot /mnt/boot
mkdir -p /mnt/etc/nixos
cp -r ${./configuration}/* /mnt/etc/nixos/
chmod -R 755 /mnt/etc/nixos
# add parameters so that nix does not try to contact a cache as we expect
# to be offline anyway
${config.system.build.nixos-install}/bin/nixos-install \
--system ${evaluatedSystem.config.system.build.toplevel} \
--no-root-passwd \
--cores 0
echo 'Done. Shutting off.'
${systemd}/bin/systemctl poweroff
'';
environment = config.nix.envVars // {
inherit (config.environment.sessionVariables) NIX_PATH;
HOME = "/root";
};
serviceConfig = {
Type = "oneshot";
};
};
}