1argparse -n deploy -X 1 c/command= r/revision= R/remote -- $argv
2or return
3
4if test -e ./flake.nix
5 set flake .
6else if test -e /etc/nixos/flake.nix
7 set flake /etc/nixos
8else
9 set flake git+ssh://grancel.ygg.pvsr.dev:/etc/nixos/
10end
11
12test -d $flake; and type -q jj
13and test (realpath $flake) = "$(jj root 2>/dev/null)"
14and begin
15 set revision (printf $_flag_revision; or printf 'heads(::@ ~ empty())')
16 set commit (jj log -r $revision --no-graph -T commit_id)
17 or return
18
19 type -q git; and git rev-parse &>/dev/null
20 and set flake "$flake?rev=$commit&ref=$commit"
21end
22
23if set -q argv[1]
24 set host $argv[1]
25 set host_url (string replace incus (hostname) $host).ygg.pvsr.dev
26 set args --target-host $host_url
27 if set -q _flag_remote
28 set -a args --build-host $host_url
29 end
30else
31 set host (hostname)
32end
33
34set -a args --no-reexec --sudo --flake $flake#$host
35
36set -a args (printf $_flag_command; or printf switch)
37
38if not set -q _flag_remote; and test -d ~/.local/share/nix/gcroots
39 set result (nix build \
40 $flake#nixosConfigurations.\"$host\".config.system.build.toplevel \
41 --print-out-paths --log-format internal-json --verbose 2>| nom --json)
42 test $pipestatus[1] = 0; or return
43end
44
45nixos-rebuild $args --log-format internal-json --verbose 2>| nom --json
46test $pipestatus[1] = 0; or return
47
48set -q commit
49and jj --color=always bookmark set $host -B -r $commit &>/dev/null
50
51set -q result
52and nix-store --realise $result \
53 --add-root ~/.local/share/nix/gcroots/$host &>/dev/null