nix_flake := "/home/petere/Nix-Vibe"
hostname := `hostname`

# list available recipes
default:
    @just --list --justfile {{justfile()}} 2>/dev/null || echo "Run: just -g --list"

# rebuild current system
[group('NixOS')]
update:
    cd {{nix_flake}} && sudo nixos-rebuild switch --flake .#{{hostname}}

# remote deploy: just deploy x470
[group('NixOS')]
deploy target:
    cd {{nix_flake}} && nixos-rebuild switch --target-host petere@{{target}} --flake .#{{target}} --sudo

# update flake.lock
[group('NixOS')]
flake-lock:
    cd {{nix_flake}} && nix flake update

# update flake + rebuild
[group('NixOS')]
upgrade:
    cd {{nix_flake}} && nix flake update && sudo nixos-rebuild switch --flake .#{{hostname}}

# build without switching (test config)
[group('NixOS')]
build:
    cd {{nix_flake}} && nixos-rebuild build --flake .#{{hostname}}

# dry activation (check if config is valid)
[group('NixOS')]
check:
    cd {{nix_flake}} && nixos-rebuild dry-activate --flake .#{{hostname}}

# switch home-manager config only
[group('NixOS')]
hm-switch:
    cd {{nix_flake}} && home-manager switch --flake .#{{hostname}}

# garbage collect nix store
[group('System')]
gc:
    nix-collect-garbage -d
    sudo nix-collect-garbage -d

# remove old generations
[group('System')]
clean:
    sudo nix-env --delete-generations old -p /nix/var/nix/profiles/system
    sudo nix-collect-garbage -d
