Commit Graph

23 Commits

Author SHA1 Message Date
Martin Fischer
d0e302d6c7 nixos/printers: fix empty value handling in ensurePrinters
E.g. this configuration:

    hardware.printers.ensurePrinters = [
      {
        name = "test";
        deviceUri = "ipp://somewhere";
        location = "";
        model = "everywhere";
      }
    ];

Resulted in the following command being generated:

    /nix/store/...-cups-2.4.19/bin/lpadmin -L -meverywhere -ptest -vipp://somewhere -E

Note the missing '' after -L which then caused /etc/cups/printers.conf to contain:

    Info test
    Location -meverywhere
    DeviceURI ipp://somewhere

This bug was introduced in 1f4c50ab81 with the
change from the (now deprecated) toGNUCommandLineShell to toCommandLineShellGNU.

Assisted-by: pi (OpenAI gpt-5.5)
2026-09-25 13:56:42 +02:00
Robert Schütz
cd1fdc1df9 nixos/printers: assert that each class contains at least one printer or class 2026-09-16 17:43:53 -07:00
h7x4
85e3dd1d48 nixos/printers: collect provisioning into CUPS' ExecStartPost
Instead of keeping multiple interdependent systemd units, it's both
cleaner and more stable to just keep all provisioning as a direct part
of the cups unit. This gets rid of all the machinery around whether or
not the unit was socket activated as well, as the provisioning scripts
now will lazily run whenever cups is activated.
2026-09-15 17:45:32 +09:00
h7x4
d6c83dc6e4 nixos/printing: refactor module
Combine attrs under `config`, and move several let-binding closer to
where they are references.
2026-09-15 17:07:53 +09:00
BenRaz123
b9a84647c1 nixos/hardware.printers: add ensureClasses option
this adds support to CUPS classes in a style similar to the
`hardware.printers.ensurePrinters` option.

Classes in CUPS are groups of printers made by the user, usually in
order to group similar printers. When a job is sent to a class, the job
is attempted at each member printer until it succeeds. Classes can be
thought of as 'logical printers', in that they can behave like printers,
despite being an abstraction solely created by the print server.
2026-08-23 22:24:07 -04:00
Lukas Wurzinger
1f4c50ab81 lib/cli: deprecate toGNUCommandLine 2025-10-21 21:01:38 +02:00
Victor Engmark
6bb5aa2d26 nixos/printers: Fix ShellCheck issue
Fixes the following warning when setting
`systemd.enableStrictShellChecks = true`:

> In /nix/store/a3mk99mgl10a4k3maxx361hdli5p2rip-unit-script-ensure-printers-start/bin/ensure-printers-start line 6:
> /nix/store/26fb46gwc5sbd045nj3dxw4zqpml359i-cups-2.4.11/bin/lpadmin -D 'virtual printer for cups-pdf instance pdf' -L '/var/spool/cups-pdf-pdf/users/${USER}' -m CUPS-PDF_opt.ppd -p pdf -v cups-pdf:/pdf -E
>                                                                                                                       ^-- SC2016 (info): Expressions don't expand in single quotes, use double quotes for that.
2025-01-04 18:08:22 +01:00
Silvan Mosberger
4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00
Felix Buehler
22946376a9 nixos/hardware.printers: remove with lib; 2024-08-30 22:59:21 +02:00
Yarny0
d93fb1bd10 nixos/hardware/printers: fix ppdOptions of ensured printers
Commit a52e27d4f6
changed the `ensurePrinter` mechanism such that it uses
`lib.cli.toGNUCommandLineShell` to assemble the
`lpadmin` command line that creates the required printer.
Before that commit, the command line contained
single quotes (')to protect certain options from being
(mis-)interpreted by the shell.
The new mechanism no longer needs those quotes as
`lib.cli.toGNUCommandLineShell` takes care of quoting/escaping.
Unfortunatelly, the commit missed the
quotes around the `-o` command line part.
`lib.cli.toGNUCommandLineShell` now properly escapes
those quotes, thereby including them in the effective
command line arguments that are passed to `lpadmin`.
The result is that no option is applied anymore.

The commit at hand simply removes the superfluous quotes.
With this change, options are again properly applied as before.
2024-05-16 18:55:28 +02:00
stuebinm
6afb255d97 nixos: remove all uses of lib.mdDoc
these changes were generated with nixq 0.0.2, by running

  nixq ">> lib.mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix
  nixq ">> mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix
  nixq ">> Inherit >> mdDoc[remove]" --batchmode nixos/**.nix

two mentions of the mdDoc function remain in nixos/, both of which
are inside of comments.

Since lib.mdDoc is already defined as just id, this commit is a no-op as
far as Nix (and the built manual) is concerned.
2024-04-13 10:07:35 -07:00
Ryan Horiguchi
a52e27d4f6 nixos/hardware/printers: fix empty ppdOptions 2024-02-25 19:06:35 +01:00
Michele Guerini Rocco
5dff7733aa Merge pull request #203454 from rnhmjoj/pr-cups-socket
nixos/hardware/printers: stop cupsd when unneeded
2022-12-21 23:06:00 +01:00
figsoda
6bb0dbf91f nixos: fix typos 2022-12-17 19:31:14 -05:00
rnhmjoj
47d9e7d3d7 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.
2022-12-07 15:57:44 +01:00
pennae
2e751c0772 treewide: automatically md-convert option descriptions
the conversion procedure is simple:

 - find all things that look like options, ie calls to either `mkOption`
   or `lib.mkOption` that take an attrset. remember the attrset as the
   option
 - for all options, find a `description` attribute who's value is not a
   call to `mdDoc` or `lib.mdDoc`
 - textually convert the entire value of the attribute to MD with a few
   simple regexes (the set from mdize-module.sh)
 - if the change produced a change in the manual output, discard
 - if the change kept the manual unchanged, add some text to the
   description to make sure we've actually found an option. if the
   manual changes this time, keep the converted description

this procedure converts 80% of nixos options to markdown. around 2000
options remain to be inspected, but most of those fail the "does not
change the manual output check": currently the MD conversion process
does not faithfully convert docbook tags like <code> and <package>, so
any option using such tags will not be converted at all.
2022-07-30 15:16:34 +02:00
Luke Granger-Brown
b4b663efc8 Merge pull request #132713 from ncfavier/cups
cups: 2.3.3 -> 2.3.3op2
2021-10-14 14:54:08 +01:00
Naïm Favier
2ddc335e6f nixos/doc: clean up defaults and examples 2021-10-04 12:47:20 +02:00
Naïm Favier
2f8ae51da9 cups: 2.3.3 -> 2.3.3op2
https://github.com/OpenPrinting/cups/releases/tag/v2.3.3op1
https://github.com/OpenPrinting/cups/releases/tag/v2.3.3op2
2021-09-19 16:17:05 +02:00
nyanotech
6a22ce0edf nixos/printers: fix ensureDefaultPrinter
`lpoptions -d` sets the default printer *for this user*, while `lpadmin -d`
  sets the system-wide default printer.
2021-04-17 12:33:31 +00:00
Justin Humm
6a7713449f nixos/printers: fix example for hardware.printers.ensurePrinters.*.model
It's `lib.versions`, not `lib.version`. Also I'm really sure that it's
supposed to be the current version of Gutenprint, not Cups, as thats
what `lpinfo -m` says on my system.
2020-04-28 22:47:57 +02:00
volth
7b8fb5c06c treewide: remove redundant quotes 2019-09-08 23:38:31 +00:00
Florian Jacob
18a5d23b55 nixos/printers: declarative configuration 2019-09-01 15:38:30 +02:00