default:
  @just --list

defhost := `hostname`
defuser := env_var('USER')

alias dh := deployhome
[group('home')]
deployhome user=defuser host=defhost:
  nh home switch -c {{user}}@{{host}} -b bak .

[group('home')]
refreshhome user=defuser host=defhost:
  nh home switch -c {{user}}@{{host}} -b bak . -- --refresh

alias do := deployos
[group('nixos')]
deployos host=defhost:
  nh os switch -H {{host}} .

alias dro := deployRemoteOs
[group('nixos')]
deployRemoteOs host:
  nixos-rebuild switch --flake .#{{host}} \
  --target-host root@{{host}} \
  --verbose --log-format internal-json |& nom --json

[group('nixos')]
deployAll:
  #!/usr/bin/env fish
  set -l systems (nix flake show --all-systems --json \
    | jq '.nixosConfigurations | keys[]' \
      # Remove literal quotes from values so that contains works.
    | string trim --chars \"\'\")

  # Remove the current system.
  set -l currentSysI (contains --index (hostname) $systems)
  if set -q currentSysI[1]
    set -e systems[$currentSysI]
  end

  just deployos

  for system in $systems
    just deployRemoteOs $system
  end

alias dd := deploydarwin
[group('darwin')]
deploydarwin host=defhost:
  darwin-rebuild switch --flake .#{{host}}

alias up := update
[group('update')]
update:
  nix flake update

[group('update')]
updatejust this:
  nix flake update {{this}}

alias gc := collectgarbage
[group('maintainence')]
collectgarbage:
  nh clean all

[group('maintainence')]
genFirefoxAddons:
  nix run git+https://git.sr.ht/~rycee/mozilla-addons-to-nix/ -- \
  overlays/firefox-addons/addons.json \
  overlays/firefox-addons/addons.nix

alias s := search
search this:
  nh search {{this}}
