2025-01-08 19:06:22 +01:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
{
|
|
|
|
config.systemd.services = lib.mkIf (config.specialisation != { }) {
|
|
|
|
nix-daemon.serviceConfig = {
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
RestrictSUIDSGID = true; # good, somehow???
|
|
|
|
|
2025-01-09 13:54:25 +01:00
|
|
|
RestrictAddressFamilies = [
|
|
|
|
"AF_UNIX"
|
|
|
|
"AF_INET"
|
|
|
|
"AF_INET6"
|
2025-01-11 11:54:34 +01:00
|
|
|
"AF_NETLINK" # needed for some checks
|
2025-01-09 13:54:25 +01:00
|
|
|
]; # needed to download sources and caches
|
|
|
|
RestrictNamespaces = [
|
|
|
|
"user"
|
|
|
|
"net"
|
|
|
|
"uts"
|
|
|
|
"mnt"
|
|
|
|
"ipc"
|
|
|
|
"pid"
|
|
|
|
]; # namespaces needed for sandboxing
|
|
|
|
SystemCallFilter = [
|
|
|
|
"@system-service"
|
|
|
|
"@cpu-emulation"
|
|
|
|
"@mount"
|
|
|
|
"@privileged"
|
|
|
|
];
|
2025-01-08 19:06:22 +01:00
|
|
|
|
|
|
|
LockPersonality = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectKernelModules = true; # todo: does kvm need a modprobe here?
|
|
|
|
PrivateMounts = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
ProtectClock = true;
|
|
|
|
|
|
|
|
# file system
|
2025-01-09 13:54:25 +01:00
|
|
|
# PrivateTmp = true; # breaks --keep-failed
|
2025-01-08 19:06:22 +01:00
|
|
|
ProtectSystem = "strict";
|
2025-01-09 13:54:25 +01:00
|
|
|
ReadWritePaths = [
|
|
|
|
"/nix"
|
|
|
|
"/tmp"
|
|
|
|
];
|
2025-01-08 19:06:22 +01:00
|
|
|
|
|
|
|
# Scheduling: only do as much as resources are available
|
|
|
|
LimitNICE = 1;
|
|
|
|
Nice = 19;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
|
|
|
|
# devices
|
|
|
|
DevicePolicy = "closed"; # allow pseudo-devices like /dev/null, but no real devices
|
|
|
|
DeviceAllow = "/dev/kvm"; # kvm is needed for VM tests
|
|
|
|
|
|
|
|
CapabilityBoundingSet = [
|
2025-01-09 13:54:25 +01:00
|
|
|
"CAP_FOWNER"
|
|
|
|
"CAP_CHOWN"
|
|
|
|
"CAP_SETUID"
|
|
|
|
"CAP_SETGID"
|
|
|
|
"CAP_SYS_ADMIN"
|
|
|
|
"CAP_DAC_OVERRIDE"
|
|
|
|
];
|
2025-01-08 19:06:22 +01:00
|
|
|
|
|
|
|
# ProtectKernelLogs=true; # BAD
|
|
|
|
# ProtectKernelTunables = true; # BAD
|
|
|
|
# PrivateUsers=true; BAD
|
|
|
|
# ProtectHome = "read-only"; # BAD
|
|
|
|
# ProtectHostname = true; # BAD!
|
|
|
|
# PrivateNetwork = true; # BAD!
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|