git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #37096 from jfrankenau/feat-cups-socket

nixos/cupsd: Add option to start when needed

commit8bda93f0b2cb32d3002a0f4cc26326abc44697de authorFranz Pletz <fpletz@fnordicwalking.de> dateSun 15 Jul 2018, 21:39 (8 years ago) parenta2eb170d81f819
1 file changed+16−1
nixos/modules/services/printing/cupsd.nix+16−1
nixos/modules/services/printing/cupsd.nix+16−1
@@ -124,6 +124,16 @@ in
124124 '';
125125 };
126126
127+ startWhenNeeded = mkOption {
128+ type = types.bool;
129+ default = false;
130+ description = ''
131+ If set, CUPS is socket-activated; that is,
132+ instead of having it permanently running as a daemon,
133+ systemd will start it on the first incoming connection.
134+ '';
135+ };
136+
127137 listenAddresses = mkOption {
128138 type = types.listOf types.str;
129139 default = [ "localhost:631" ];
@@ -287,8 +297,13 @@ in
287297
288298 systemd.packages = [ cups.out ];
289299
300+ systemd.sockets.cups = mkIf cfg.startWhenNeeded {
301+ wantedBy = [ "sockets.target" ];
302+ listenStreams = map (x: replaceStrings ["localhost"] ["127.0.0.1"] (removePrefix "*:" x)) cfg.listenAddresses;
303+ };
304+
290305 systemd.services.cups =
291− { wantedBy = [ "multi-user.target" ];
306+ { wantedBy = optionals (!cfg.startWhenNeeded) [ "multi-user.target" ];
292307 wants = [ "network.target" ];
293308 after = [ "network.target" ];
294309