NixOS configuration files
1#!/usr/bin/env sh
2
3set -eu
4
5format() {
6 alejandra . &>/dev/null
7}
8
9git_stage() {
10 git status
11 read -p "All files will be added to git. Press Enter to confirm."
12 git add -A
13}
14
15rebuild() {
16 echo "NixOS Rebuilding..."
17 sudo nixos-rebuild switch --flake . &>nixos-switch.log || (
18 cat nixos-switch.log | grep --color error && false
19 )
20}
21
22message() {
23 local msg
24 read -p "Enter commit message: " msg
25 nixos-rebuild list-generations | grep True | awk -v msg="$msg" -v machine="$(hostname)" 'BEGIN \
26 {if (msg!="") {
27 {print msg}
28 {print ""}
29 }}
30 {printf "Generation: "} {print $1}
31 {if (msg=="") {
32 {print ""}
33 }}
34 {printf "Built at: "} {printf $3} {printf " on "} {print $2}
35 {printf "Build machine: "} {print machine}
36 {printf "Kernel: "} {print $5}
37 {printf "nixpkgs: "} {print $4}'
38}
39
40git_commit() {
41 gen=$(message)
42 git commit -m "$gen"
43}
44
45main() {
46 pushd ~/.config/amuro
47 # Format Nix code with alejandra
48 format
49 # Add all files to git
50 git_stage
51 # nixos-rebuild
52 rebuild
53 # Commit all files to git
54 git_commit
55 popd
56}
57
58main