vibed improved gc

This commit is contained in:
alisceon 2026-05-24 17:15:28 +02:00
parent a79ca6a399
commit 9cb871275a
5 changed files with 208 additions and 4 deletions

View file

@ -2,6 +2,15 @@
let
autoUpgradeUser = "alisceon";
flakeRef = "path:${repoLocalPath}";
devFlakeGarbageCollect = pkgs.writeShellApplication {
name = "dev-flake-garbage-collect";
runtimeInputs = [
pkgs.coreutils
pkgs.findutils
pkgs.gnugrep
];
text = builtins.readFile ../../util/dev_flake_gc.sh;
};
in
{
boot = {
@ -34,9 +43,34 @@ in
runGarbageCollection = true;
};
systemd.services.nixos-upgrade.preStart = ''
${pkgs.util-linux}/bin/runuser -u ${autoUpgradeUser} -- ${lib.getExe config.nix.package} flake update --flake ${lib.escapeShellArg flakeRef}
'';
systemd = {
services = {
nixos-upgrade.preStart = ''
${pkgs.util-linux}/bin/runuser -u ${autoUpgradeUser} -- ${lib.getExe config.nix.package} flake update --flake ${lib.escapeShellArg flakeRef}
'';
dev-flake-garbage-collect = {
description = "Remove stale development flake caches and build symlinks";
wants = [ "nix-gc.service" ];
before = [ "nix-gc.service" ];
serviceConfig = {
Type = "oneshot";
ExecStart = lib.getExe devFlakeGarbageCollect;
Nice = 10;
IOSchedulingClass = "idle";
};
};
};
timers.dev-flake-garbage-collect = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "weekly";
Persistent = true;
RandomizedDelaySec = "3h";
};
};
};
nix = {
settings = {

View file

@ -1,4 +1,12 @@
{ pkgs, pkgs-unstable, ... }:
{ pkgs, pkgs-unstable, lib, ... }:
let
commands = import ../../../lib/commands.nix { inherit pkgs; };
systemNotify = commands."system-notify";
notify = urgency: title: body:
"${systemNotify} ${lib.escapeShellArgs [ urgency title body ]}";
notifyFailure = title: service:
"${systemNotify} ${lib.escapeShellArgs [ "critical" title ]} \"${service} ended with: $SERVICE_RESULT\"";
in
{
boot = {
plymouth = {
@ -53,6 +61,34 @@
8888
];
systemd.services = {
nixos-upgrade = {
preStart = lib.mkBefore ''
${notify "normal" "System update started" "Updating flake inputs and preparing the NixOS switch."}
'';
postStop = ''
if [ "$SERVICE_RESULT" = "success" ]; then
${notify "normal" "System update finished" "The automated NixOS update completed successfully."}
else
${notifyFailure "System update failed" "nixos-upgrade.service"}
fi
'';
};
nix-gc = {
preStart = ''
${notify "normal" "Garbage collection started" "Cleaning old Nix generations and unreferenced store paths."}
'';
postStop = ''
if [ "$SERVICE_RESULT" = "success" ]; then
${notify "normal" "Garbage collection finished" "Nix store garbage collection completed successfully."}
else
${notifyFailure "Garbage collection failed" "nix-gc.service"}
fi
'';
};
};
environment = {
systemPackages = [
pkgs-unstable.discord