mirror of
https://github.com/itme-brain/nixos.git
synced 2026-03-23 16:29:42 -04:00
updated justfile
This commit is contained in:
parent
0ec643d3c6
commit
9d0dcf9305
1 changed files with 139 additions and 16 deletions
155
justfile
155
justfile
|
|
@ -14,7 +14,18 @@ _validate SYSTEM:
|
||||||
*) echo "Error: Unknown system '{{SYSTEM}}'. Use one of: {{VALID_SYSTEMS}}"; exit 1 ;;
|
*) echo "Error: Unknown system '{{SYSTEM}}'. Use one of: {{VALID_SYSTEMS}}"; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# Helper to parse submodules from .gitmodules
|
||||||
|
[private]
|
||||||
|
_subs_init := '''
|
||||||
|
declare -A SUBS
|
||||||
|
while read -r key path; do
|
||||||
|
name="${key#submodule.}"; name="${name%.path}"
|
||||||
|
SUBS[$name]="$path"
|
||||||
|
done < <(git config -f .gitmodules --get-regexp 'submodule\..*\.path')
|
||||||
|
'''
|
||||||
|
|
||||||
# Clean up build artifacts
|
# Clean up build artifacts
|
||||||
|
[group('nix')]
|
||||||
clean:
|
clean:
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
@ -24,22 +35,26 @@ clean:
|
||||||
echo "Done"
|
echo "Done"
|
||||||
|
|
||||||
# Output what derivations will be built
|
# Output what derivations will be built
|
||||||
|
[group('nix')]
|
||||||
out SYSTEM="desktop": (_validate SYSTEM)
|
out SYSTEM="desktop": (_validate SYSTEM)
|
||||||
@echo "Outputting derivations to be built for {{SYSTEM}}..."
|
@echo "Outputting derivations to be built for {{SYSTEM}}..."
|
||||||
@nix build --dry-run .#nixosConfigurations."{{SYSTEM}}".config.system.build.toplevel -L
|
@nix build --dry-run .#nixosConfigurations."{{SYSTEM}}".config.system.build.toplevel -L
|
||||||
|
|
||||||
# Test switch into the next generation
|
# Test switch into the next generation
|
||||||
|
[group('nixos')]
|
||||||
test SYSTEM="desktop": (_validate SYSTEM)
|
test SYSTEM="desktop": (_validate SYSTEM)
|
||||||
@echo "Testing switching to next NixOS generation for {{SYSTEM}}..."
|
@echo "Testing switching to next NixOS generation for {{SYSTEM}}..."
|
||||||
@sudo nixos-rebuild test --flake .#{{SYSTEM}}
|
@sudo nixos-rebuild test --flake .#{{SYSTEM}}
|
||||||
|
|
||||||
# Build the nix expression and hydrate the results directory
|
# Build the nix expression and hydrate the results directory
|
||||||
|
[group('nix')]
|
||||||
build SYSTEM="desktop": (_validate SYSTEM)
|
build SYSTEM="desktop": (_validate SYSTEM)
|
||||||
@echo "Building NixOS configuration for {{SYSTEM}}..."
|
@echo "Building NixOS configuration for {{SYSTEM}}..."
|
||||||
@nix build .#nixosConfigurations."{{SYSTEM}}".config.system.build.toplevel -L
|
@nix build .#nixosConfigurations."{{SYSTEM}}".config.system.build.toplevel -L
|
||||||
@echo -e "\033[32mBuild success - result directory hydrated\033[0m"
|
@echo -e "\033[32mBuild success - result directory hydrated\033[0m"
|
||||||
|
|
||||||
# Deploy a vm of the defined system
|
# Deploy a vm of the defined system
|
||||||
|
[group('nixos')]
|
||||||
vm SYSTEM: (_validate SYSTEM)
|
vm SYSTEM: (_validate SYSTEM)
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
@ -53,48 +68,39 @@ vm SYSTEM: (_validate SYSTEM)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# grep nixpkgs for PKG
|
# grep nixpkgs for PKG
|
||||||
|
[group('nix')]
|
||||||
search PKG:
|
search PKG:
|
||||||
nix search nixpkgs {{PKG}}
|
nix search nixpkgs {{PKG}}
|
||||||
|
|
||||||
# Open nixos packages in the browser
|
# Open nixos packages in the browser
|
||||||
|
[group('nix')]
|
||||||
pkgs:
|
pkgs:
|
||||||
@xdg-open https://search.nixos.org/packages
|
@xdg-open https://search.nixos.org/packages
|
||||||
|
|
||||||
# Open nixos options in the browser
|
# Open nixos options in the browser
|
||||||
|
[group('nix')]
|
||||||
options:
|
options:
|
||||||
@xdg-open https://search.nixos.org/options
|
@xdg-open https://search.nixos.org/options
|
||||||
|
|
||||||
# NixOS-rebuild switch for the current system
|
# NixOS-rebuild switch for the current system
|
||||||
|
[group('nixos')]
|
||||||
switch:
|
switch:
|
||||||
@echo -e "\033[32m->> Switching to next generation ->>\033[0m"
|
@echo -e "\033[32m->> Switching to next generation ->>\033[0m"
|
||||||
@sudo nixos-rebuild switch --flake .#{{SYSTEM}}
|
@sudo nixos-rebuild switch --flake .#{{SYSTEM}}
|
||||||
|
|
||||||
# Rollback to previous generation
|
# Rollback to previous generation
|
||||||
|
[group('nixos')]
|
||||||
rollback:
|
rollback:
|
||||||
@sudo nixos-rebuild switch --rollback
|
@sudo nixos-rebuild switch --rollback
|
||||||
|
|
||||||
# NixOS-rebuild boot for the current system
|
# NixOS-rebuild boot for the current system
|
||||||
|
[group('nixos')]
|
||||||
boot:
|
boot:
|
||||||
@echo -e "\033[34m->> Reboot to new generation ->>\033[0m"
|
@echo -e "\033[34m->> Reboot to new generation ->>\033[0m"
|
||||||
@sudo nixos-rebuild boot --flake .#{{SYSTEM}}
|
@sudo nixos-rebuild boot --flake .#{{SYSTEM}}
|
||||||
|
|
||||||
# Commit all changes and push to upstream
|
|
||||||
gh COMMIT_MESSAGE:
|
|
||||||
#!/usr/bin/env bash
|
|
||||||
set -euo pipefail
|
|
||||||
git add -A
|
|
||||||
git commit -m "{{COMMIT_MESSAGE}}"
|
|
||||||
git push
|
|
||||||
|
|
||||||
# List available disks for installation
|
|
||||||
disks:
|
|
||||||
@echo "Available disks:"
|
|
||||||
@lsblk -d -o NAME,SIZE,MODEL
|
|
||||||
@echo ""
|
|
||||||
@echo "Disk IDs (use these for install):"
|
|
||||||
@ls /dev/disk/by-id/ | grep -E '^(ata|nvme|scsi|usb)' | grep -v 'part' || true
|
|
||||||
|
|
||||||
# Install NixOS from live USB (interactive disk selection)
|
# Install NixOS from live USB (interactive disk selection)
|
||||||
|
[group('nixos')]
|
||||||
install SYSTEM:
|
install SYSTEM:
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
@ -164,7 +170,124 @@ install SYSTEM:
|
||||||
|
|
||||||
echo -e "\033[32mDone! Reboot to start NixOS.\033[0m"
|
echo -e "\033[32mDone! Reboot to start NixOS.\033[0m"
|
||||||
|
|
||||||
|
# Commit all changes and push to upstream
|
||||||
|
[group('git')]
|
||||||
|
gh COMMIT_MESSAGE:
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
git add -A
|
||||||
|
git commit -m "{{COMMIT_MESSAGE}}"
|
||||||
|
git push
|
||||||
|
|
||||||
|
# Show status of submodules with changes
|
||||||
|
[group('submodule')]
|
||||||
|
sstatus:
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
{{_subs_init}}
|
||||||
|
for name in "${!SUBS[@]}"; do
|
||||||
|
status=$(git -C "${SUBS[$name]}" status -s)
|
||||||
|
[[ -n "$status" ]] && echo -e "\033[34m$name:\033[0m" && echo "$status"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Pull all submodules and parent
|
||||||
|
[group('submodule')]
|
||||||
|
spull:
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
{{_subs_init}}
|
||||||
|
git pull
|
||||||
|
for name in "${!SUBS[@]}"; do
|
||||||
|
echo -e "\033[34m$name:\033[0m"
|
||||||
|
git -C "${SUBS[$name]}" pull
|
||||||
|
done
|
||||||
|
|
||||||
|
# Push submodules and parent
|
||||||
|
[group('submodule')]
|
||||||
|
spush NAME="":
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
{{_subs_init}}
|
||||||
|
if [[ -n "{{NAME}}" ]]; then
|
||||||
|
path="${SUBS[{{NAME}}]:-}"
|
||||||
|
[[ -z "$path" ]] && echo "Unknown: {{NAME}}. Available: ${!SUBS[*]}" && exit 1
|
||||||
|
git -C "$path" push
|
||||||
|
else
|
||||||
|
for path in "${SUBS[@]}"; do git -C "$path" push; done
|
||||||
|
fi
|
||||||
|
git push
|
||||||
|
|
||||||
|
# Commit submodule changes and update parent
|
||||||
|
[group('submodule')]
|
||||||
|
scommit NAME="":
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
{{_subs_init}}
|
||||||
|
MSGS=()
|
||||||
|
|
||||||
|
commit_sub() {
|
||||||
|
local name="$1" path="$2"
|
||||||
|
[[ -z "$(git -C "$path" status -s)" ]] && return 0
|
||||||
|
echo -e "\033[34m$name:\033[0m"
|
||||||
|
git -C "$path" status -s
|
||||||
|
read -p "Commit message: " MSG
|
||||||
|
[[ -z "$MSG" ]] && return 0
|
||||||
|
git -C "$path" add -A && git -C "$path" commit -m "$MSG"
|
||||||
|
git add "$path"
|
||||||
|
MSGS+=("$name: $MSG")
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ -n "{{NAME}}" ]]; then
|
||||||
|
path="${SUBS[{{NAME}}]:-}"
|
||||||
|
[[ -z "$path" ]] && echo "Unknown: {{NAME}}. Available: ${!SUBS[*]}" && exit 1
|
||||||
|
commit_sub "{{NAME}}" "$path"
|
||||||
|
else
|
||||||
|
for name in "${!SUBS[@]}"; do commit_sub "$name" "${SUBS[$name]}"; done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! git diff --cached --quiet; then
|
||||||
|
COMMIT_MSG="updated submodules"$'\n'
|
||||||
|
for m in "${MSGS[@]}"; do COMMIT_MSG+="- $m"$'\n'; done
|
||||||
|
git commit -m "$COMMIT_MSG"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Commit and push submodules + parent
|
||||||
|
[group('submodule')]
|
||||||
|
ssync NAME="":
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
{{_subs_init}}
|
||||||
|
MSGS=()
|
||||||
|
|
||||||
|
sync_sub() {
|
||||||
|
local name="$1" path="$2"
|
||||||
|
[[ -z "$(git -C "$path" status -s)" ]] && return 0
|
||||||
|
echo -e "\033[34m$name:\033[0m"
|
||||||
|
git -C "$path" status -s
|
||||||
|
read -p "Commit message: " MSG
|
||||||
|
[[ -z "$MSG" ]] && return 0
|
||||||
|
git -C "$path" add -A && git -C "$path" commit -m "$MSG"
|
||||||
|
git -C "$path" push
|
||||||
|
git add "$path"
|
||||||
|
MSGS+=("$name: $MSG")
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ -n "{{NAME}}" ]]; then
|
||||||
|
path="${SUBS[{{NAME}}]:-}"
|
||||||
|
[[ -z "$path" ]] && echo "Unknown: {{NAME}}. Available: ${!SUBS[*]}" && exit 1
|
||||||
|
sync_sub "{{NAME}}" "$path"
|
||||||
|
else
|
||||||
|
for name in "${!SUBS[@]}"; do sync_sub "$name" "${SUBS[$name]}"; done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! git diff --cached --quiet; then
|
||||||
|
COMMIT_MSG="updated submodules"$'\n'
|
||||||
|
for m in "${MSGS[@]}"; do COMMIT_MSG+="- $m"$'\n'; done
|
||||||
|
git commit -m "$COMMIT_MSG"
|
||||||
|
fi
|
||||||
|
git push
|
||||||
|
|
||||||
# Fetch resources and compute sha256 hash
|
# Fetch resources and compute sha256 hash
|
||||||
|
[group('nix')]
|
||||||
hash URL:
|
hash URL:
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue