-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.nu
108 lines (84 loc) · 2.41 KB
/
util.nu
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
#!/usr/bin/env nu
export-env {
$env.get_addr = { |map, per| $map | get $per | $in.addr }
$env.get_user = { |map, per| $map | get $per | $in.user }
$env.map = open ./hosts/sum.toml | $in.node
}
export def br [
nodes?: list<string>
--builder (-b): string = "hastur"
] {
let target_addr = do $env.get_addr ($env.map) $builder
let h = hostname | str trim
let job = if $h != $builder {
["--max-jobs" "0"]
} else { [] }
let machine_spec = "x86_64-linux - - - big-parallel"
$nodes | par-each {||
(nix build $'.#nixosConfigurations.($in).config.system.build.toplevel'
--builders $"($target_addr) ($machine_spec)"
...($job) -vvv)
}
}
# build
export def b [
nodes?: list<string>
] {
$nodes | par-each {||
(nom build $'.#nixosConfigurations.($in).config.system.build.toplevel')
}
}
# deploy
# all op with hostname
export def d [
nodes?: list<string>
mode?: string = "switch"
--builder: string
--sod
] {
let get_addr = {|x| do $env.get_addr ($env.map) ($x)}
let get_user = {|x| do $env.get_user ($env.map) ($x)}
let machine_spec = "i686-linux,x86_64-linux - - - big-parallel"
let extra_builder_args = if ($builder != null) { [--max-jobs 0 --builders $'(do $get_addr $builder) ($machine_spec)'] } else {[]}
print $extra_builder_args
if ($nodes == null or $nodes == []) {
(nh os $mode . -- ...($extra_builder_args))
} else {
use std log;
$nodes | each {|per|
let per_node_addr = do $get_addr $per;
let user = do $get_user $per;
nixos-rebuild switch --flake . --target-host $'($user)@($per_node_addr)' --sudo
}
}
}
const age_pub = "/run/vaultix/age"
# decrypt
export def de [path: string] {
let tmp_path = (mktemp -t)
rage -d $path -i $age_pub -o $tmp_path # -i ./age-yubikey-identity-7d5d5540.txt.pub
let mime_type = (xdg-mime query filetype $tmp_path)
if ($mime_type | str contains "image") {
cat $tmp_path | img2sixel
} else {
cat $tmp_path
}
srm -C $tmp_path
}
export def dump [path?: string = "./sec/decrypted"] {
srm -frC $path
mkdir $path
ls ./sec/*.age | par-each {|i|
de $i.name | save $'($path)/($i.name | path parse | $in.stem)'
}
}
export def chk [] {
let allow = ["f" "age-yubikey-identity-7d5d5540.txt.pub" "rekeyed"]
ls sec |
filter {|i|
not ($in.name | path basename | str ends-with "age")
} |
filter {|i|
not ($i.name | path basename | $in in $allow)
}
}