about summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorMichele Guerini Rocco <rnhmjoj@users.noreply.github.com>2022-12-21 23:06:00 +0100
committerGitHub <noreply@github.com>2022-12-21 23:06:00 +0100
commit5dff7733aac371c0390b2e8b52935883e4762031 (patch)
tree685a4e9865a9f5375ac8e5bd03d5258747df0c73 /nixos/modules
parentdac3b0d87329edf225ea7d2ed68b9ab79ca8c53b (diff)
parent4f67365482305a0fec444b725b131c82c563982b (diff)
downloadnixlib-5dff7733aac371c0390b2e8b52935883e4762031.tar
nixlib-5dff7733aac371c0390b2e8b52935883e4762031.tar.gz
nixlib-5dff7733aac371c0390b2e8b52935883e4762031.tar.bz2
nixlib-5dff7733aac371c0390b2e8b52935883e4762031.tar.lz
nixlib-5dff7733aac371c0390b2e8b52935883e4762031.tar.xz
nixlib-5dff7733aac371c0390b2e8b52935883e4762031.tar.zst
nixlib-5dff7733aac371c0390b2e8b52935883e4762031.zip
Merge pull request #203454 from rnhmjoj/pr-cups-socket
nixos/hardware/printers: stop cupsd when unneeded 
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/hardware/printers.nix19
-rw-r--r--nixos/modules/services/printing/cupsd.nix7
2 files changed, 14 insertions, 12 deletions
diff --git a/nixos/modules/hardware/printers.nix b/nixos/modules/hardware/printers.nix
index 85e3215127fd..846ff6f3fb4f 100644
--- a/nixos/modules/hardware/printers.nix
+++ b/nixos/modules/hardware/printers.nix
@@ -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")
+      ];
     };
   };
 }
diff --git a/nixos/modules/services/printing/cupsd.nix b/nixos/modules/services/printing/cupsd.nix
index ae59dcc226de..9ac89e057620 100644
--- a/nixos/modules/services/printing/cupsd.nix
+++ b/nixos/modules/services/printing/cupsd.nix
@@ -341,7 +341,7 @@ in
 
     systemd.sockets.cups = mkIf cfg.startWhenNeeded {
       wantedBy = [ "sockets.target" ];
-      listenStreams = [ "/run/cups/cups.sock" ]
+      listenStreams = [ "" "/run/cups/cups.sock" ]
         ++ map (x: replaceStrings ["localhost"] ["127.0.0.1"] (removePrefix "*:" x)) cfg.listenAddresses;
     };
 
@@ -395,10 +395,7 @@ in
             ''}
           '';
 
-          serviceConfig = {
-            PrivateTmp = true;
-            RuntimeDirectory = [ "cups" ];
-          };
+          serviceConfig.PrivateTmp = true;
       };
 
     systemd.services.cups-browsed = mkIf avahiEnabled