Initial pass on updater script

This commit is contained in:
Nathan McCarty 2025-06-30 14:30:15 -04:00
parent 9670087330
commit bb373ac40b
2 changed files with 83 additions and 3 deletions

6
flake.lock generated
View file

@ -242,11 +242,11 @@
}, },
"nixpkgs_3": { "nixpkgs_3": {
"locked": { "locked": {
"lastModified": 1750969886, "lastModified": 1751211869,
"narHash": "sha256-zW/OFnotiz/ndPFdebpo3X0CrbVNf22n4DjN2vxlb58=", "narHash": "sha256-1Cu92i1KSPbhPCKxoiVG5qnoRiKTgR5CcGSRyLpOd7Y=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "a676066377a2fe7457369dd37c31fd2263b662f4", "rev": "b43c397f6c213918d6cfe6e3550abfe79b5d1c51",
"type": "github" "type": "github"
}, },
"original": { "original": {

80
scripts/update Normal file
View file

@ -0,0 +1,80 @@
#!/usr/bin/env raku
# Find the flake path and make sure we are in the flake directory
my $flake-dir = $?FILE.IO.parent.parent.absolute;
my $flake-path = $flake-dir.IO.add('flake.nix');
chdir $flake-dir.IO;
# TODO: Parse `nix flake show --json` to figure out these targets instead of just
# yoloing it
# Setup our exception handler
# We will display the error, then invoke git to undo any changes before exiting
CATCH {
default {
# Display backtrace
$*ERR.say: .message;
for .backtrace.reverse {
next if .file.starts-with('SETTING::');
next unless .subname;
$*ERR.say: " in block {.subname} at {.file} line {.line}";
}
# TODO: Revert any changes
run <echo git restore $flake-dir>;
}
}
# Identify all the machines we will be building
sub systems() {
my $machine-dir = $flake-dir.IO.add('nixos').add('machines');
dir($machine-dir).map: *.basename;
}
# Identify all the home-manager configs we will be building
sub homes() {
my $homes-dir = $flake-dir.IO.add('home-manager').add('machines');
dir($homes-dir).map: *.basename;
}
# Build a system given its name
sub build-system($system-name) {
say "Building nixos system for $system-name";
my $proc = run <nixos-rebuild build -L --flake>, "$flake-path#$system-name",
:out, :err, :merge;
my $output = $proc.out.slurp: :close;
unless $proc.exitcode == 0 {
die "Failed building nixos system named $system-name:"
, "nixos-rebuild output:"
, $output;
}
}
# Build a home-manager config given its name
sub build-home($home-name) {
say "Building home-manager config for $home-name";
my $proc = run <home-manager build --flake>, "$flake-path#$home-name",
:out, :err, :merge;
my $output = $proc.out.slurp: :close;
unless $proc.exitcode == 0 {
die "Failed building home-manger config named $home-name:"
, "home-manager build output:"
, $output;
}
}
# Update the flake
my $nix-flake-update = run <nix flake update>, :out, :err, :merge;
my $nfu-out = $nix-flake-update.out.slurp: :close;
die "Failed updating flake", $nfu-out unless $nix-flake-update;
# Validate each system
for systems() {
build-system $_;
}
# Validate each home-manager config
for homes() {
build-home $_;
}
# TODO: Validate each dev-shell
# TODO: Setup git and ssh
# TODO: Commit
# TODO: Push``