@@ -0,0 +1,49 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.nix.optimise;
7+in
8+
9+{
10+
11+ ###### interface
12+
13+ options = {
14+
15+ nix.optimise = {
16+
17+ automatic = mkOption {
18+ default = false;
19+ type = types.bool;
20+ description = "Automatically run the nix store optimiser at a specific time.";
21+ };
22+
23+ dates = mkOption {
24+ default = "03:45";
25+ type = types.listOf types.str;
26+ description = ''
27+ Specification (in the format described by
28+ <citerefentry><refentrytitle>systemd.time</refentrytitle>
29+ <manvolnum>5</manvolnum></citerefentry>) of the time at
30+ which the optimiser will run.
31+ '';
32+ };
33+ };
34+ };
35+
36+
37+ ###### implementation
38+
39+ config = {
40+
41+ systemd.services.nix-optimise =
42+ { description = "Nix Store Optimiser";
43+ serviceConfig.ExecStart = "${config.nix.package}/bin/nix-store --optimise";
44+ startAt = optional cfg.automatic cfg.dates;
45+ };
46+
47+ };
48+
49+}