Files
nixos-config/os.sh
Morten Olsen c0aeb8ec57 flake.lock: Update
Flake lock file updates:

• Updated input 'home-manager':
    'github:nix-community/home-manager/d9b88b43524db1591fb3d9410a21428198d75d49' (2023-09-13)
  → 'github:nix-community/home-manager/408ba13188ff9ce309fa2bdd2f81287d79773b00' (2023-09-20)
• Updated input 'home-manager/nixpkgs':
    'github:NixOS/nixpkgs/3a2786eea085f040a66ecde1bc3ddc7099f6dbeb' (2023-09-11)
  → 'github:NixOS/nixpkgs/970a59bd19eff3752ce552935687100c46e820a5' (2023-09-17)
• Updated input 'nixos-hardware':
    'github:NixOS/nixos-hardware/570256327eb6ca6f7bebe8d93af49459092a0c43' (2023-09-14)
  → 'github:NixOS/nixos-hardware/cb4dc98f776ddb6af165e6f06b2902efe31ca67a' (2023-09-19)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/ace5093e36ab1e95cb9463863491bee90d5a4183' (2023-09-15)
  → 'github:NixOS/nixpkgs/5ba549eafcf3e33405e5f66decd1a72356632b96' (2023-09-19)
• Updated input 'nur':
    'github:nix-community/NUR/9b70f21fd41d3b96580e7ca4a3d1c29e87bdab36' (2023-09-15)
  → 'github:nix-community/NUR/41797d553c8bc067fa3db0681db940b135590ab5' (2023-09-21)
2023-09-21 23:10:39 +02:00

64 lines
1003 B
Bash
Executable File

function help() {
echo "Usage: $0 {apply|upgrade|init} [name]"
exit 1
}
if [ -z "$1" ]; then
help
fi
ACTION=$1; shift
LOCATION=$PWD
function apply() {
name=$1
if [ -z "$name" ]; then
sudo nixos-rebuild switch --flake $LOCATION
else
sudo nixos-rebuild switch --flake "$LOCATION#$name"
fi
}
function upgrade() {
if git -C "$LOCATION" diff-index --quiet HEAD --; then
nix flake update --commit-lock-file "$LOCATION"
apply $1
cleanup
else
echo "Error: git working tree is dirty"
exit 1
fi
}
function cleanup() {
amount=${1:-"7d"}
nix-env --delete-generations "$amount"
nix-collect-garbage -d
nix-store --optimise
nix-store --verify --check-contents --repair
}
function init() {
mkdir -p "$LOCATION"
git clone "https://github.com/morten-olsen/home-server.git" "$LOCATION"
}
case $ACTION in
init)
init $1
;;
apply)
apply $1
;;
upgrade)
upgrade $1
;;
cleanup)
cleanup $1
;;
*)
help
;;
esac