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