From 8ac7fd4862a67982265e2e640d7fb0fce76c7a0c Mon Sep 17 00:00:00 2001 From: Prouk Date: Sat, 10 Oct 2026 23:58:13 +0200 Subject: [PATCH] added some utilities and going to nh --- flake.lock | 26 +++++----- home/packages/development.nix | 1 + home/packages/system.nix | 1 + home/shell.nix | 8 +++ justfile | 96 ++++++++++++++++++++--------------- nixos/default.nix | 1 + nixos/programs/nh.nix | 9 ++++ nixos/system/users.nix | 6 ++- 8 files changed, 92 insertions(+), 56 deletions(-) create mode 100644 nixos/programs/nh.nix diff --git a/flake.lock b/flake.lock index dedd798..da1d85a 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1790955005, - "narHash": "sha256-EEQKUylD8zuRTmDFX4rbwsHQ+iZhqqOldYcFN8SLcE0=", + "lastModified": 1791306979, + "narHash": "sha256-KuLePuhwJM9NLt/gTLHzXaOoSZKGoB3m7NfXjiQ98HY=", "owner": "nix-community", "repo": "home-manager", - "rev": "0560d64401a6d5370732a69d08bc4a6b135962d9", + "rev": "fae6e9e42c3b762ab47635cddcfaf6f52374a61b", "type": "github" }, "original": { @@ -22,11 +22,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1790822859, - "narHash": "sha256-VBA0QerzzmL+4wxgtwiCdiLwLpJg2/9xOxhgO3BRJQA=", - "rev": "c59305bab2065cfecc4944690d9eedbb56f3a9fa", + "lastModified": 1791260994, + "narHash": "sha256-MFBjw66d4h06MvpW6lIl7RwarLteD0sk859CncGwb1Q=", + "rev": "151fa4e8ddfdd8dd25d945ad94ed54a13de9f6e4", "type": "tarball", - "url": "https://releases.nixos.org/nixos/unstable/nixos-26.11pre1083223.c59305bab206/nixexprs.tar.zst" + "url": "https://releases.nixos.org/nixos/unstable/nixos-26.11pre1086391.151fa4e8ddfd/nixexprs.tar.zst" }, "original": { "id": "nixpkgs", @@ -71,11 +71,11 @@ "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1790770493, - "narHash": "sha256-sNWVkfOVelr60lWHvEgCWx7Mr/2PcoAN8oOrOk7Yp/g=", + "lastModified": 1791203262, + "narHash": "sha256-+RlIyHipr7BOLsIC9jnpzbkLBsY6XbLhuPinAwJsYjo=", "owner": "Supreeeme", "repo": "xwayland-satellite", - "rev": "b5690b56d749526a05db9b9268d58bf8f700957f", + "rev": "ae88928f7334556d298b8d9552abdf395931931b", "type": "github" }, "original": { @@ -94,11 +94,11 @@ ] }, "locked": { - "lastModified": 1790940304, - "narHash": "sha256-i1W4IdG9PVdSRN1rvTHaqiVqvnRS3+OXgaQa7z5iRDc=", + "lastModified": 1791266850, + "narHash": "sha256-F/scdmE9Y03TfSQWrBHaJWTRTr3rRQBqvJSDgF48g1c=", "owner": "0xc000022070", "repo": "zen-browser-flake", - "rev": "b12abb753335dd3b9ba5ea90d3be799bd9b2dc29", + "rev": "d9e4e25d6ade5d541074045d332d887c044e11f5", "type": "github" }, "original": { diff --git a/home/packages/development.nix b/home/packages/development.nix index 5393d36..38f9d21 100644 --- a/home/packages/development.nix +++ b/home/packages/development.nix @@ -9,6 +9,7 @@ just nil nixd + scrcpy ]; programs.zed-editor = { diff --git a/home/packages/system.nix b/home/packages/system.nix index adc6681..0ee8d82 100644 --- a/home/packages/system.nix +++ b/home/packages/system.nix @@ -4,5 +4,6 @@ btop gparted yazi + unzip ]; } diff --git a/home/shell.nix b/home/shell.nix index b6a4453..526c0e7 100644 --- a/home/shell.nix +++ b/home/shell.nix @@ -1,5 +1,13 @@ { ... }: { + programs.fish = { + enable = true; + # nixpkgs' devenv only ships fish completions, not the auto-loaded hook. + interactiveShellInit = '' + devenv hook fish | source + ''; + }; + programs.bash = { enable = true; bashrcExtra = "eval \"$(devenv hook bash)\"\n"; diff --git a/justfile b/justfile index 35a3fa8..2e847e7 100644 --- a/justfile +++ b/justfile @@ -1,63 +1,75 @@ # Justfile to safely clean up NixOS profiles, keeping only the last 3 generations. +# Uses nh (https://github.com/nix-community/nh) when available, falling back to plain nix commands. + +host := "prouk" +keep := "3" +nh := `command -v nh || true` +hm_profile := env("HOME") / ".local/state/nix/profiles/home-manager" # Default recipe displays the help menu. help: @echo "NixOS Profile Cleanup Utility" @echo "=============================" + @echo "nh: {{ if nh != "" { "found (" + nh + ")" } else { "not found, using plain nix commands" } }}" @echo "Available recipes:" @echo " just dry-run - Safe preview of what will be deleted" - @echo " just clean-system - Clean system generations and update bootloader (requires sudo)" - @echo " just clean-user - Clean current user's profile generations" - @echo " just clean-home-manager - Clean Home Manager generations (if applicable)" - @echo " just clean-all - Clean everything (System, User, and Home Manager)" + @echo " just clean-all - Clean System, User and Home Manager generations (requires sudo)" + @echo " just build - Rebuild and switch the system" + @echo " just update - Update flake inputs" # Dry run to preview changes without deleting anything. dry-run: - @echo "=== [DRY RUN] System Profile ===" - sudo nix-env --profile /nix/var/nix/profiles/system --delete-generations +3 --dry-run - @echo "\n=== [DRY RUN] User Profile ===" - nix-env --delete-generations +3 --dry-run - @echo "\n=== [DRY RUN] Home Manager Profile ===" - @if [ -d "$HOME/.local/state/nix/profiles/home-manager" ]; then \ - nix-env --profile "$HOME/.local/state/nix/profiles/home-manager" --delete-generations +3 --dry-run; \ - elif [ -d "$HOME/.nix-profile" ]; then \ - echo "No Home Manager directory found, but user profile exists."; \ - else \ - echo "No Home Manager profile detected."; \ + #!/usr/bin/env bash + set -euo pipefail + if [ -n "{{ nh }}" ]; then + echo "=== [DRY RUN] All profiles (nh) ===" + nh clean all --keep {{ keep }} --dry + exit 0 + fi + echo "=== [DRY RUN] System Profile ===" + sudo nix-env --profile /nix/var/nix/profiles/system --delete-generations +{{ keep }} --dry-run + echo -e "\n=== [DRY RUN] User Profile ===" + nix-env --delete-generations +{{ keep }} --dry-run + echo -e "\n=== [DRY RUN] Home Manager Profile ===" + if [ -e "{{ hm_profile }}" ]; then + nix-env --profile "{{ hm_profile }}" --delete-generations +{{ keep }} --dry-run + elif [ -d "$HOME/.nix-profile" ]; then + echo "No Home Manager directory found, but user profile exists." + else + echo "No Home Manager profile detected." fi -# Clean system generations (requires sudo). -clean-system: - @echo "--- Cleaning System Profile (SUDO) ---" - sudo nix-env --profile /nix/var/nix/profiles/system --delete-generations +3 - sudo nix-collect-garbage - @echo "--- Updating Bootloader Menu ---" - sudo nixos-rebuild boot --flake .#prouk - -# Clean user generations (no sudo). -clean-user: - @echo "--- Cleaning User Profile ---" - nix-env --delete-generations +3 - nix-collect-garbage - -# Clean Home Manager generations (no sudo). -clean-home-manager: - @echo "--- Cleaning Home Manager Profile ---" - @if [ -d "$HOME/.local/state/nix/profiles/home-manager" ]; then \ - nix-env --profile "$HOME/.local/state/nix/profiles/home-manager" --delete-generations +3; \ - nix-collect-garbage; \ - else \ - echo "No Home Manager profile found. Skipping."; \ +# Clean system, user and Home Manager generations, then update the bootloader (requires sudo). +clean-all: + #!/usr/bin/env bash + set -euo pipefail + if [ -n "{{ nh }}" ]; then + echo "--- Cleaning All Profiles (nh) ---" + nh clean all --keep {{ keep }} + echo "--- Updating Bootloader Menu ---" + nh os boot . --hostname {{ host }} + else + echo "--- Cleaning System Profile (SUDO) ---" + sudo nix-env --profile /nix/var/nix/profiles/system --delete-generations +{{ keep }} + echo "--- Cleaning User Profile ---" + nix-env --delete-generations +{{ keep }} + echo "--- Cleaning Home Manager Profile ---" + if [ -e "{{ hm_profile }}" ]; then + nix-env --profile "{{ hm_profile }}" --delete-generations +{{ keep }} + else + echo "No Home Manager profile found. Skipping." + fi + sudo nix-collect-garbage + nix-collect-garbage + echo "--- Updating Bootloader Menu ---" + sudo nixos-rebuild boot --flake .#{{ host }} fi - -# Clean everything in one go. -clean-all: clean-system clean-user clean-home-manager - @echo "All cleanups successfully completed!" + echo "All cleanups successfully completed!" # Build. build: @echo "--- Rebuilding System ---" - sudo nixos-rebuild switch --flake .#prouk + {{ if nh != "" { "nh os switch . --hostname " + host } else { "sudo nixos-rebuild switch --flake .#" + host } }} # Update flake. update: diff --git a/nixos/default.nix b/nixos/default.nix index ec2e4a5..66d8747 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -27,6 +27,7 @@ # Programs ./programs/gaming.nix ./programs/obs.nix + ./programs/nh.nix ]; # NO TOUCHY diff --git a/nixos/programs/nh.nix b/nixos/programs/nh.nix new file mode 100644 index 0000000..137e3f0 --- /dev/null +++ b/nixos/programs/nh.nix @@ -0,0 +1,9 @@ +{ ... }: +{ + # nh: nicer frontend for nixos-rebuild / nix-collect-garbage. + # Cleanup stays on nix.gc (see system/nix.nix) to avoid two GC timers. + programs.nh = { + enable = true; + flake = "/home/prouk/flake"; + }; +} diff --git a/nixos/system/users.nix b/nixos/system/users.nix index a32b076..c137b24 100644 --- a/nixos/system/users.nix +++ b/nixos/system/users.nix @@ -1,7 +1,11 @@ -{ ... }: +{ pkgs, ... }: { + # Required so fish is registered in /etc/shells and gets the NixOS environment. + programs.fish.enable = true; + users.users.prouk = { isNormalUser = true; extraGroups = [ "wheel" ]; + shell = pkgs.fish; }; }