2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2014-01-17 09:02:13 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2014-01-17 09:02:13 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.haveged;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.haveged = {
|
|
|
|
|
2021-12-17 03:53:54 +00:00
|
|
|
enable = mkEnableOption ''
|
|
|
|
haveged entropy daemon, which refills /dev/random when low.
|
|
|
|
NOTE: does nothing on kernels newer than 5.6.
|
|
|
|
'';
|
|
|
|
# source for the note https://github.com/jirka-h/haveged/issues/57
|
2020-08-07 14:43:58 +01:00
|
|
|
|
2014-01-17 09:02:13 +00:00
|
|
|
refill_threshold = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 1024;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2014-01-17 09:02:13 +00:00
|
|
|
The number of bits of available entropy beneath which
|
|
|
|
haveged should refill the entropy pool.
|
|
|
|
'';
|
|
|
|
};
|
2020-08-07 14:43:58 +01:00
|
|
|
|
2014-01-17 09:02:13 +00:00
|
|
|
};
|
2020-08-07 14:43:58 +01:00
|
|
|
|
2014-01-17 09:02:13 +00:00
|
|
|
};
|
2020-08-07 14:43:58 +01:00
|
|
|
|
2014-01-17 09:02:13 +00:00
|
|
|
config = mkIf cfg.enable {
|
2020-08-07 14:43:58 +01:00
|
|
|
|
2021-12-17 03:53:54 +00:00
|
|
|
# https://github.com/jirka-h/haveged/blob/a4b69d65a8dfc5a9f52ff8505c7f58dcf8b9234f/contrib/Fedora/haveged.service
|
|
|
|
systemd.services.haveged = {
|
|
|
|
description = "Entropy Daemon based on the HAVEGE algorithm";
|
|
|
|
unitConfig = {
|
|
|
|
Documentation = "man:haveged(8)";
|
|
|
|
DefaultDependencies = false;
|
|
|
|
ConditionKernelVersion = "<5.6";
|
|
|
|
};
|
|
|
|
wantedBy = [ "sysinit.target" ];
|
|
|
|
after = [ "systemd-tmpfiles-setup-dev.service" ];
|
|
|
|
before = [ "sysinit.target" "shutdown.target" "systemd-journald.service" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.haveged}/bin/haveged -w ${toString cfg.refill_threshold} --Foreground -v 1";
|
|
|
|
Restart = "always";
|
|
|
|
SuccessExitStatus = "137 143";
|
|
|
|
SecureBits = "noroot-locked";
|
|
|
|
CapabilityBoundingSet = [ "CAP_SYS_ADMIN" "CAP_SYS_CHROOT" ];
|
|
|
|
# We can *not* set PrivateTmp=true as it can cause an ordering cycle.
|
|
|
|
PrivateTmp = false;
|
|
|
|
PrivateDevices = true;
|
|
|
|
ProtectSystem = "full";
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = [ "@system-service" "newuname" "~@mount" ];
|
|
|
|
SystemCallErrorNumber = "EPERM";
|
2014-01-17 09:02:13 +00:00
|
|
|
};
|
|
|
|
|
2021-12-17 03:53:54 +00:00
|
|
|
};
|
2014-01-17 09:02:13 +00:00
|
|
|
};
|
2020-08-07 14:43:58 +01:00
|
|
|
|
2014-11-19 11:56:32 +00:00
|
|
|
}
|