|
| 1 | +{ |
| 2 | + pkgs, |
| 3 | + config, |
| 4 | + lib, |
| 5 | + utils, |
| 6 | + ... |
| 7 | +}: |
| 8 | +let |
| 9 | + cfg = config.services.glances; |
| 10 | + |
| 11 | + inherit (lib) |
| 12 | + getExe |
| 13 | + maintainers |
| 14 | + mkEnableOption |
| 15 | + mkOption |
| 16 | + mkIf |
| 17 | + mkPackageOption |
| 18 | + ; |
| 19 | + |
| 20 | + inherit (lib.types) |
| 21 | + bool |
| 22 | + listOf |
| 23 | + port |
| 24 | + str |
| 25 | + ; |
| 26 | + |
| 27 | + inherit (utils) |
| 28 | + escapeSystemdExecArgs |
| 29 | + ; |
| 30 | + |
| 31 | +in |
| 32 | +{ |
| 33 | + options.services.glances = { |
| 34 | + enable = mkEnableOption "Glances"; |
| 35 | + |
| 36 | + package = mkPackageOption pkgs "glances" { }; |
| 37 | + |
| 38 | + port = mkOption { |
| 39 | + description = "Port the server will isten on."; |
| 40 | + type = port; |
| 41 | + default = 61208; |
| 42 | + }; |
| 43 | + |
| 44 | + openFirewall = mkOption { |
| 45 | + description = "Open port in the firewall for glances."; |
| 46 | + type = bool; |
| 47 | + default = false; |
| 48 | + }; |
| 49 | + |
| 50 | + extraArgs = mkOption { |
| 51 | + type = listOf str; |
| 52 | + default = [ "--webserver" ]; |
| 53 | + example = [ |
| 54 | + "--webserver" |
| 55 | + "--disable-webui" |
| 56 | + ]; |
| 57 | + description = '' |
| 58 | + Extra command-line arguments to pass to glances. |
| 59 | +
|
| 60 | + See https://glances.readthedocs.io/en/latest/cmds.html for all available options. |
| 61 | + ''; |
| 62 | + }; |
| 63 | + }; |
| 64 | + |
| 65 | + config = mkIf cfg.enable { |
| 66 | + |
| 67 | + environment.systemPackages = [ cfg.package ]; |
| 68 | + |
| 69 | + systemd.services."glances" = { |
| 70 | + description = "Glances"; |
| 71 | + after = [ "network.target" ]; |
| 72 | + wantedBy = [ "multi-user.target" ]; |
| 73 | + |
| 74 | + serviceConfig = { |
| 75 | + Type = "simple"; |
| 76 | + DynamicUser = true; |
| 77 | + ExecStart = "${getExe cfg.package} --port ${toString cfg.port} ${escapeSystemdExecArgs cfg.extraArgs}"; |
| 78 | + Restart = "on-failure"; |
| 79 | + |
| 80 | + NoNewPrivileges = true; |
| 81 | + ProtectSystem = "full"; |
| 82 | + ProtectHome = true; |
| 83 | + PrivateTmp = true; |
| 84 | + PrivateDevices = true; |
| 85 | + ProtectKernelTunables = true; |
| 86 | + ProtectKernelModules = true; |
| 87 | + ProtectKernelLogs = true; |
| 88 | + ProtectControlGroups = true; |
| 89 | + MemoryDenyWriteExecute = true; |
| 90 | + RestrictAddressFamilies = [ |
| 91 | + "AF_INET" |
| 92 | + "AF_INET6" |
| 93 | + "AF_NETLINK" |
| 94 | + "AF_UNIX" |
| 95 | + ]; |
| 96 | + LockPersonality = true; |
| 97 | + RestrictRealtime = true; |
| 98 | + ProtectClock = true; |
| 99 | + ReadWritePaths = [ "/var/log" ]; |
| 100 | + CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ]; |
| 101 | + AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ]; |
| 102 | + SystemCallFilter = [ "@system-service" ]; |
| 103 | + }; |
| 104 | + }; |
| 105 | + |
| 106 | + networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ]; |
| 107 | + }; |
| 108 | + |
| 109 | + meta.maintainers = with maintainers; [ claha ]; |
| 110 | +} |
0 commit comments