-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nixos/printers: declarative configuration #55510
Conversation
A note: In my limited testing with lpadmin, if you add an existing printer again, any printer settings you have changed (for the given printer) seem to be reset. (so for example if reconfiguration calls lpadmin again) Not a breaking thing, but possibly a bit annoying. When I poked at /etc/cups/printers.conf , printers had UUIDs. Its also possible the entry it just being overwritten with a new UUID so it only looked like the same entry, I haven't checked. |
1137ffb
to
c2f0eaf
Compare
@deliciouslytyped that's actually my intention here, as the alternative would be that what's written in the nix config and the actual state of the printer can easily diverge, which I wanted to avoid as far as possible. I tried to improve the documentation in that this isn't a one-time thing, but will actually happen on each reboot or restart of cups. "oneshot" means that the |
Found the cups tests, rewriting them to use this instead of manual lpadmin commands… |
Hm. Ok, I guess that's a reasonable decision, but I still feel some cognitive dissonance given that the stuff is basically mutable and on a first look doesn't appear touch any of the values in question. |
c2f0eaf
to
30818c3
Compare
@deliciouslytyped Not sure what you're refering to here, could you explain what do you mean by that? |
f102a13
to
e22ab6d
Compare
@GrahamcOfBorg test printing |
Added support for socket activation, and added a socket activation version to the printing test to catch such errors. |
$client->succeed("lpq -a") =~ /no entries/; | ||
Machine::retry sub { | ||
return 1 if $server->succeed("lpq -a") =~ /no entries/; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here:
$server->waitUntilSucceeds("lpq -a | grep -q -E 'no entries'");
e22ab6d
to
a95a565
Compare
@Mic92 replaced all but one sleep with waitUntilSuceeds (no sure what I could match on to find out that service-based cups is actually ready and accepts printing jobs), and also find out about |
@GrahamcOfBorg test printing |
1e07fa8
to
863830e
Compare
Damn, time for 19.09 already… But rebased, resolved conflicts, adressed more change requests. :) @etu Thanks for your offer! 👍 In addition to doing another round of proofreading and testing with the new changes (and old ones like the waitUntilSucceeds changes which vanished somehow but are now recreated), |
b5407be
to
63cfe71
Compare
Conflicts in the printing test is 01cd466, where it's default socket activated now. |
In light of #53027, would we want to have paper size as a declarative option? |
That could be a very nice thing, at least for us that aren't in the US. But at the moment I'm more worried if we get it in at all before the release. Freeze in 10 days. https://discourse.nixos.org/t/nixos-19-09-feature-freeze/3707 |
e6f7bee
to
325a69a
Compare
Just resolved the conflicts, continuing to have both always-running and socket-activated cups in the tests because why not when I already wrote the code for both. But I don't cling to that. @aaronjanse @etu thank you for reminding me, I already had the code to specify arbitrary ppd options laying around but forgot it was not yet included in this PR. Added those options, handy for working drivers with duplex print and the like, though they obviously don't help against broken drivers like in #53027. Calling in @matthewbauer (:+1: for making socket activation the new default) as new cups module maintainer for decision on what to do with this. |
325a69a
to
0663b99
Compare
0663b99
to
18a5d23
Compare
@GrahamcOfBorg test printing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to work perfectly fine for me, even with setting page size etc :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go 😄 ✨
Thanks so much @florianjacob.
@etu @worldofpeace thanks! :) To anybody lurking here and wanting to try this out, you can use this snippet here on stable 19.03 and then start to configure your printers declaratively right now: { ... }:
let
declarativePrintersNixpkgsFJ = builtins.fetchGit {
name = "florianjacob-nixpkgs-declarative-printers";
url = https://github.com/florianjacob/nixpkgs/;
ref = "declarative-printers";
rev = "18a5d23b55d0b0d1bff6bfd971d471d3064011c2";
};
in {
imports = [
"${declarativePrintersNixpkgsFJ}/nixos/modules/hardware/printers.nix"
];
} |
If nobody comes with any real complaints about this before Friday (2019-09-06), I intend to merge it by then because it works perfectly fine in my tests. |
Looking good, let's go :) |
in { | ||
options = { | ||
hardware.printers = { | ||
ensureDefaultPrinter = mkOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we drop the "ensure" part? It seems redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@edolstra You see a conceptual difference between ensurePrinters
and ensureDefaultPrinter
here, and therefore it's redundant for defaultPrinter
but not for ensurePrinters
, is that correct? I'm at your service. Maybe you could provide some general guidance on this, though?
I started to use those ensure
prefixes to mark options that can only be enforced on a best effort basis on each service reload. In this concrete case, both ensurePrinters
and ensureDefaultPrinter
are translated into lpadmin
command. I can't stop the user from modifying printers / change default printer, but the state will be restored. In case of ensurePrinters
, I deliberately do not try to delete non-listed printers that the user might have added manually. Similar options in NixOS exist though which don't have that prefix.
There's a discussion going on about that, sparked off by similar mysql / postgresql options
I explained my point there as well.
EDIT: corrected link to discussion
Motivation for this change
This saves one from going through the cups webinterface each time one sets up a new NixOS machine.
I created a half-stateful solution similar to
mysql.ensureDatabases
, which useslpadmin
etc. to create the configured printers and force them in the right configuration, without having to touch the deep parts of cups. Works quite well, at least for me.Resolves #52776, supersedes #23684.
Tests, comments & proposals for improvements welcome.
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)