Merge pull request #37096 from jfrankenau/feat-cups-socket

nixos/cupsd: Add option to start when needed
This commit is contained in:
Franz Pletz 2018-07-15 21:39:07 +00:00 committed by GitHub
commit 8bda93f0b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -124,6 +124,16 @@ in
''; '';
}; };
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 { listenAddresses = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = [ "localhost:631" ]; default = [ "localhost:631" ];
@ -287,8 +297,13 @@ in
systemd.packages = [ cups.out ]; 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 = systemd.services.cups =
{ wantedBy = [ "multi-user.target" ]; { wantedBy = optionals (!cfg.startWhenNeeded) [ "multi-user.target" ];
wants = [ "network.target" ]; wants = [ "network.target" ];
after = [ "network.target" ]; after = [ "network.target" ];