1
0
Fork 0

Replace update script with nh

This commit is contained in:
Aires 2024-04-20 01:01:17 -04:00
parent 99a2022185
commit 429017f601
5 changed files with 26 additions and 91 deletions

View file

@ -117,11 +117,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1713391096, "lastModified": 1713566308,
"narHash": "sha256-5xkzsy+ILgQlmvDDipL5xqAehnjWBenAQXV4/NLg2dE=", "narHash": "sha256-7Y91t8pheIzjJveUMAPyeh5NOq5F49Nq4Hl2532QpJs=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "f46814ec7cbef9c2aef18ca1cbe89f2bb1e8c394", "rev": "057117a401a34259c9615ce62218aea7afdee4d3",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -174,11 +174,11 @@
}, },
"nixos-hardware": { "nixos-hardware": {
"locked": { "locked": {
"lastModified": 1713441075, "lastModified": 1713521961,
"narHash": "sha256-3GGeFsEO8ivD+TcDEqe4s/d0VLvMYGNDGtx0ZnBxkUs=", "narHash": "sha256-EwR8wW9AqJhSIY+0oxWRybUZ32BVKuZ9bjlRh8SJvQ8=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixos-hardware", "repo": "nixos-hardware",
"rev": "6f976e53752e5b9ab08f9a3b1b0b9c67815c9754", "rev": "5d48925b815fd202781bfae8fb6f45c07112fdb2",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -222,11 +222,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1713248628, "lastModified": 1713537308,
"narHash": "sha256-NLznXB5AOnniUtZsyy/aPWOk8ussTuePp2acb9U+ISA=", "narHash": "sha256-XtTSSIB2DA6tOv+l0FhvfDMiyCmhoRbNB+0SeInZkbk=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "5672bc9dbf9d88246ddab5ac454e82318d094bb8", "rev": "5c24cf2f0a12ad855f444c30b2421d044120c66f",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -7,17 +7,9 @@ let
ref = "main"; ref = "main";
rev = "55fc814d477d956ab885e157f24c2d43f433dc7a"; rev = "55fc814d477d956ab885e157f24c2d43f433dc7a";
}; };
# Install upgrade script
nixos-upgrade = pkgs.writeShellScriptBin "nixos-upgrade" (builtins.readFile ./nixos-upgrade.sh);
in{ in{
imports = [ imports = [
../../modules ../../modules
"${nix-secrets}/default.nix" "${nix-secrets}/default.nix"
]; ];
# Add upgrade script
environment.systemPackages = [
nixos-upgrade
];
} }

View file

@ -1,63 +0,0 @@
#!/usr/bin/env bash
# Update NixOS system while printing out the different packages to install.
# Inspiration: https://blog.tjll.net/previewing-nixos-system-updates/
set -e
OPERATION="boot" # Which update method to use. Defaults to "boot", which applies updates on reboot.
AUTOACCEPT=false # Whether to automatically apply the update or ask for permission.
function usage() {
echo "Usage: nixos-upgrade.sh [ -y | --auto-accept ] [-o | --operation]"
echo "Options:"
echo " -h | --help Show this help screen."
echo " -y | --auto-accept Automatically approve pending changes."
echo " -o | --operation Which update operation to perform (switch, boot, etc.). Defaults to boot."
exit 2
}
while [[ $# -gt 0 ]]; do
case "$1" in
-y|-Y|--auto-accept)
AUTOACCEPT=true
shift
;;
-o|-O|--operation)
OPERATION=$2
shift
;;
-h|--help)
usage
exit
;;
*)
#echo "Unknown argument $1"
#exit 1
break
;;
esac
done
echo "Using installation mode: $OPERATION"
cd ~/Development/nix-configuration
nix flake update
nixos-rebuild build --flake .
PACKAGE_UPDATES=$(nix store diff-closures /run/current-system ./result | awk '/[0-9] →|→ [0-9]/ && !/nixos/' || echo)
if [ "$PACKAGE_UPDATES" ]; then
echo "Packages to update: "
echo $PACKAGE_UPDATES
fi
if [ $AUTOACCEPT == false ]; then
read -p "Continue with upgrade (y/n) ? " choice
case "$choice" in
y|Y|yes ) echo "Running nixos-rebuild $OPERATION :";;
n|N|no ) echo "Upgrade cancelled." && exit;;
* ) echo "Invalid option. Upgrade cancelled." && exit;;
esac
fi
sudo nixos-rebuild $OPERATION --flake .
echo "Updating Flatpaks:"
flatpak update

View file

@ -18,10 +18,12 @@ with lib;
nano nano
p7zip p7zip
fastfetch fastfetch
nh # Nix Helper: https://github.com/viperML/nh
]; ];
# Set default editor to nano variables = {
variables.EDITOR = "nano"; EDITOR = "nano"; # Set default editor to nano
};
# System configuration file overrides # System configuration file overrides
etc = { etc = {
@ -78,13 +80,6 @@ with lib;
# Enable periodic nix store optimization # Enable periodic nix store optimization
optimise.automatic = true; optimise.automatic = true;
# Enable garbage collection
gc = {
automatic = true;
dates = "daily";
options = "--delete-older-than 7d";
};
# Configure NixOS to use the same software channel as Flakes # Configure NixOS to use the same software channel as Flakes
registry = lib.mapAttrs (_: value: { flake = value; }) inputs; registry = lib.mapAttrs (_: value: { flake = value; }) inputs;
nixPath = lib.mapAttrsToList (key: value: "${key}=${value.to.path}") config.nix.registry; nixPath = lib.mapAttrsToList (key: value: "${key}=${value.to.path}") config.nix.registry;
@ -103,6 +98,18 @@ with lib;
set softwrap set softwrap
''; '';
}; };
nh = {
enable = true;
flake = "/home/aires/Development/nix-configuration";
# Alternative garbage collection system to nix.gc.automatic
clean = {
enable = true;
dates = "daily";
extraArgs = "--keep-since 7d --keep 10"; # Keep the last 10 entries
};
};
}; };
services = { services = {

View file

@ -86,9 +86,8 @@ with lib;
theme = "gentoo"; theme = "gentoo";
}; };
shellAliases = { shellAliases = {
dry-build = "cd ~/Development/nix-configuration && nix flake update && nixos-rebuild dry-build --flake .";
update = "upgrade"; update = "upgrade";
upgrade = "cd ~/Development/nix-configuration && nixos-upgrade"; upgrade = "nh os boot --update --ask";
protontricks = "flatpak run com.github.Matoking.protontricks"; protontricks = "flatpak run com.github.Matoking.protontricks";
please = "sudo"; please = "sudo";
}; };