feat(hosts/orion): integrate optimize-nix-store module
Some checks failed
Check Formatting of Files / Check-Formatting (push) Failing after 35s

This commit is contained in:
Price Hiller 2025-01-02 14:18:32 -06:00
parent 9a2e65600a
commit 2ab55ebf38
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB
3 changed files with 73 additions and 2 deletions

View File

@ -162,6 +162,7 @@
};
modules = [
./modules/btrfs-rollback.nix
./modules/optimize-nix-store.nix
inputs.home-manager.nixosModules.home-manager
{
home-manager = {

View File

@ -3,6 +3,10 @@
{
nixpkgs.config.allowUnfree = true;
nix = {
optimize-nix-store = {
enable = true;
randomizedDelaySec = "30min";
};
nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];
settings = {
experimental-features = [
@ -10,7 +14,6 @@
"nix-command"
"flakes"
];
auto-optimise-store = true;
use-xdg-base-directories = true;
trusted-users = [ "@wheel" ];
substituters = [
@ -24,7 +27,7 @@
};
gc = {
automatic = true;
dates = "weekly";
dates = "daily";
options = "--delete-older-than 7d";
};
};

View File

@ -0,0 +1,67 @@
{
config,
lib,
...
}:
let
cfg = config.nix.optimize-nix-store;
in
{
options.nix.optimize-nix-store = {
enable = lib.mkEnableOption "Auto optimize the nix store on a schedule.";
dates = lib.mkOption {
type = lib.types.singleLineStr;
default = "daily";
example = "weekly";
description = ''
How often or when nix store optimization is performed.
This value must be a calendar event in the format specified by
{manpage}`systemd.time(7)`.
'';
};
randomizedDelaySec = lib.mkOption {
default = "0";
type = lib.types.singleLineStr;
example = "45min";
description = ''
Add a randomized delay before each nix store optimization.
The delay will be chosen between zero and this value.
This value must be a time span in the format specified by
{manpage}`systemd.time(7)`
'';
};
persistent = lib.mkOption {
default = true;
type = lib.types.bool;
example = false;
description = ''
Takes a boolean argument. If true, the time when the service
unit was last triggered is stored on disk. When the timer is
activated, the service unit is triggered immediately if it
would have been triggered at least once during the time when
the timer was inactive. Such triggering is nonetheless
subject to the delay imposed by RandomizedDelaySec=. This is
useful to catch up on missed runs of the service when the
system was powered down.
'';
};
};
config = lib.mkIf (cfg.enable && config.nix.enable) {
systemd = {
services.optimize-nix-store = {
description = "Optimizes the Nix Store on a regular schedule";
script = "exec ${config.nix.package.out}/bin/nix-store --optimise";
serviceConfig.Type = "oneshot";
startAt = cfg.dates;
};
timers.optimize-nix-store.timerConfig = {
Persistent = cfg.persistent;
RandomizedDelaySec = cfg.randomizedDelaySec;
};
};
};
}