# List all receipes
default:
    @just --list

# Format all files in repo
fmt:
    treefmt --on-unmatched info

# Clean user files
clean-user:
    nh clean user

# Clean all files
clean-all:
    nh clean all

# Build a specific host but don't activate it. Host must use same system as target system
build HOST:
    git add .
    just fmt
    nh os build . -H {{HOST}}

# Switch to new config, but don't add to bootloader
test *FLAGS:
    git add .
    just fmt
    nh os test . {{FLAGS}}

# Add new configuration to bootloader, but don't activate it now
boot *FLAGS:
    git add .
    just fmt
    nh os test . {{FLAGS}}

# Switch to new config and add to bootloader
switch *FLAGS:
    git add .
    just fmt
    nh os switch . {{FLAGS}}

# Switch to new config and add to bootloader without formatting or adding to git
switch-now *FLAGS:
    nh os switch . {{FLAGS}}

update-all *FLAGS:
    nix flake update
    just switch {{FLAGS}}

update PKG:
    nix flake update {{PKG}}
    just switch

# Encrypt all files in the repo using git-crypt
lock:
    git-crypt lock

# Decrypt all files in the repo using git-crypt and the user's GPG key
unlock:
    git-crypt unlock ~/.config/git/crypt-key

# Connect to tailnet or sign-in if not registered
start-tailscale:
    tailscale up --login-server https://vpn.martials.no

# Generate a new SSH key without passphrase
generate-ssh:
    ssh-keygen -t ed25519 -a 32 -f ~/.ssh/id_ed25519 -P ""

# Generate a new age key from an existing ssh key (without passphrase)
generate-age-from-ssh:
    mkdir -p ~/.config/sops/age
    nix run nixpkgs#ssh-to-age -- -private-key -i ~/.ssh/id_ed25519 > ~/.config/sops/age/keys.txt

# Get a public age key from an existing age private key
get-public-age-key:
    nix shell nixpkgs#age -c age-keygen -y ~/.config/sops/age/keys.txt

# Get the public ssh key from the current user
get-public-ssh-key:
    cat ~/.ssh/id_ed25519.pub

# Edit the SOPS secrets file
edit-secrets:
    nix run nixpkgs#sops -- shared/secrets/secrets.yaml

# Hash a string using the mkpasswd command
hash PASS:
    echo "{{PASS}}" | mkpasswd -s
