blob: e877041094eb223c3cf4ae16ff36fba23b27ce60 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
{ config, lib, pkgs, ... }:
with lib;
let
bin = drv: name: "${lib.getBin drv}/bin/${name}";
cfg = config.vuizvui.user.openlab.speedtest;
py = pkgs.runCommand "speedtest.py" {} ''
cat ${./speedtest.py} \
| sed -e 's|^PING_BIN =.*$|PING_BIN = "${config.security.wrapperDir}/ping"|' \
> $out
'';
speedtest = pkgs.writeScript "speedtest" ''
#!${bin pkgs.bash "bash"}
mkdir -p "$(dirname "${cfg.outputPath}")"
${bin pkgs.python3 "python3"} ${py} >> "${cfg.outputPath}"
'';
in {
options.vuizvui.user.openlab.speedtest = {
enable = mkEnableOption "openlab speedtest";
outputPath = mkOption {
description = "File to which the results are appended.";
type = types.path;
default = "/dev/null";
};
};
config = mkIf cfg.enable {
systemd.services.speedtest = {
description = "openlab network speedtest";
path = with pkgs; [ curl bind.host ];
environment = { "LC_ALL" = "C"; };
wantedBy = [ "default.target" ];
after = [ "network.target" ];
script = "${speedtest}";
startAt = [ "*-*-* *:00/15:00" ];
};
assertions = [ {
assertion = cfg.outputPath != "/dev/null";
message = "You should set `vuizvui.user.openlab.speedtest.outputPath`.";
} ];
};
}
|