mirror of
https://github.com/Cian-H/My_NixOS_Config.git
synced 2026-04-29 19:01:45 +01:00
Fixed bugs and improved justfile UX
This commit is contained in:
@@ -10,11 +10,15 @@ default:
|
||||
|
||||
_git-sync:
|
||||
@if [ -n "$(git status --porcelain)" ]; then \
|
||||
echo ">> Error: Git working directory is not clean. Stash or commit your changes first."; \
|
||||
exit 1; \
|
||||
echo ">> Stashing local changes..."; \
|
||||
git stash; \
|
||||
git pull --ff-only --recurse-submodules; \
|
||||
git submodule update --remote --recursive; \
|
||||
git stash pop; \
|
||||
else \
|
||||
git pull --ff-only --recurse-submodules; \
|
||||
git submodule update --remote --recursive; \
|
||||
fi
|
||||
git pull --ff-only --recurse-submodules
|
||||
git submodule update --remote --recursive
|
||||
|
||||
_flake-update:
|
||||
nix flake update
|
||||
@@ -83,6 +87,10 @@ repl:
|
||||
# Fully update the system, home-manager, and flatpaks
|
||||
update: prebuild _update-root _update-home update-flatpaks
|
||||
|
||||
# Preview system changes without activating them
|
||||
dry-run: prebuild
|
||||
sudo nixos-rebuild dry-activate --flake .?submodules=1#$(hostname)
|
||||
|
||||
# Run Nix and Flatpak garbage collection. Optionally specify age (e.g., 'just cleanup 7d')
|
||||
cleanup days="":
|
||||
@if [ -n "{{days}}" ]; then \
|
||||
|
||||
@@ -35,7 +35,7 @@ def clone_repository(repo_url: str, target_dir: str):
|
||||
"""Clone the configuration repository and enter the directory."""
|
||||
print(f">> Cloning {repo_url} into {target_dir}...")
|
||||
try:
|
||||
subprocess.run(["git", "clone", repo_url, target_dir], check=True)
|
||||
subprocess.run(["git", "clone", "--recursive", repo_url, target_dir], check=True)
|
||||
except subprocess.CalledProcessError:
|
||||
print("Error: Failed to clone repository.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
+8
-4
@@ -5,21 +5,24 @@ from pathlib import Path
|
||||
import mimetypes
|
||||
|
||||
|
||||
def is_text_file(filepath):
|
||||
def is_text_file(filepath: str):
|
||||
mime_type, _ = mimetypes.guess_type(filepath)
|
||||
if mime_type:
|
||||
return mime_type.startswith("text/")
|
||||
|
||||
try:
|
||||
with open(filepath, "tr") as f:
|
||||
f.read(1024)
|
||||
with open(filepath, "rb") as f:
|
||||
chunk = f.read(1024)
|
||||
if b"\0" in chunk:
|
||||
return False # Null bytes usually mean binary
|
||||
return True
|
||||
except (UnicodeDecodeError, IsADirectoryError):
|
||||
except IsADirectoryError:
|
||||
return False
|
||||
|
||||
|
||||
app = typer.Typer()
|
||||
|
||||
|
||||
@app.command()
|
||||
def edit(target: Path = typer.Argument(..., help="File or directory to edit")):
|
||||
if not target.exists():
|
||||
@@ -35,5 +38,6 @@ def edit(target: Path = typer.Argument(..., help="File or directory to edit")):
|
||||
else:
|
||||
subprocess.run(["heh", str(target)])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app()
|
||||
|
||||
+17
-8
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env bb
|
||||
|
||||
(require '[babashka.cli :as cli]
|
||||
'[babashka.fs :as fs]
|
||||
'[babashka.process :refer [shell]]
|
||||
'[clojure.string :as str])
|
||||
|
||||
@@ -12,7 +13,7 @@
|
||||
|
||||
(def cli-spec
|
||||
{:spec {:home {:coerce :boolean :desc "Edit home-manager config instead of NixOS config"}
|
||||
:sys {:desc "Specify system (defaults to current hostname)"} ; Removed :default from spec
|
||||
:sys {:desc "Specify system (defaults to current hostname)"}
|
||||
:user {:default (System/getProperty "user.name")
|
||||
:desc "Specify user (defaults to current user)"}
|
||||
:update {:coerce :boolean :default true
|
||||
@@ -34,11 +35,19 @@
|
||||
(str "home-manager/" sys "/packages.nix")
|
||||
(str "nixos/" sys "/packages.nix"))]
|
||||
|
||||
(println ">> Editing" target "...")
|
||||
(shell "just" "edit" target)
|
||||
|
||||
(if (:update opts)
|
||||
(if-not (fs/exists? target)
|
||||
(do
|
||||
(println ">> Applying updates...")
|
||||
(shell "just" "quick-update"))
|
||||
(println ">> Skipping update (no-update provided)."))))
|
||||
(binding [*out* *err*]
|
||||
(println (str ">> Error: Target file does not exist: " target))
|
||||
(println ">> Please ensure this system profile has been bootstrapped or configured first."))
|
||||
(System/exit 1))
|
||||
|
||||
(do
|
||||
(println ">> Editing" target "...")
|
||||
(shell "just" "edit" target)
|
||||
|
||||
(if (:update opts)
|
||||
(do
|
||||
(println ">> Applying updates...")
|
||||
(shell "just" "quick-update"))
|
||||
(println ">> Skipping update (no-update provided)."))))))
|
||||
|
||||
Reference in New Issue
Block a user