2024-03-17 18:48:49 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
modulesPath,
|
|
|
|
...
|
|
|
|
}:
|
2024-04-23 21:10:05 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
network-status = pkgs.writeShellScript "network-status" ''
|
|
|
|
export PATH=${
|
|
|
|
lib.makeBinPath (
|
|
|
|
with pkgs;
|
|
|
|
[
|
|
|
|
iproute2
|
|
|
|
coreutils
|
|
|
|
gnugrep
|
|
|
|
nettools
|
|
|
|
gum
|
|
|
|
]
|
|
|
|
)
|
|
|
|
}
|
|
|
|
set -efu -o pipefail
|
|
|
|
msgs=()
|
|
|
|
if [[ -e /var/shared/qrcode.utf8 ]]; then
|
|
|
|
qrcode=$(gum style --border-foreground 240 --border normal "$(< /var/shared/qrcode.utf8)")
|
|
|
|
msgs+=("$qrcode")
|
|
|
|
fi
|
|
|
|
network_status="Root password: $(cat /var/shared/root-password)
|
|
|
|
Local network addresses:
|
|
|
|
$(ip -brief -color addr | grep -v 127.0.0.1)
|
|
|
|
$([[ -e /var/shared/onion-hostname ]] && echo "Onion address: $(cat /var/shared/onion-hostname)" || echo "Onion address: Waiting for tor network to be ready...")
|
|
|
|
Multicast DNS: $(hostname).local"
|
|
|
|
network_status=$(gum style --border-foreground 240 --border normal "$network_status")
|
|
|
|
msgs+=("$network_status")
|
|
|
|
msgs+=("Press 'Ctrl-C' for console access")
|
|
|
|
|
|
|
|
gum join --vertical "''${msgs[@]}"
|
|
|
|
'';
|
|
|
|
in
|
2024-03-17 18:48:49 +00:00
|
|
|
{
|
2024-04-07 19:07:02 +00:00
|
|
|
############################################
|
|
|
|
# #
|
|
|
|
# For install image debugging execute: #
|
|
|
|
# $ qemu-kvm result/stick.raw -snapshot #
|
|
|
|
# #
|
|
|
|
############################################
|
2023-07-28 14:37:10 +00:00
|
|
|
imports = [
|
|
|
|
(modulesPath + "/profiles/installation-device.nix")
|
|
|
|
(modulesPath + "/profiles/all-hardware.nix")
|
|
|
|
(modulesPath + "/profiles/base.nix")
|
|
|
|
];
|
2024-04-23 21:10:05 +00:00
|
|
|
|
|
|
|
########################################################################################################
|
|
|
|
# #
|
|
|
|
# Copied from: #
|
|
|
|
# https://github.com/nix-community/nixos-images/blob/main/nix/image-installer/module.nix#L46C3-L117C6 #
|
|
|
|
# #
|
|
|
|
########################################################################################################
|
|
|
|
systemd.tmpfiles.rules = [ "d /var/shared 0777 root root - -" ];
|
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
|
2024-04-23 21:10:05 +00:00
|
|
|
${pkgs.xkcdpass}/bin/xkcdpass --numwords 3 --delimiter - --count 1 > /var/shared/root-password
|
2023-07-07 13:55:13 +00:00
|
|
|
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" \
|
2024-04-23 21:10:05 +00:00
|
|
|
'{ pass: $password, tor: $onion_address, addrs: $local_addrs }' \
|
2023-10-27 14:56:54 +00:00
|
|
|
> /var/shared/login.json
|
2024-04-23 21:10:05 +00:00
|
|
|
cat /var/shared/login.json | qrencode -s 2 -m 2 -t utf8 -o /var/shared/qrcode.utf8
|
2023-07-07 13:55:13 +00:00
|
|
|
'';
|
|
|
|
};
|
2024-04-23 21:10:05 +00:00
|
|
|
|
2023-07-07 13:55:13 +00:00
|
|
|
services.getty.autologinUser = lib.mkForce "root";
|
2024-04-23 21:10:05 +00:00
|
|
|
|
|
|
|
console.earlySetup = true;
|
|
|
|
console.font = lib.mkDefault "${pkgs.terminus_font}/share/consolefonts/ter-u22n.psf.gz";
|
|
|
|
|
|
|
|
# Less ipv6 addresses to reduce the noise
|
|
|
|
networking.tempAddresses = "disabled";
|
|
|
|
|
|
|
|
# Tango theme: https://yayachiken.net/en/posts/tango-colors-in-terminal/
|
|
|
|
console.colors = lib.mkDefault [
|
|
|
|
"000000"
|
|
|
|
"CC0000"
|
|
|
|
"4E9A06"
|
|
|
|
"C4A000"
|
|
|
|
"3465A4"
|
|
|
|
"75507B"
|
|
|
|
"06989A"
|
|
|
|
"D3D7CF"
|
|
|
|
"555753"
|
|
|
|
"EF2929"
|
|
|
|
"8AE234"
|
|
|
|
"FCE94F"
|
|
|
|
"739FCF"
|
|
|
|
"AD7FA8"
|
|
|
|
"34E2E2"
|
|
|
|
"EEEEEC"
|
|
|
|
];
|
|
|
|
|
2023-07-07 13:55:13 +00:00
|
|
|
programs.bash.interactiveShellInit = ''
|
2024-03-17 18:14:24 +00:00
|
|
|
if [[ "$(tty)" =~ /dev/(tty1|hvc0|ttyS0)$ ]]; then
|
2024-04-23 21:10:05 +00:00
|
|
|
# workaround for https://github.com/NixOS/nixpkgs/issues/219239
|
|
|
|
systemctl restart systemd-vconsole-setup.service
|
|
|
|
|
|
|
|
watch --no-title --color ${network-status}
|
2023-07-07 13:55:13 +00:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
}
|