nixpkgs/nixos/modules/services/networking/sitespeed-io.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

130 lines
3.5 KiB
Nix

{
lib,
config,
pkgs,
...
}:
let
cfg = config.services.sitespeed-io;
format = pkgs.formats.json { };
in
{
options.services.sitespeed-io = {
enable = lib.mkEnableOption "Sitespeed.io";
user = lib.mkOption {
type = lib.types.str;
default = "sitespeed-io";
description = "User account under which sitespeed-io runs.";
};
package = lib.mkOption {
type = lib.types.package;
default = pkgs.sitespeed-io;
defaultText = "pkgs.sitespeed-io";
description = "Sitespeed.io package to use.";
};
dataDir = lib.mkOption {
default = "/var/lib/sitespeed-io";
type = lib.types.str;
description = "The base sitespeed-io data directory.";
};
period = lib.mkOption {
type = lib.types.str;
default = "hourly";
description = ''
Systemd calendar expression when to run. See {manpage}`systemd.time(7)`.
'';
};
runs = lib.mkOption {
default = [ ];
description = ''
A list of run configurations. The service will call sitespeed-io once
for every run listed here. This lets you examine different websites
with different sitespeed-io settings.
'';
type = lib.types.listOf (
lib.types.submodule {
options = {
urls = lib.mkOption {
type = with lib.types; listOf str;
default = [ ];
description = ''
URLs the service should monitor.
'';
};
settings = lib.mkOption {
type = lib.types.submodule {
freeformType = format.type;
options = { };
};
default = { };
description = ''
Configuration for sitespeed-io, see
<https://www.sitespeed.io/documentation/sitespeed.io/configuration/>
for available options. The value here will be directly transformed to
JSON and passed as `--config` to the program.
'';
};
extraArgs = lib.mkOption {
type = with lib.types; listOf str;
default = [ ];
description = ''
Extra command line arguments to pass to the program.
'';
};
};
}
);
};
};
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.runs != [ ];
message = "At least one run must be configured.";
}
{
assertion = lib.all (run: run.urls != [ ]) cfg.runs;
message = "All runs must have at least one url configured.";
}
];
systemd.services.sitespeed-io = {
description = "Check website status";
startAt = cfg.period;
serviceConfig = {
WorkingDirectory = cfg.dataDir;
User = cfg.user;
};
preStart = "chmod u+w -R ${cfg.dataDir}"; # Make sure things are writable
script =
(lib.concatMapStrings (run: ''
${lib.getExe cfg.package} \
--config ${format.generate "sitespeed.json" run.settings} \
${lib.escapeShellArgs run.extraArgs} \
${builtins.toFile "urls.txt" (lib.concatLines run.urls)} &
'') cfg.runs)
+ ''
wait
'';
};
users = {
extraUsers.${cfg.user} = {
isSystemUser = true;
group = cfg.user;
home = cfg.dataDir;
createHome = true;
homeMode = "755";
};
extraGroups.${cfg.user} = { };
};
};
}