diff --git a/README.md b/README.md index 1c0cdf0..2b530dc 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,17 @@ Initialize the submodule with: git submodule update --init --recursive ``` -### Updating Flakes +### Upgrading -This repo uses Flakes. To get the latest packages and update your `flake.lock` file, run this command before `nixos-rebuild`: +This config comes with a script for upgrading the system called `nixos-upgrade.sh`. To run this script, just run `nixos-upgrade` or `upgrade`. -```sh -nix flake update -``` +Running this script does three things: + +1. Update `flake.lock` +2. Build the new closure and list the updates that will be applied +3. (Optionally) Install the new closure + +By default, the script calls `nixos-rebuild boot`. You can change this to switch or any other rebuild operation by passing it as an argument when calling the script, e.g. `nixos-upgrade switch` or `nixos-upgrade test`. ### Applying the configuration @@ -54,16 +58,6 @@ To preview changes in a virtual machine, use this command to create a virtual ma nixos-rebuild build-vm --flake . ``` -### Updating - -`flake.lock` locks the version of any packages/modules used. To update them, run `nix flake update` first: - -```zsh -nix flake update && sudo nixos-rebuild switch --flake . -``` - -Home-manager also installs a ZSH alias, so you can just run `update` or `upgrade` for the same effect. - ## Layout This config uses two systems: Flakes, and Home-manager. diff --git a/flake.lock b/flake.lock index f168a97..9ef9e16 100644 --- a/flake.lock +++ b/flake.lock @@ -117,11 +117,11 @@ ] }, "locked": { - "lastModified": 1711133180, - "narHash": "sha256-WJOahf+6115+GMl3wUfURu8fszuNeJLv9qAWFQl3Vmo=", + "lastModified": 1711625603, + "narHash": "sha256-W+9dfqA9bqUIBV5u7jaIARAzMe3kTq/Hp2SpSVXKRQw=", "owner": "nix-community", "repo": "home-manager", - "rev": "1c2c5e4cabba4c43504ef0f8cc3f3dfa284e2dbb", + "rev": "c0ef0dab55611c676ad7539bf4e41b3ec6fa87d2", "type": "github" }, "original": { @@ -174,11 +174,11 @@ }, "nixos-hardware": { "locked": { - "lastModified": 1711274671, - "narHash": "sha256-19KQXya5VERUXOdeEJJN+zOqtvuE6MV3qTk9Gr4J9Uo=", + "lastModified": 1711352745, + "narHash": "sha256-luvqik+i3HTvCbXQZgB6uggvEcxI9uae0nmrgtXJ17U=", "owner": "NixOS", "repo": "nixos-hardware", - "rev": "7559df1e4af972d5f1de87975b5ef6a8d7559db2", + "rev": "9a763a7acc4cfbb8603bb0231fec3eda864f81c0", "type": "github" }, "original": { @@ -222,11 +222,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1711163522, - "narHash": "sha256-YN/Ciidm+A0fmJPWlHBGvVkcarYWSC+s3NTPk/P+q3c=", + "lastModified": 1711703276, + "narHash": "sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "44d0940ea560dee511026a53f0e2e2cde489b4d4", + "rev": "d8fe5e6c92d0d190646fb9f1056741a229980089", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 70d304c..acc8085 100644 --- a/flake.nix +++ b/flake.nix @@ -21,6 +21,8 @@ url = "github:nix-community/home-manager/master"; inputs.nixpkgs.follows = "nixpkgs"; # Use system packages list where available }; + + # TODO: Add Disko - https://github.com/nix-community/disko }; outputs = inputs@{ self, nixpkgs, lanzaboote, nix-flatpak, home-manager, nixos-hardware, ... }: diff --git a/hosts/common/default.nix b/hosts/common/default.nix index e4634f5..640bed7 100644 --- a/hosts/common/default.nix +++ b/hosts/common/default.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib, pkgs, ... }: let # Fetch secrets # IMPORTANT: Make sure this repo exists on the filesystem first! @@ -7,9 +7,17 @@ let ref = "main"; rev = "55fc814d477d956ab885e157f24c2d43f433dc7a"; }; + + # Install upgrade script + nixos-upgrade = pkgs.writeShellScriptBin "start-haven" (builtins.readFile ./nixos-upgrade.sh); in{ imports = [ ../../modules "${nix-secrets}/default.nix" ]; + + # Add upgrade script + environment.systemPackages = [ + nixos-upgrade + ]; } diff --git a/hosts/common/nixos-upgrade.sh b/hosts/common/nixos-upgrade.sh new file mode 100755 index 0000000..da80d5e --- /dev/null +++ b/hosts/common/nixos-upgrade.sh @@ -0,0 +1,24 @@ +#!/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. + +if ! [ -z "$1" ]; then + OPERATION=$1 +fi + +echo "Using installation mode: $OPERATION" + +cd ~/Development/nix-configuration +nix flake update +nixos-rebuild build --flake . +echo "Updates to apply:" +nix store diff-closures /run/current-system ./result | awk '/[0-9] →|→ [0-9]/ && !/nixos/' || echo + +read -p "Continue with upgrade (y/n) ? " choice +case "$choice" in + y|Y|yes ) sudo nixos-rebuild $OPERATION --flake .;; + n|N|no ) echo "Upgrade cancelled.";; + * ) echo "Invalid option. Upgrade cancelled.";; +esac \ No newline at end of file diff --git a/modules/users/aires/default.nix b/modules/users/aires/default.nix index adeee24..ea49e79 100644 --- a/modules/users/aires/default.nix +++ b/modules/users/aires/default.nix @@ -92,8 +92,8 @@ with lib; }; shellAliases = { dry-build = "cd ~/Development/nix-configuration && nix flake update && nixos-rebuild dry-build --flake ."; - update = "cd ~/Development/nix-configuration && nix flake update && sudo nixos-rebuild switch --flake ."; - upgrade = "update"; + update = "upgrade"; + upgrade = "cd ~/Development/nix-configuration && nixos-upgrade"; protontricks = "flatpak run com.github.Matoking.protontricks"; please = "sudo"; };