Utoljára aktív 1 week ago

Revízió 8325e3aa4beb1c978707ba0b788202f1ec99ff5c

nixos-anywhere-install.nu Eredeti
1def nixos-anywhere-install [
2 ip: string
3 hostname: string
4 port: int = 22
5 temp: string = ""
6 --rsa
7 --nix-args: list<string> = []
8] {
9 if (which ssh-keygen | length) == 0 {
10 error make {msg: "ssh-keygen not found in PATH"}
11 }
12 if (which nix | length) == 0 {
13 error make {msg: "nix not found in PATH"}
14 }
15 let temp_dir = if $temp == "" {
16 let dir = mktemp -d | str trim
17 print $dir
18 $dir
19 } else {
20 $temp
21 }
22 let persist_dir = $temp_dir | path join "persist"
23 let etc_dir = $persist_dir | path join "etc"
24 let key_dir = $etc_dir | path join "ssh"
25 let target = $"root@($ip)"
26 let flake = $".#($hostname)"
27 let comment = $"root@($hostname)"
28 let ed25519_key = $temp_dir | path join "ssh_host_ed25519_key"
29 let rsa_key = $temp_dir | path join "ssh_host_rsa_key"
30 mkdir $key_dir
31 chmod 755 $persist_dir
32 chmod 755 $etc_dir
33 chmod 755 $key_dir
34 ^ssh-keygen -q -t ed25519 -N "" -f $ed25519_key -C $comment
35 cp $ed25519_key ($key_dir | path join "ssh_host_ed25519_key")
36 cp $"($ed25519_key).pub" ($key_dir | path join "ssh_host_ed25519_key.pub")
37 chmod 600 ($key_dir | path join "ssh_host_ed25519_key")
38 chmod 644 ($key_dir | path join "ssh_host_ed25519_key.pub")
39 if $rsa {
40 ^ssh-keygen -q -t rsa -b 4096 -N "" -f $rsa_key -C $comment
41 cp $rsa_key ($key_dir | path join "ssh_host_rsa_key")
42 cp $"($rsa_key).pub" ($key_dir | path join "ssh_host_rsa_key.pub")
43 chmod 600 ($key_dir | path join "ssh_host_rsa_key")
44 chmod 644 ($key_dir | path join "ssh_host_rsa_key.pub")
45 }
46 let nix_cmd = [
47 run
48 ...$nix_args
49 github:nix-community/nixos-anywhere
50 --
51 --ssh-port
52 ($port | into string)
53 --post-kexec-ssh-port
54 ($port | into string)
55 --flake
56 $flake
57 --extra-files
58 $temp_dir
59 $target
60 ]
61 print "Press (x) to start installation"
62 let key = (input --numchar 1)
63 if $key == "x" {
64 ^nix ...$nix_cmd
65 } else {
66 print "Installation cancelled"
67 }
68}
69
70