feat(hosts/orion): integrate optimize-nix-store
module
Some checks failed
Check Formatting of Files / Check-Formatting (push) Failing after 35s
Some checks failed
Check Formatting of Files / Check-Formatting (push) Failing after 35s
This commit is contained in:
parent
9a2e65600a
commit
2ab55ebf38
@ -162,6 +162,7 @@
|
|||||||
};
|
};
|
||||||
modules = [
|
modules = [
|
||||||
./modules/btrfs-rollback.nix
|
./modules/btrfs-rollback.nix
|
||||||
|
./modules/optimize-nix-store.nix
|
||||||
inputs.home-manager.nixosModules.home-manager
|
inputs.home-manager.nixosModules.home-manager
|
||||||
{
|
{
|
||||||
home-manager = {
|
home-manager = {
|
||||||
|
@ -3,6 +3,10 @@
|
|||||||
{
|
{
|
||||||
nixpkgs.config.allowUnfree = true;
|
nixpkgs.config.allowUnfree = true;
|
||||||
nix = {
|
nix = {
|
||||||
|
optimize-nix-store = {
|
||||||
|
enable = true;
|
||||||
|
randomizedDelaySec = "30min";
|
||||||
|
};
|
||||||
nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];
|
nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];
|
||||||
settings = {
|
settings = {
|
||||||
experimental-features = [
|
experimental-features = [
|
||||||
@ -10,7 +14,6 @@
|
|||||||
"nix-command"
|
"nix-command"
|
||||||
"flakes"
|
"flakes"
|
||||||
];
|
];
|
||||||
auto-optimise-store = true;
|
|
||||||
use-xdg-base-directories = true;
|
use-xdg-base-directories = true;
|
||||||
trusted-users = [ "@wheel" ];
|
trusted-users = [ "@wheel" ];
|
||||||
substituters = [
|
substituters = [
|
||||||
@ -24,7 +27,7 @@
|
|||||||
};
|
};
|
||||||
gc = {
|
gc = {
|
||||||
automatic = true;
|
automatic = true;
|
||||||
dates = "weekly";
|
dates = "daily";
|
||||||
options = "--delete-older-than 7d";
|
options = "--delete-older-than 7d";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
67
modules/optimize-nix-store.nix
Normal file
67
modules/optimize-nix-store.nix
Normal 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;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user