+17
-9
modules/deploy.fish
+17
-9
modules/deploy.fish
···
1
1
#!/usr/bin/env fish
2
-
argparse -n deploy -X 1 c/command= r/remote -- $argv
2
+
argparse -n deploy -X 1 c/command= r/revision= R/remote -- $argv
3
3
or return
4
4
5
5
if test -e ./flake.nix
···
10
10
set flake git+ssh://grancel:/etc/nixos/
11
11
end
12
12
13
-
test -d "$flake"
14
-
and type -q jj
15
-
and test (realpath "$flake") = "$(jj root 2>/dev/null)"
16
-
and set change (jj log -r 'heads(::@ ~ empty())' --no-graph -T change_id)
13
+
if test -d $flake; and type -q jj; and test (realpath $flake) = "$(jj root 2>/dev/null)"
14
+
set revision (printf $_flag_revision; or printf 'heads(::@ ~ empty())')
15
+
set commit (jj log -r $revision --no-graph -T commit_id)
16
+
set flake "$flake?rev=$commit&ref=$commit"
17
+
end
17
18
18
19
if set -q argv[1]
19
20
set host $argv[1]
···
27
28
set -a args --no-reexec --sudo --flake $flake#$host
28
29
set -a args (printf $_flag_command; or printf switch)
29
30
30
-
nixos-rebuild $args --log-format internal-json --verbose &| nom --json
31
+
if not set -q _flag_remote; and test -d ~/.local/share/nix/gcroots
32
+
set result (nix build $flake#nixosConfigurations.$host.config.system.build.toplevel \
33
+
--print-out-paths --log-format internal-json --verbose 2>| nom --json)
34
+
test $pipestatus[1] = 0; or return
35
+
nix-store --realise $result --add-root ~/.local/share/nix/gcroots/$host
36
+
end
31
37
32
-
test $pipestatus[1] = 0
33
-
and set -q change
34
-
and jj --color=always bookmark set $host -B -r $change 2&>/dev/null
38
+
nixos-rebuild $args --log-format internal-json --verbose 2>| nom --json
39
+
test $pipestatus[1] = 0; or return
40
+
41
+
set -q commit; or return
42
+
jj --color=always bookmark set $host -B -r $commit 2&>/dev/null