nixos/cupsd: add option to start when needed

Changed files
+16 -1
nixos
modules
services
printing
+16 -1
nixos/modules/services/printing/cupsd.nix
···
'';
};
+
startWhenNeeded = mkOption {
+
type = types.bool;
+
default = false;
+
description = ''
+
If set, CUPS is socket-activated; that is,
+
instead of having it permanently running as a daemon,
+
systemd will start it on the first incoming connection.
+
'';
+
};
+
listenAddresses = mkOption {
type = types.listOf types.str;
default = [ "localhost:631" ];
···
systemd.packages = [ cups.out ];
+
systemd.sockets.cups = mkIf cfg.startWhenNeeded {
+
wantedBy = [ "sockets.target" ];
+
listenStreams = map (x: replaceStrings ["localhost"] ["127.0.0.1"] (removePrefix "*:" x)) cfg.listenAddresses;
+
};
+
systemd.services.cups =
-
{ wantedBy = [ "multi-user.target" ];
+
{ wantedBy = optionals (!cfg.startWhenNeeded) [ "multi-user.target" ];
wants = [ "network.target" ];
after = [ "network.target" ];