1
0
Fork 0

Create new install script that shows package diffs

This commit is contained in:
Aires 2024-03-30 02:29:37 -04:00
parent 675e1a9f47
commit 0d494a6b1a
6 changed files with 55 additions and 27 deletions

View file

@ -16,13 +16,17 @@ Initialize the submodule with:
git submodule update --init --recursive 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 Running this script does three things:
nix flake update
``` 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 ### 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 . 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 ## Layout
This config uses two systems: Flakes, and Home-manager. This config uses two systems: Flakes, and Home-manager.

View file

@ -117,11 +117,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1711133180, "lastModified": 1711625603,
"narHash": "sha256-WJOahf+6115+GMl3wUfURu8fszuNeJLv9qAWFQl3Vmo=", "narHash": "sha256-W+9dfqA9bqUIBV5u7jaIARAzMe3kTq/Hp2SpSVXKRQw=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "1c2c5e4cabba4c43504ef0f8cc3f3dfa284e2dbb", "rev": "c0ef0dab55611c676ad7539bf4e41b3ec6fa87d2",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -174,11 +174,11 @@
}, },
"nixos-hardware": { "nixos-hardware": {
"locked": { "locked": {
"lastModified": 1711274671, "lastModified": 1711352745,
"narHash": "sha256-19KQXya5VERUXOdeEJJN+zOqtvuE6MV3qTk9Gr4J9Uo=", "narHash": "sha256-luvqik+i3HTvCbXQZgB6uggvEcxI9uae0nmrgtXJ17U=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixos-hardware", "repo": "nixos-hardware",
"rev": "7559df1e4af972d5f1de87975b5ef6a8d7559db2", "rev": "9a763a7acc4cfbb8603bb0231fec3eda864f81c0",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -222,11 +222,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1711163522, "lastModified": 1711703276,
"narHash": "sha256-YN/Ciidm+A0fmJPWlHBGvVkcarYWSC+s3NTPk/P+q3c=", "narHash": "sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "44d0940ea560dee511026a53f0e2e2cde489b4d4", "rev": "d8fe5e6c92d0d190646fb9f1056741a229980089",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -21,6 +21,8 @@
url = "github:nix-community/home-manager/master"; url = "github:nix-community/home-manager/master";
inputs.nixpkgs.follows = "nixpkgs"; # Use system packages list where available 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, ... }: outputs = inputs@{ self, nixpkgs, lanzaboote, nix-flatpak, home-manager, nixos-hardware, ... }:

View file

@ -1,4 +1,4 @@
{ lib, ... }: { lib, pkgs, ... }:
let let
# Fetch secrets # Fetch secrets
# IMPORTANT: Make sure this repo exists on the filesystem first! # IMPORTANT: Make sure this repo exists on the filesystem first!
@ -7,9 +7,17 @@ let
ref = "main"; ref = "main";
rev = "55fc814d477d956ab885e157f24c2d43f433dc7a"; rev = "55fc814d477d956ab885e157f24c2d43f433dc7a";
}; };
# Install upgrade script
nixos-upgrade = pkgs.writeShellScriptBin "start-haven" (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
];
} }

24
hosts/common/nixos-upgrade.sh Executable file
View file

@ -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

View file

@ -92,8 +92,8 @@ with lib;
}; };
shellAliases = { shellAliases = {
dry-build = "cd ~/Development/nix-configuration && nix flake update && nixos-rebuild dry-build --flake ."; 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 ."; update = "upgrade";
upgrade = "update"; upgrade = "cd ~/Development/nix-configuration && nixos-upgrade";
protontricks = "flatpak run com.github.Matoking.protontricks"; protontricks = "flatpak run com.github.Matoking.protontricks";
please = "sudo"; please = "sudo";
}; };