3
0
Fork 0
forked from mirrors/nixpkgs

nixos/hardware/printers: stop cupsd when unneeded

If socket activation is enable (the default) and printers are configured
declaratively, the ensure-printers service will always start cupsd and
leave it running, thus defeating the point of socket activation.

With this change ensure-printers continues to start the cups.service at
boot, but automatically stops it afterwards if socket activation is
enabled.

Note: Later restarts of ensure-printers will also restart cupsd, but
it's not an issue since it will be reactivate, if necessary.
This commit is contained in:
rnhmjoj 2022-11-28 14:50:41 +01:00
parent a5eb3b03ff
commit 47d9e7d3d7
No known key found for this signature in database
GPG key ID: BFBAF4C975F76450

View file

@ -110,21 +110,26 @@ in {
};
config = mkIf (cfg.ensurePrinters != [] && config.services.printing.enable) {
systemd.services.ensure-printers = let
cupsUnit = if config.services.printing.startWhenNeeded then "cups.socket" else "cups.service";
in {
systemd.services.ensure-printers = {
description = "Ensure NixOS-configured CUPS printers";
wantedBy = [ "multi-user.target" ];
requires = [ cupsUnit ];
after = [ cupsUnit ];
wants = [ "cups.service" ];
after = [ "cups.service" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
script = concatMapStringsSep "\n" ensurePrinter cfg.ensurePrinters
+ optionalString (cfg.ensureDefaultPrinter != null) (ensureDefaultPrinter cfg.ensureDefaultPrinter);
script = concatStringsSep "\n" [
(concatMapStrings ensurePrinter cfg.ensurePrinters)
(optionalString (cfg.ensureDefaultPrinter != null)
(ensureDefaultPrinter cfg.ensureDefaultPrinter))
# Note: if cupsd is "stateless" the service can't be stopped,
# otherwise the configuration will be wiped on the next start.
(optionalString (with config.services.printing; startWhenNeeded && !stateless)
"systemctl stop cups.service")
];
};
};
}