-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy.nu
executable file
·54 lines (44 loc) · 1.23 KB
/
deploy.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
#!/usr/bin/env nu
def run [host: string, ...cmd: string] {
let command = ($cmd | str join ' ')
if $host == (hostname) {
exec ($command)
} else {
ssh $host -- $"cd code/dotfiles; ($command)"
}
}
def buildHere [derivation: string, destination: string] {
nix build ($derivation)
nix copy -L ($derivation) --no-check-sigs --to ssh-ng://($destination)
}
def updateRemote [host: string] {
if $host != (hostname) {
run $host git fetch
run $host git pull
}
}
def compareRemotely [host: string, derivation: string] {
updateRemote $host
run $host nix build ($derivation)
run $host nvd diff /run/current-system ./result
}
def runUpdate [host: string] {
print ''
print -n 'Switch to new config? (y/_) '
let result = (input listen --types [key])
print ''
if $result.code == 'y' {
print 'Updating...'
run $host sudo nixos-rebuild switch "--flake" .#($host)
} else {
print 'Not updating.'
}
}
def main [inputHost: string] {
let host = if $inputHost == null { hostname } else { $inputHost }
let derivation = $".#nixosConfigurations.($host).config.system.build.toplevel"
let destination = $"evie@($host)"
buildHere $derivation $destination
compareRemotely $host $derivation
runUpdate $host
}