1 { lib, config, pkgs, ... }:
3 cfg = config.services.sitespeed-io;
4 format = pkgs.formats.json { };
7 options.services.sitespeed-io = {
8 enable = lib.mkEnableOption "Sitespeed.io";
12 default = "sitespeed-io";
13 description = "User account under which sitespeed-io runs.";
16 package = lib.mkOption {
17 type = lib.types.package;
18 default = pkgs.sitespeed-io;
19 defaultText = "pkgs.sitespeed-io";
20 description = "Sitespeed.io package to use.";
23 dataDir = lib.mkOption {
24 default = "/var/lib/sitespeed-io";
26 description = "The base sitespeed-io data directory.";
29 period = lib.mkOption {
33 Systemd calendar expression when to run. See {manpage}`systemd.time(7)`.
40 A list of run configurations. The service will call sitespeed-io once
41 for every run listed here. This lets you examine different websites
42 with different sitespeed-io settings.
44 type = lib.types.listOf (lib.types.submodule {
47 type = with lib.types; listOf str;
50 URLs the service should monitor.
54 settings = lib.mkOption {
55 type = lib.types.submodule {
56 freeformType = format.type;
61 Configuration for sitespeed-io, see
62 <https://www.sitespeed.io/documentation/sitespeed.io/configuration/>
63 for available options. The value here will be directly transformed to
64 JSON and passed as `--config` to the program.
68 extraArgs = lib.mkOption {
69 type = with lib.types; listOf str;
72 Extra command line arguments to pass to the program.
80 config = lib.mkIf cfg.enable {
83 assertion = cfg.runs != [];
84 message = "At least one run must be configured.";
87 assertion = lib.all (run: run.urls != []) cfg.runs;
88 message = "All runs must have at least one url configured.";
92 systemd.services.sitespeed-io = {
93 description = "Check website status";
96 WorkingDirectory = cfg.dataDir;
99 preStart = "chmod u+w -R ${cfg.dataDir}"; # Make sure things are writable
100 script = (lib.concatMapStrings (run: ''
101 ${lib.getExe cfg.package} \
102 --config ${format.generate "sitespeed.json" run.settings} \
103 ${lib.escapeShellArgs run.extraArgs} \
104 ${builtins.toFile "urls.txt" (lib.concatLines run.urls)} &
112 extraUsers.${cfg.user} = {
119 extraGroups.${cfg.user} = { };