Skip to content

Instantly share code, notes, and snippets.

@stigtsp
Last active September 25, 2023 18:11
Show Gist options
  • Save stigtsp/bc6e83945d4d673a1b3956c6bf0b230e to your computer and use it in GitHub Desktop.
Save stigtsp/bc6e83945d4d673a1b3956c6bf0b230e to your computer and use it in GitHub Desktop.
script for updating all the nixos stuffs
#!/usr/bin/env bash
set -e
function ver2rev {
echo $1 | perl -pe 's/.+\.(.+?)"?$/$1/g'
}
nixver=$(nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version')
echo -e "\n\e[32m[*] Updating channels ($USER)\e[39m"
nix-channel --update
echo -e "\n\e[32m[*] Updating channels (sudo)\e[39m"
sudo nix-channel --update
nixver_new=$(nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version')
#nixver_new=master
cd ~/nixos/ && nix flake update
if [ "$nixver" = "$nixver_new" ]; then
echo -e "\n\e[32m[*] nixpkgs version: $nixver\e[39m"
echo -e "\e[32m commit: https://github.com/NixOS/nixpkgs/commits/"$(ver2rev $nixver)"\e[39m"
else
echo -e "\n\e[96m[!] nixpkgs version: $nixver -> $nixver_new\e[39m"
echo -e "\e[96m compare changes: https://github.com/NixOS/nixpkgs/compare/"$(ver2rev $nixver)...$(ver2rev $nixver_new)"\e[39m"
fi
echo -e "\n\e[32m[*] Updating nix-env ($USER)\e[39m"
nix-env -u
echo -e "\n\e[32m[*] Updating NixOS (sudo)\e[39m"
sudo nixos-rebuild switch -j auto
echo -e "\n\e[32m[*] Running nix-collect-garbage --delete-older-than 7d\e[39m"
sudo nix-collect-garbage --delete-older-than 7d
echo -e "\n\e[32m[*] Running nix store optimize\e[39m"
sudo nix store optimise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment