#!/usr/bin/env bash

set -euo pipefail

nix fmt --option warn-dirty false

# Allow usage of untracked files in nix code
git add --intent-to-add .

# I only use warn-dirty=false because of this
git --no-pager diff

run() {
    nixos-rebuild \
        switch \
        --sudo \
        --option warn-dirty false \
        --print-build-logs \
        --flake .# \
        "$@"
}

if which nom >/dev/null; then
    run --log-format internal-json \
        "$@" \
    |& nom --json
else
    run "$@"
fi
