-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrebuild.nu
More file actions
executable file
·67 lines (55 loc) · 1.77 KB
/
Copy pathrebuild.nu
File metadata and controls
executable file
·67 lines (55 loc) · 1.77 KB
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
#!/usr/bin/env nu
def --wrapped sync [...arguments] {
(rsync
--archive
--compress
--delete --recursive --force
--delete-excluded
--delete-missing-args
--human-readable
--delay-updates
...$arguments)
}
# Rebuild a NixOS / Darwin config.
def main --wrapped [
host: string = "" # The host to build.
--remote # Whether if this is a remote host. The config will be built on this host if it is.
...arguments # The arguments to pass to `nh {os,darwin} switch` and `nix` (separated by --).
]: nothing -> nothing {
let host = if ($host | is-not-empty) {
if $host != (hostname) and not $remote {
print $"(ansi yellow_bold)warn:(ansi reset) building local configuration for hostname that does not match the local machine"
}
$host
} else if $remote {
print $"(ansi red_bold)error:(ansi reset) hostname not specified for remote build"
exit 1
} else {
(hostname)
}
if $remote {
ssh -tt ("root@" + $host) "
rm --recursive --force ncc
"
git ls-files
| sync --files-from - ./ $"root@($host):ncc"
ssh -tt ("root@" + $host) $"
cd ncc
./rebuild.nu ($host) ($arguments | str join ' ')
"
return
}
let args_split = $arguments | prepend "" | split list "--"
let nh_flags = [
"--hostname" $host
] | append ($args_split | get 0 | where { $in != "" })
let nix_flags = [
"--accept-flake-config"
"--extra-experimental-features" "pipe-operators"
] | append ($args_split | get --ignore-errors 1 | default [])
if (uname | get kernel-name) == "Darwin" {
sudo NH_BYPASS_ROOT_CHECK=true NH_NO_CHECKS=true nh darwin switch . ...$nh_flags -- ...$nix_flags
} else {
NH_BYPASS_ROOT_CHECK=true NH_NO_CHECKS=true nh os switch . ...$nh_flags -- ...$nix_flags
}
}