Last active
January 23, 2026 07:49
-
Star
(104)
You must be signed in to star a gist -
Fork
(10)
You must be signed in to fork a gist
-
-
Save 0atman/1a5133b842f929ba4c1e195ee67599d5 to your computer and use it in GitHub Desktop.
A rebuild script that commits on a successful build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| config, | |
| pkgs, | |
| options, | |
| ... | |
| }: let | |
| hostname = "oatman-pc"; # to alllow per-machine config | |
| in { | |
| networking.hostName = hostname; | |
| imports = [ | |
| /etc/nixos/hardware-configuration.nix | |
| (/home/oatman/dotfiles/nixos + "/${hostname}.nix") | |
| ]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # I believe there are a few ways to do this: | |
| # | |
| # 1. My current way, using a minimal /etc/nixos/configuration.nix that just imports my config from my home directory (see it in the gist) | |
| # 2. Symlinking to your own configuration.nix in your home directory (I think I tried and abandoned this and links made relative paths weird) | |
| # 3. My new favourite way: as @clot27 says, you can provide nixos-rebuild with a path to the config, allowing it to be entirely inside your dotfies, with zero bootstrapping of files required. | |
| # `nixos-rebuild switch -I nixos-config=path/to/configuration.nix` | |
| # 4. If you uses a flake as your primary config, you can specify a path to `configuration.nix` in it and then `nixos-rebuild switch —flake` path/to/directory | |
| # As I hope was clear from the video, I am new to nixos, and there may be other, better, options, in which case I'd love to know them! (I'll update the gist if so) | |
| # A rebuild script that commits on a successful build | |
| set -e | |
| # Edit your config | |
| $EDITOR configuration.nix | |
| # cd to your config dir | |
| pushd ~/dotfiles/nixos/ | |
| # Early return if no changes were detected (thanks @singiamtel!) | |
| if git diff --quiet '*.nix'; then | |
| echo "No changes detected, exiting." | |
| popd | |
| exit 0 | |
| fi | |
| # Autoformat your nix files | |
| alejandra . &>/dev/null \ | |
| || ( alejandra . ; echo "formatting failed!" && exit 1) | |
| # Shows your changes | |
| git diff -U0 '*.nix' | |
| echo "NixOS Rebuilding..." | |
| # Rebuild, output simplified errors, log trackebacks | |
| sudo nixos-rebuild switch &>nixos-switch.log || (cat nixos-switch.log | grep --color error && exit 1) | |
| # Get current generation metadata | |
| current=$(nixos-rebuild list-generations | grep current) | |
| # Commit all changes witih the generation metadata | |
| git commit -am "$current" | |
| # Back to where you were | |
| popd | |
| # Notify all OK! | |
| notify-send -e "NixOS Rebuilt OK!" --icon=software-update-available |
I have made a script that handles all initialization logic, and post+pre git hooks. See here
Author
I've been playing with changing the automatic commit message from just the nixos version metadata to also include a local llm summary of the changes. lumen is a good tool for this (though aichat probably works too), and I've found that mevatron/diffsense:0.5b is a good, small model for this that runs in ~3s on my mid-range i5 laptop with no GPU:
echo "Summarising diff with ollama..."
summary=$(lumen -p ollama -m"mevatron/diffsense:0.5b" draft)
echo $summary
sudo echo "installing..."
nh os switch ~/dotfiles/nixos/ -Hdefault -- --impure
current=$(nixos-rebuild list-generations --json | jq '.[] | select (.current == true) | "\(.generation)"')
git commit -am "$current - llm summary: $summary" && true
git pushThe output seems to be a single-line summary, then a blank line, then some semi-useful detail. Better than nothing!
Whatever you use will require an ollama server running, which I've found to be quite light on resources when not in use. Trivial to install with nixos, of course:
configuration.nix
services.ollama.enable = true;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For all fish shell users, I have compiled my own script, which is a combination of most of the features seen here and more. have a look