@@ -0,0 +1,62 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.virtualisation.rkt;
7+in
8+{
9+ options.virtualisation.rkt = {
10+ enable = mkEnableOption "rkt metadata service";
11+
12+ gc = {
13+ automatic = mkOption {
14+ default = true;
15+ type = types.bool;
16+ description = "Automatically run the garbage collector at a specific time.";
17+ };
18+
19+ dates = mkOption {
20+ default = "03:15";
21+ type = types.str;
22+ description = ''
23+ Specification (in the format described by
24+ <citerefentry><refentrytitle>systemd.time</refentrytitle>
25+ <manvolnum>5</manvolnum></citerefentry>) of the time at
26+ which the garbage collector will run.
27+ '';
28+ };
29+
30+ options = mkOption {
31+ default = "--grace-period=24h";
32+ type = types.str;
33+ description = ''
34+ Options given to <filename>rkt gc</filename> when the
35+ garbage collector is run automatically.
36+ '';
37+ };
38+ };
39+ };
40+
41+ config = mkIf cfg.enable {
42+ environment.systemPackages = [ pkgs.rkt ];
43+
44+ systemd.services.rkt = {
45+ description = "rkt metadata service";
46+ wantedBy = [ "multi-user.target" ];
47+ after = [ "network.target" ];
48+ serviceConfig = {
49+ ExecStart = "${pkgs.rkt}/bin/rkt metadata-service";
50+ };
51+ };
52+
53+ systemd.services.rkt-gc = {
54+ description = "rkt garbage collection";
55+ startAt = optionalString cfg.gc.automatic cfg.gc.dates;
56+ serviceConfig = {
57+ Type = "oneshot";
58+ ExecStart = "${pkgs.rkt}/bin/rkt gc ${cfg.gc.options}";
59+ };
60+ };
61+ };
62+}