2024-03-17 18:48:49 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
modulesPath,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
{
|
2024-04-07 19:07:02 +00:00
|
|
|
############################################
|
|
|
|
# #
|
|
|
|
# For install image debugging execute: #
|
|
|
|
# $ qemu-kvm result/stick.raw -snapshot #
|
|
|
|
# #
|
|
|
|
############################################
|
2024-03-17 18:48:49 +00:00
|
|
|
systemd.tmpfiles.rules = [ "d /var/shared 0777 root root - -" ];
|
2023-07-28 14:37:10 +00:00
|
|
|
imports = [
|
|
|
|
(modulesPath + "/profiles/installation-device.nix")
|
|
|
|
(modulesPath + "/profiles/all-hardware.nix")
|
|
|
|
(modulesPath + "/profiles/base.nix")
|
|
|
|
];
|
2023-07-07 13:55:13 +00:00
|
|
|
services.openssh.settings.PermitRootLogin = "yes";
|
|
|
|
system.activationScripts.root-password = ''
|
2023-07-24 09:31:52 +00:00
|
|
|
mkdir -p /var/shared
|
2023-07-07 13:55:13 +00:00
|
|
|
${pkgs.pwgen}/bin/pwgen -s 16 1 > /var/shared/root-password
|
|
|
|
echo "root:$(cat /var/shared/root-password)" | chpasswd
|
|
|
|
'';
|
2023-07-24 10:09:11 +00:00
|
|
|
hidden-ssh-announce = {
|
2023-07-07 13:55:13 +00:00
|
|
|
enable = true;
|
2023-10-27 14:56:54 +00:00
|
|
|
script = pkgs.writeShellScript "write-hostname" ''
|
2023-07-28 16:17:10 +00:00
|
|
|
set -efu
|
2024-03-17 18:48:49 +00:00
|
|
|
export PATH=${
|
|
|
|
lib.makeBinPath (
|
|
|
|
with pkgs;
|
|
|
|
[
|
|
|
|
iproute2
|
|
|
|
coreutils
|
|
|
|
jq
|
|
|
|
qrencode
|
|
|
|
]
|
|
|
|
)
|
|
|
|
}
|
2023-10-27 14:56:54 +00:00
|
|
|
|
2023-07-24 09:31:52 +00:00
|
|
|
mkdir -p /var/shared
|
2023-07-07 13:55:13 +00:00
|
|
|
echo "$1" > /var/shared/onion-hostname
|
2023-10-27 14:56:54 +00:00
|
|
|
local_addrs=$(ip -json addr | jq '[map(.addr_info) | flatten | .[] | select(.scope == "global") | .local]')
|
|
|
|
jq -nc \
|
2023-07-24 10:09:11 +00:00
|
|
|
--arg password "$(cat /var/shared/root-password)" \
|
2023-10-27 14:56:54 +00:00
|
|
|
--arg onion_address "$(cat /var/shared/onion-hostname)" \
|
|
|
|
--argjson local_addrs "$local_addrs" \
|
|
|
|
'{ password: $password, onion_address: $onion_address, local_addresses: $local_addrs }' \
|
|
|
|
> /var/shared/login.json
|
|
|
|
cat /var/shared/login.json | qrencode -t utf8 -o /var/shared/qrcode.utf8
|
2023-07-07 13:55:13 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
services.getty.autologinUser = lib.mkForce "root";
|
|
|
|
programs.bash.interactiveShellInit = ''
|
2024-03-17 18:14:24 +00:00
|
|
|
if [[ "$(tty)" =~ /dev/(tty1|hvc0|ttyS0)$ ]]; then
|
2023-10-27 14:56:54 +00:00
|
|
|
echo -n 'waiting for tor to generate the hidden service'
|
|
|
|
until test -e /var/shared/qrcode.utf8; do echo -n .; sleep 1; done
|
|
|
|
echo
|
|
|
|
echo "Root password: $(cat /var/shared/root-password)"
|
|
|
|
echo "Onion address: $(cat /var/shared/onion-hostname)"
|
|
|
|
echo "Local network addresses:"
|
|
|
|
${pkgs.iproute}/bin/ip -brief -color addr | grep -v 127.0.0.1
|
2023-07-24 10:09:11 +00:00
|
|
|
cat /var/shared/qrcode.utf8
|
2023-07-07 13:55:13 +00:00
|
|
|
fi
|
|
|
|
'';
|
2024-03-06 15:41:26 +00:00
|
|
|
|
2024-04-07 19:07:02 +00:00
|
|
|
# boot.loader.systemd-boot.enable = true;
|
2024-03-06 15:41:26 +00:00
|
|
|
|
|
|
|
# Grub doesn't find devices for both BIOS and UEFI?
|
2024-04-07 19:07:02 +00:00
|
|
|
# Mic92: Please write where this exactly breaks if you want to comment out grub again.
|
2024-04-07 15:09:44 +00:00
|
|
|
# NOTE: We need grub here. Otherwise, the system won't boot in some machines.
|
|
|
|
# example: Lenovo E495 didn't boot without grub.
|
|
|
|
boot.loader.grub.efiInstallAsRemovable = true;
|
|
|
|
boot.loader.grub.efiSupport = true;
|
2024-04-07 19:07:02 +00:00
|
|
|
|
2023-07-28 14:37:10 +00:00
|
|
|
disko.devices = {
|
|
|
|
disk = {
|
|
|
|
stick = {
|
|
|
|
type = "disk";
|
|
|
|
device = "/vda";
|
|
|
|
imageSize = "3G";
|
|
|
|
content = {
|
|
|
|
type = "gpt";
|
|
|
|
partitions = {
|
2024-04-07 15:09:44 +00:00
|
|
|
boot = {
|
2024-04-07 19:07:02 +00:00
|
|
|
priority = 1;
|
|
|
|
size = "1M";
|
|
|
|
type = "EF02"; # for grub MBR
|
2024-04-07 15:09:44 +00:00
|
|
|
};
|
2023-07-28 14:37:10 +00:00
|
|
|
ESP = {
|
|
|
|
size = "100M";
|
|
|
|
type = "EF00";
|
|
|
|
content = {
|
|
|
|
type = "filesystem";
|
|
|
|
format = "vfat";
|
|
|
|
mountpoint = "/boot";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
root = {
|
|
|
|
size = "100%";
|
|
|
|
content = {
|
|
|
|
type = "filesystem";
|
|
|
|
format = "ext4";
|
|
|
|
mountpoint = "/";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-07-07 14:05:20 +00:00
|
|
|
};
|
2023-07-07 13:55:13 +00:00
|
|
|
}
|