56 lines
1.5 KiB
Bash
56 lines
1.5 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
FLAKE='/etc/nixos'
|
|
|
|
function nixos-update() {
|
|
sudo nix flake update --flake $FLAKE
|
|
}
|
|
|
|
function nixos-change-immediate() {
|
|
sudo nixos-rebuild switch --flake $FLAKE
|
|
}
|
|
|
|
function nix-shell-cwd() {
|
|
if [ -f shell.nix ] && [ -z "$IN_NIX_SHELL" ]; then
|
|
echo "Entering nix-shell for $(pwd)"
|
|
nix-shell --command zsh
|
|
elif [ -f default.nix ] && [ -z "$IN_NIX_SHELL" ];then
|
|
echo "Using default.nix for nix-shell in $(pwd)"
|
|
nix-shell -p '(import ./default.nix { pkgs = import <nixpkgs> {}; })'
|
|
fi
|
|
}
|
|
|
|
function nix-list-applications (){
|
|
echo "From: /run/current-system/sw/share/applications"
|
|
ll /run/current-system/sw/share/applications
|
|
}
|
|
|
|
function nixos-gens() {
|
|
local profile="/nix/var/nix/profiles/system"
|
|
|
|
case "$1" in
|
|
help|-h|--help|"")
|
|
echo "Usage: nixos-gens [command]"
|
|
echo
|
|
echo "Commands:"
|
|
echo " help Show this help message"
|
|
echo " list List system generations"
|
|
echo " delete [N] Delete old generations, keeping the last N (default: 5)"
|
|
;;
|
|
list)
|
|
sudo nix-env --list-generations --profile "$profile"
|
|
;;
|
|
delete)
|
|
local keep="${2:-5}"
|
|
echo "Deleting old generations, keeping the last $keep..."
|
|
sudo nix-env --delete-generations +$keep --profile "$profile"
|
|
;;
|
|
*)
|
|
echo "Unknown command: $1"
|
|
echo "Use 'nixos-gens help' for usage information."
|
|
return 1
|
|
;;
|
|
esac
|
|
}
|
|
|