diff --git a/hosts/laptop/configuration.nix b/hosts/laptop/configuration.nix index f8ae7e2..c71456d 100755 --- a/hosts/laptop/configuration.nix +++ b/hosts/laptop/configuration.nix @@ -23,6 +23,7 @@ ../../hostsModules/laptop/nixos/ollama.nix # llm config ../../modules/nixos/mullvad.nix # vpn config ../../hostsModules/laptop/nixos/autoUpdate.nix # auto update the flakes. Handles notification via libnotify and matrix-commander-rs + ../../hostsModules/laptop/nixos/cleanNix.nix # uses alexandra deadnix and statix to clean the whole config ../../hostsModules/laptop/nixos/bootloader.nix ../../hostsModules/laptop/nixos/networking.nix # firewall, ssh, networkmanager, etc. ../../modules/nixos/bluetooth.nix diff --git a/hostsModules/laptop/nixos/autoCleanup.nix b/hostsModules/laptop/nixos/autoCleanup.nix new file mode 100644 index 0000000..af6545c --- /dev/null +++ b/hostsModules/laptop/nixos/autoCleanup.nix @@ -0,0 +1,45 @@ +{pkgs, ...}: { + # Ensure your script is available system-wide + environment.systemPackages = [ + (pkgs.callPackage ../scripts/cleanNix.nix {}) + ]; + users.users.tomasr = { + linger = true; # lingering is required + }; + + systemd.user.services.custom-autoupdate = { + description = "NixOS configuration auto cleanup"; + + serviceConfig = { + Type = "oneshot"; + + ExecStart = "/run/current-system/sw/bin/custom-cleanNix"; + + # safety for long rebuilds + TimeoutStartSec = "45min"; + TimeoutStopSec = "10min"; + + # avoid overlap + RemainAfterExit = true; + + # tweaks that should make the system run normally during the rebuilds + Nice = 10; + IOSchedulingClass = "best-effort"; + IOSchedulingPriority = 7; + }; + }; + + # Systemd USER timer + systemd.user.timers.custom-autoupdate = { + wantedBy = ["timers.target"]; + + timerConfig = { + OnCalendar = "Sat *-*-* 20:00:00"; # runs saturday night. If for whatever reason something breaks. I have whole sunday to fix it. + + Persistent = true; # if it happens during shutted down + + # avoids thundering herd on boot + RandomizedDelaySec = "2h"; + }; + }; +} diff --git a/modules/nixos/nixUtils.nix b/modules/nixos/nixUtils.nix index 3bfd2d1..696a3c1 100644 --- a/modules/nixos/nixUtils.nix +++ b/modules/nixos/nixUtils.nix @@ -31,6 +31,5 @@ vimPluginsUpdater # used for building plugins nix-index statix - (pkgs.callPackage ../../hostsModules/laptop/scripts/cleanNix.nix {}) ]; }