git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/cupsd: add option to start when needed
commitd81f819db35fe833d935486439d085bd5c3e85da authorJohannes Frankenau <johannes@frankenau.net> dateThu 15 Mar 2018, 12:55 (9 years ago) parent23f5fe7
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