NixOS system configurations + dotfiles via home-manager
at main 57 lines 1.6 kB view raw
1argparse -n deploy 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:/etc/nixos/ 10end 11 12test -d $flake; and type -q jj 13and test (realpath $flake) = "$(jj root 2>/dev/null)" 14and type -q git; and git rev-parse &>/dev/null 15and begin 16 set revision (printf $_flag_revision; or printf 'heads(::@ ~ empty())') 17 set commit (jj log -r $revision --no-graph -T commit_id) 18 or return 19 set flake "$flake?rev=$commit&ref=$commit" 20end 21 22function _deploy_one -a host 23 set host (string replace .$domain '' $host) 24 set host_url $host.$domain 25 set args -e passwordless --diff never $flake 26 set -a args --hostname $host --target-host $host_url 27 if set -q _flag_remote 28 set -a args --build-host $host_url 29 end 30 31 set root ~/.local/share/nix/gcroots/$host 32 if not set -q _flag_remote; and test -d ~/.local/share/nix/gcroots 33 set -a args --out-link $root 34 end 35 36 set command (printf $_flag_command; or printf switch) 37 nh os $command $args 38 or return 39 40 set -q commit 41 and jj --color=always bookmark set $host -B -r $commit &>/dev/null 42 43 set highlight (set_color -o brmagenta) 44 set reset (set_color normal) 45 random (echo -n $host | sum | cut -d' ' -f1) 46 set icon (random choice 🌸 🌼 🌻 🌺 🌷 🍄 🍀 🌳) 47 echo \nDeployed $icon$highlight$host_url$reset$icon 48end 49 50if not set -q argv[1] 51 set argv (hostname -f) 52end 53for arg in $argv 54 _deploy_one $arg 55end 56 57functions -e _deploy_one