1
0
Fork 0

add multiple envs for packages

This commit is contained in:
cătălin 2026-01-05 15:15:02 +01:00
commit 546c5170d7
No known key found for this signature in database
11 changed files with 733 additions and 75 deletions

View file

@ -77,8 +77,71 @@ function gur
end
function nix_upgrade
sudo nix flake update --flake /home/catalin/.dotfiles/nix/
sudo nixos-rebuild switch --flake /home/catalin/.dotfiles/nix/ --upgrade
# Upgrade this system based on hostname matching the flake host.
# Works on both NixOS (nixos-rebuild) and non-NixOS (Home Manager).
# Usage: nix_upgrade [host-override]
set -l flake_path /home/catalin/.dotfiles/nix
# Determine host either from arg or from the machine hostname
if set -q argv[1]
set -l host $argv[1]
else
set -l host (hostname -s)
if test $status -ne 0 -o -z "$host"
set host (hostname)
end
end
if not test -f $flake_path/flake.nix
echo "Error: flake not found at $flake_path/flake.nix"
return 1
end
# Detect if we are on NixOS
set -l is_nixos 0
if test -f /etc/NIXOS
set is_nixos 1
else if type -q nixos-version
set is_nixos 1
end
echo "Updating inputs for flake: $flake_path"
# On non-NixOS this usually doesn't require sudo; on NixOS it might.
if test $is_nixos -eq 1
sudo nix flake update --flake $flake_path
else
nix flake update --flake $flake_path
end
if test $is_nixos -eq 1
# NixOS path: verify host exists under nixosConfigurations (heuristic)
if not grep -Eq "^[[:space:]]*$host[[:space:]]*=[[:space:]]*lib\\.nixosSystem" $flake_path/flake.nix
echo "Error: host '$host' not found in nixosConfigurations in $flake_path/flake.nix."
echo " Pass an explicit host: nix_upgrade <host>"
return 1
end
echo "Rebuilding NixOS for host: $host"
sudo nixos-rebuild switch --flake $flake_path#$host --upgrade
else
# non-NixOS path: try Home Manager via flake's homeConfigurations
if not grep -q "homeConfigurations" $flake_path/flake.nix
echo "Error: no homeConfigurations found in flake; cannot upgrade on non-NixOS."
return 1
end
# Best-effort heuristic that the host exists as a home configuration
if not grep -Eq "^[[:space:]]*$host[[:space:]]*=" $flake_path/flake.nix
echo "Warning: host '$host' not explicitly found; attempting Home Manager switch anyway."
end
echo "Rebuilding Home Manager for host: $host"
if type -q home-manager
home-manager switch --flake $flake_path#$host
else
# Fallback: use nix to run HM
nix run github:nix-community/home-manager -- switch --flake $flake_path#$host
end
end
end
function delete_line