nixos/printing: add services.printing.stateless option

This will remove all state directories related to CUPS on startup, which
is particularly useful for guaranteeing that printer discovery works
more reliably on some networks, since CUPS will no longer be able to
store state that effects the next run of the service, such as old
printer names and mDNS information.

Co-authored-by: Sandro <sandro.jaeckel@gmail.com>

Changed files
+13 -2
nixos
modules
services
printing
tests
+12 -2
nixos/modules/services/printing/cupsd.nix
···
'';
};
+
stateless = mkOption {
+
type = types.bool;
+
default = false;
+
description = lib.mdDoc ''
+
If set, all state directories relating to CUPS will be removed on
+
startup of the service.
+
'';
+
};
+
startWhenNeeded = mkOption {
type = types.bool;
default = true;
···
path = [ cups.out ];
-
preStart =
-
''
+
preStart = lib.optionalString cfg.stateless ''
+
rm -rf /var/cache/cups /var/lib/cups /var/spool/cups
+
'' + ''
mkdir -m 0700 -p /var/cache/cups
mkdir -m 0700 -p /var/spool/cups
mkdir -m 0755 -p ${cfg.tempDir}
+1
nixos/tests/printing.nix
···
let
printingServer = startWhenNeeded: {
services.printing.enable = true;
+
services.printing.stateless = true;
services.printing.startWhenNeeded = startWhenNeeded;
services.printing.listenAddresses = [ "*:631" ];
services.printing.defaultShared = true;