Merge pull request #311039 from DavHau/pr_smokeping

nixos/smokeping: use nginx instead of thttpd

Changed files
+44 -37
nixos
doc
manual
release-notes
modules
services
networking
tests
+4
nixos/doc/manual/release-notes/rl-2405.section.md
···
- `halloy` package was updated past 2024.5 which introduced a breaking change by switching the config format from YAML to TOML. See https://github.com/squidowl/halloy/releases/tag/2024.5 for details.
- The `wpaperd` package has a breaking change moving to 1.0.1, previous version 0.3.0 had 2 different configuration files, one for wpaperd and one for the wallpapers. Remove the former and move the latter (`wallpaper.toml`) to `config.toml`.
- Ada packages (libraries and tools) have been moved into the `gnatPackages` scope. `gnatPackages` uses the default GNAT compiler, `gnat12Packages` and `gnat13Packages` use the respective matching compiler version.
···
- `halloy` package was updated past 2024.5 which introduced a breaking change by switching the config format from YAML to TOML. See https://github.com/squidowl/halloy/releases/tag/2024.5 for details.
+
- If `services.smokeping.webService` was enabled, smokeping is now served via nginx instead of thttpd. This change brings the following consequences:
+
- The default port for smokeping is now the nginx default port 80 instead of 8081.
+
- The option `services.smokeping.port` has been removed. To customize the port, use `services.nginx.virtualHosts.smokeping.listen.*.port`.
+
- The `wpaperd` package has a breaking change moving to 1.0.1, previous version 0.3.0 had 2 different configuration files, one for wpaperd and one for the wallpapers. Remove the former and move the latter (`wallpaper.toml`) to `config.toml`.
- Ada packages (libraries and tools) have been moved into the `gnatPackages` scope. `gnatPackages` uses the default GNAT compiler, `gnat12Packages` and `gnat13Packages` use the respective matching compiler version.
+30 -33
nixos/modules/services/networking/smokeping.nix
···
in
{
options = {
services.smokeping = {
enable = mkEnableOption "smokeping service";
···
};
cgiUrl = mkOption {
type = types.str;
-
default = "http://${cfg.hostName}:${toString cfg.port}/smokeping.cgi";
-
defaultText = literalExpression ''"http://''${hostName}:''${toString port}/smokeping.cgi"'';
example = "https://somewhere.example.com/smokeping.cgi";
description = "URL to the smokeping cgi.";
};
···
Setting it to `null` skips passing the -h option to thttpd,
which makes it bind to all interfaces.
'';
-
};
-
port = mkOption {
-
type = types.port;
-
default = 8081;
-
description = "TCP port to use for the web server.";
};
presentationConfig = mkOption {
type = types.lines;
···
description = "smokeping daemon user";
home = smokepingHome;
createHome = true;
-
# When `cfg.webService` is enabled, `thttpd` makes SmokePing available
-
# under `${cfg.host}:${cfg.port}/smokeping.fcgi` as per the `ln -s` below.
-
# We also want that going to `${cfg.host}:${cfg.port}` without `smokeping.fcgi`
-
# makes it easy for the user to find SmokePing.
-
# However `thttpd` does not seem to support easy redirections from `/` to `smokeping.fcgi`
-
# and only allows directory listings or `/` -> `index.html` resolution if the directory
-
# has `chmod 755` (see https://acme.com/software/thttpd/thttpd_man.html#PERMISSIONS,
-
# " directories should be 755 if you want to allow indexing").
-
# Otherwise it shows `403 Forbidden` on `/`.
-
# Thus, we need to make `smokepingHome` (which is given to `thttpd -d` below) `755`.
-
homeMode = "755";
};
users.groups.${cfg.user} = { };
systemd.services.smokeping = {
···
${cfg.package}/bin/smokeping --static --config=${configPath}
'';
};
-
systemd.services.thttpd = mkIf cfg.webService {
-
requiredBy = [ "multi-user.target" ];
-
requires = [ "smokeping.service" ];
-
path = with pkgs; [ bash rrdtool smokeping thttpd ];
-
serviceConfig = {
-
Restart = "always";
-
ExecStart = lib.concatStringsSep " " (lib.concatLists [
-
[ "${pkgs.thttpd}/bin/thttpd" ]
-
[ "-u ${cfg.user}" ]
-
[ ''-c "**.fcgi"'' ]
-
[ "-d ${smokepingHome}" ]
-
(lib.optional (cfg.host != null) "-h ${cfg.host}")
-
[ "-p ${builtins.toString cfg.port}" ]
-
[ "-D -nos" ]
-
]);
};
};
};
···
in
{
+
imports = [
+
(mkRemovedOptionModule [ "services" "smokeping" "port" ] ''
+
The smokeping web service is now served by nginx.
+
In order to change the port, you need to change the nginx configuration under `services.nginx.virtualHosts.smokeping.listen.*.port`.
+
'')
+
];
+
options = {
services.smokeping = {
enable = mkEnableOption "smokeping service";
···
};
cgiUrl = mkOption {
type = types.str;
+
default = "http://${cfg.hostName}/smokeping.cgi";
+
defaultText = literalExpression ''"http://''${hostName}/smokeping.cgi"'';
example = "https://somewhere.example.com/smokeping.cgi";
description = "URL to the smokeping cgi.";
};
···
Setting it to `null` skips passing the -h option to thttpd,
which makes it bind to all interfaces.
'';
};
presentationConfig = mkOption {
type = types.lines;
···
description = "smokeping daemon user";
home = smokepingHome;
createHome = true;
+
# When `cfg.webService` is enabled, `nginx` requires read permissions on the home directory.
+
homeMode = "711";
};
users.groups.${cfg.user} = { };
systemd.services.smokeping = {
···
${cfg.package}/bin/smokeping --static --config=${configPath}
'';
};
+
+
# use nginx to serve the smokeping web service
+
services.fcgiwrap.enable = mkIf cfg.webService true;
+
services.nginx = mkIf cfg.webService {
+
enable = true;
+
virtualHosts."smokeping" = {
+
serverName = mkDefault cfg.host;
+
locations."/" = {
+
root = smokepingHome;
+
index = "smokeping.fcgi";
+
};
+
locations."/smokeping.fcgi" = {
+
extraConfig = ''
+
include ${config.services.nginx.package}/conf/fastcgi_params;
+
fastcgi_pass unix:${config.services.fcgiwrap.socketAddress};
+
fastcgi_param SCRIPT_FILENAME ${smokepingHome}/smokeping.fcgi;
+
fastcgi_param DOCUMENT_ROOT ${smokepingHome};
+
'';
+
};
};
};
};
+10 -4
nixos/tests/smokeping.nix
···
networking.domain = "example.com"; # FQDN: sm.example.com
services.smokeping = {
enable = true;
-
port = 8081;
mailHost = "127.0.0.2";
probeConfig = ''
+ FPing
···
testScript = ''
start_all()
sm.wait_for_unit("smokeping")
-
sm.wait_for_unit("thttpd")
sm.wait_for_file("/var/lib/smokeping/data/Local/LocalMachine.rrd")
-
sm.succeed("curl -s -f localhost:8081/smokeping.fcgi?target=Local")
# Check that there's a helpful page without explicit path as well.
-
sm.succeed("curl -s -f localhost:8081")
sm.succeed("ls /var/lib/smokeping/cache/Local/LocalMachine_mini.png")
sm.succeed("ls /var/lib/smokeping/cache/index.html")
'';
})
···
networking.domain = "example.com"; # FQDN: sm.example.com
services.smokeping = {
enable = true;
mailHost = "127.0.0.2";
probeConfig = ''
+ FPing
···
testScript = ''
start_all()
sm.wait_for_unit("smokeping")
+
sm.wait_for_unit("nginx")
sm.wait_for_file("/var/lib/smokeping/data/Local/LocalMachine.rrd")
+
sm.succeed("curl -s -f localhost/smokeping.fcgi?target=Local")
# Check that there's a helpful page without explicit path as well.
+
sm.succeed("curl -s -f localhost")
sm.succeed("ls /var/lib/smokeping/cache/Local/LocalMachine_mini.png")
sm.succeed("ls /var/lib/smokeping/cache/index.html")
+
+
# stop and start the service like nixos-rebuild would do
+
# see https://github.com/NixOS/nixpkgs/issues/265953)
+
sm.succeed("systemctl stop smokeping")
+
sm.succeed("systemctl start smokeping")
+
# ensure all services restarted properly
+
sm.succeed("systemctl --failed | grep -q '0 loaded units listed'")
'';
})