nixos/redlib: use upstream systemd service file

Changed files
+12 -36
nixos
modules
services
misc
pkgs
by-name
re
redlib
+6 -36
nixos/modules/services/misc/redlib.nix
···
};
config = mkIf cfg.enable {
+
systemd.packages = [ cfg.package ];
systemd.services.redlib = {
-
description = "Private front-end for Reddit";
-
wantedBy = [ "multi-user.target" ];
-
after = [ "network.target" ];
+
wantedBy = [ "default.target" ];
environment = mapAttrs (_: v: if isBool v then boolToString' v else toString v) cfg.settings;
serviceConfig = {
-
DynamicUser = true;
-
ExecStart = "${lib.getExe cfg.package} ${args}";
+
ExecStart = [
+
""
+
"${lib.getExe cfg.package} ${args}"
+
];
AmbientCapabilities = lib.mkIf (cfg.port < 1024) [ "CAP_NET_BIND_SERVICE" ];
-
Restart = "on-failure";
-
RestartSec = "2s";
-
-
# Hardening
CapabilityBoundingSet = if (cfg.port < 1024) then [ "CAP_NET_BIND_SERVICE" ] else [ "" ];
-
DeviceAllow = [ "" ];
-
LockPersonality = true;
-
MemoryDenyWriteExecute = true;
-
PrivateDevices = true;
# A private user cannot have process capabilities on the host's user
# namespace and thus CAP_NET_BIND_SERVICE has no effect.
PrivateUsers = (cfg.port >= 1024);
-
ProcSubset = "pid";
-
ProtectClock = true;
-
ProtectControlGroups = true;
-
ProtectHome = true;
-
ProtectHostname = true;
-
ProtectKernelLogs = true;
-
ProtectKernelModules = true;
-
ProtectKernelTunables = true;
-
ProtectProc = "invisible";
-
RestrictAddressFamilies = [
-
"AF_INET"
-
"AF_INET6"
-
];
-
RestrictNamespaces = true;
-
RestrictRealtime = true;
-
RestrictSUIDSGID = true;
-
SystemCallArchitectures = "native";
-
SystemCallFilter = [
-
"@system-service"
-
"~@privileged"
-
"~@resources"
-
];
-
UMask = "0077";
};
};
+6
pkgs/by-name/re/redlib/package.nix
···
darwin.apple_sdk.frameworks.Security
];
+
postInstall = ''
+
install -Dm644 contrib/redlib.service $out/lib/systemd/system/redlib.service
+
sed -i "s#/usr/bin/redlib#$out/bin/redlib#" $out/lib/systemd/system/redlib.service
+
sed -i "/EnvironmentFile/d" $out/lib/systemd/system/redlib.service
+
'';
+
checkFlags = [
# All these test try to connect to Reddit.
# utils.rs