8 cfg = config.services.sitespeed-io;
9 format = pkgs.formats.json { };
12 options.services.sitespeed-io = {
13 enable = lib.mkEnableOption "Sitespeed.io";
17 default = "sitespeed-io";
18 description = "User account under which sitespeed-io runs.";
21 package = lib.mkOption {
22 type = lib.types.package;
23 default = pkgs.sitespeed-io;
24 defaultText = "pkgs.sitespeed-io";
25 description = "Sitespeed.io package to use.";
28 dataDir = lib.mkOption {
29 default = "/var/lib/sitespeed-io";
31 description = "The base sitespeed-io data directory.";
34 period = lib.mkOption {
38 Systemd calendar expression when to run. See {manpage}`systemd.time(7)`.
45 A list of run configurations. The service will call sitespeed-io once
46 for every run listed here. This lets you examine different websites
47 with different sitespeed-io settings.
49 type = lib.types.listOf (
53 type = with lib.types; listOf str;
56 URLs the service should monitor.
60 settings = lib.mkOption {
61 type = lib.types.submodule {
62 freeformType = format.type;
67 Configuration for sitespeed-io, see
68 <https://www.sitespeed.io/documentation/sitespeed.io/configuration/>
69 for available options. The value here will be directly transformed to
70 JSON and passed as `--config` to the program.
74 extraArgs = lib.mkOption {
75 type = with lib.types; listOf str;
78 Extra command line arguments to pass to the program.
87 config = lib.mkIf cfg.enable {
90 assertion = cfg.runs != [ ];
91 message = "At least one run must be configured.";
94 assertion = lib.all (run: run.urls != [ ]) cfg.runs;
95 message = "All runs must have at least one url configured.";
99 systemd.services.sitespeed-io = {
100 description = "Check website status";
101 startAt = cfg.period;
103 WorkingDirectory = cfg.dataDir;
106 preStart = "chmod u+w -R ${cfg.dataDir}"; # Make sure things are writable
108 (lib.concatMapStrings (run: ''
109 ${lib.getExe cfg.package} \
110 --config ${format.generate "sitespeed.json" run.settings} \
111 ${lib.escapeShellArgs run.extraArgs} \
112 ${builtins.toFile "urls.txt" (lib.concatLines run.urls)} &
120 extraUsers.${cfg.user} = {
127 extraGroups.${cfg.user} = { };