lol

nixos/sitespeed-io: init

authored by

Gabriel Fontes and committed by
Anderson Torres
147668b8 cf615b05

+125
+2
nixos/doc/manual/release-notes/rl-2311.section.md
··· 14 14 15 15 - [river](https://github.com/riverwm/river), A dynamic tiling wayland compositor. Available as [programs.river](#opt-programs.river.enable). 16 16 17 + - [sitespeed-io](https://sitespeed.io), a tool that can generate metrics (timings, diagnostics) for websites. Available as [services.sitespeed-io](#opt-services.sitespeed-io.enable). 18 + 17 19 ## Backward Incompatibilities {#sec-release-23.11-incompatibilities} 18 20 19 21 - The latest version of `clonehero` now stores custom content in `~/.clonehero`. See the [migration instructions](https://clonehero.net/2022/11/29/v23-to-v1-migration-instructions.html). Typically, these content files would exist along side the binary, but the previous build used a wrapper script that would store them in `~/.config/unity3d/srylain Inc_/Clone Hero`.
+1
nixos/modules/module-list.nix
··· 1010 1010 ./services/networking/shorewall.nix 1011 1011 ./services/networking/shorewall6.nix 1012 1012 ./services/networking/shout.nix 1013 + ./services/networking/sitespeed-io.nix 1013 1014 ./services/networking/skydns.nix 1014 1015 ./services/networking/smartdns.nix 1015 1016 ./services/networking/smokeping.nix
+122
nixos/modules/services/networking/sitespeed-io.nix
··· 1 + { lib, config, pkgs, ... }: 2 + let 3 + cfg = config.services.sitespeed-io; 4 + format = pkgs.formats.json { }; 5 + in 6 + { 7 + options.services.sitespeed-io = { 8 + enable = lib.mkEnableOption (lib.mdDoc "Sitespeed.io"); 9 + 10 + user = lib.mkOption { 11 + type = lib.types.str; 12 + default = "sitespeed-io"; 13 + description = lib.mdDoc "User account under which sitespeed-io runs."; 14 + }; 15 + 16 + package = lib.mkOption { 17 + type = lib.types.package; 18 + default = pkgs.sitespeed-io; 19 + defaultText = "pkgs.sitespeed-io"; 20 + description = lib.mdDoc "Sitespeed.io package to use."; 21 + }; 22 + 23 + dataDir = lib.mkOption { 24 + default = "/var/lib/sitespeed-io"; 25 + type = lib.types.str; 26 + description = lib.mdDoc "The base sitespeed-io data directory."; 27 + }; 28 + 29 + period = lib.mkOption { 30 + type = lib.types.str; 31 + default = "hourly"; 32 + description = lib.mdDoc '' 33 + Systemd calendar expression when to run. See {manpage}`systemd.time(7)`. 34 + ''; 35 + }; 36 + 37 + runs = lib.mkOption { 38 + default = [ ]; 39 + description = lib.mdDoc '' 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. 43 + ''; 44 + type = lib.types.listOf (lib.types.submodule { 45 + options = { 46 + urls = lib.mkOption { 47 + type = with lib.types; listOf str; 48 + default = []; 49 + description = lib.mdDoc '' 50 + URLs the service should monitor. 51 + ''; 52 + }; 53 + 54 + settings = lib.mkOption { 55 + type = lib.types.submodule { 56 + freeformType = format.type; 57 + options = { }; 58 + }; 59 + default = { }; 60 + description = lib.mdDoc '' 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. 65 + ''; 66 + }; 67 + 68 + extraArgs = lib.mkOption { 69 + type = with lib.types; listOf str; 70 + default = []; 71 + description = lib.mdDoc '' 72 + Extra command line arguments to pass to the program. 73 + ''; 74 + }; 75 + }; 76 + }); 77 + }; 78 + }; 79 + 80 + config = lib.mkIf cfg.enable { 81 + assertions = [ 82 + { 83 + assertion = cfg.runs != []; 84 + message = "At least one run must be configured."; 85 + } 86 + { 87 + assertion = lib.all (run: run.urls != []) cfg.runs; 88 + message = "All runs must have at least one url configured."; 89 + } 90 + ]; 91 + 92 + systemd.services.sitespeed-io = { 93 + description = "Check website status"; 94 + startAt = cfg.period; 95 + serviceConfig = { 96 + WorkingDirectory = cfg.dataDir; 97 + User = cfg.user; 98 + }; 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)} & 105 + '') cfg.runs) + 106 + '' 107 + wait 108 + ''; 109 + }; 110 + 111 + users = { 112 + extraUsers.${cfg.user} = { 113 + isSystemUser = true; 114 + group = cfg.user; 115 + home = cfg.dataDir; 116 + createHome = true; 117 + homeMode = "755"; 118 + }; 119 + extraGroups.${cfg.user} = { }; 120 + }; 121 + }; 122 + }