-
Notifications
You must be signed in to change notification settings - Fork 0
/
iso.nix
99 lines (86 loc) · 2.69 KB
/
iso.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
{
config,
lib,
pkgs,
modulesPath,
...
}: {
imports = [
"${modulesPath}/installer/cd-dvd/installation-cd-minimal.nix"
];
boot.kernelPackages = pkgs.linuxKernel.packages.linux_6_1;
boot.loader.timeout = lib.mkForce 5;
hardware.enableAllFirmware = true;
nixpkgs.config.allowUnfree = true;
isoImage.isoName = lib.mkForce "gather-facts-${config.isoImage.isoBaseName}-${pkgs.stdenv.hostPlatform.system}.iso";
environment.systemPackages = with pkgs; [
dmidecode
hwinfo
python3
magic-wormhole
lshw
smartmontools
];
services.getty.helpLine = ''
An UNATTENDED script is about to run to gather
facts about CPU, RAM, storage, etc., and send
them over MAGIC WORMHOLE (potentially an ONLINE
EXTERNAL SERVER). The computer will require an
ACTIVE NETWORK CONNECTION WITHOUT AUTHENTICATION
to send the information.
The system will POWER OFF after it is done.
'';
systemd.services.gather = {
description = "Gather information about the system";
after = ["network.target"];
wants = ["network.target"];
wantedBy = ["multi-user.target"];
serviceConfig = {
WorkingDirectory = "/home/nixos";
};
path = ["/run/current-system/sw/"];
script = let
wormhole-code-env = builtins.getEnv "WORMHOLE_CODE";
wormhole-code =
if wormhole-code-env == ""
then throw "No WORMHOLE_CODE environment variable set"
else wormhole-code-env;
in ''
set -x
mkdir -p facts
hwinfo > facts/hwinfo.txt
lscpu > facts/lscpu.txt
lsusb > facts/lsusb.txt
lsblk > facts/lsblk.txt
lspci > facts/lspci.txt
lsmem > facts/lsmem.txt
lshw > facts/lshw.txt
lshw -short > facts/lshw-short.txt
dmidecode > facts/dmidecode.txt
for drive in $(lsblk -o NAME -nld); do
if smartctl -a /dev/$drive; then
smartctl -a /dev/$drive > facts/smart-$drive.txt
fi
done
# generate a random ID in the form MXXXXXXXXC
# where M is arbitrary, X's are digits 0-9, and the last C is the Luhn checksum digit
ID=$(cat /dev/urandom | tr -dc 0-9 | head -c 8)
CHECK_DIGIT=$(python3 -c "digits = list(map(int,str('$ID' + '0'))); print((10 - (sum(digits[-1::-2]) + sum([sum(divmod(2 * d, 10)) for d in digits[-2::-2]]))) % 10)")
echo "M''${ID}''${CHECK_DIGIT}" > facts/id
cd facts
zip ../facts.zip *
cd ..
wormhole send --code ${lib.escapeShellArg wormhole-code} facts.zip
poweroff
'';
environment =
config.nix.envVars
// {
inherit (config.environment.sessionVariables) NIX_PATH;
HOME = "/root";
};
serviceConfig = {
Type = "oneshot";
};
};
}