Skip to content
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

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
4 participants
@florianjacob
Copy link
Contributor

florianjacob commented Feb 10, 2019

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 uses lpadmin 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
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@deliciouslytyped

This comment has been minimized.

Copy link
Contributor

deliciouslytyped commented Feb 10, 2019

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.
What is the behavior of "oneshot"?

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.

@florianjacob

This comment has been minimized.

Copy link
Contributor Author

florianjacob commented Feb 10, 2019

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)

@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 lpadmin commands are run like a script on startup of cups. The main identifier is the printer name here; so subsequent lpadmin calls from the service will modify the existing printer.

@florianjacob

This comment has been minimized.

Copy link
Contributor Author

florianjacob commented Feb 10, 2019

Found the cups tests, rewriting them to use this instead of manual lpadmin commands…

@deliciouslytyped

This comment has been minimized.

Copy link
Contributor

deliciouslytyped commented Feb 10, 2019

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.
TL;DR: I don't know what to do/think about it, just a little uneasy.

@florianjacob florianjacob force-pushed the florianjacob:declarative-printers branch from c2f0eaf to 30818c3 Feb 10, 2019

@florianjacob

This comment has been minimized.

Copy link
Contributor Author

florianjacob commented Feb 10, 2019

and on a first look doesn't appear touch any of the values in question

@deliciouslytyped Not sure what you're refering to here, could you explain what do you mean by that?

@florianjacob florianjacob force-pushed the florianjacob:declarative-printers branch 2 times, most recently from f102a13 to e22ab6d Feb 10, 2019

@florianjacob

This comment has been minimized.

Copy link
Contributor Author

florianjacob commented Feb 10, 2019

@GrahamcOfBorg test printing

@florianjacob

This comment has been minimized.

Copy link
Contributor Author

florianjacob commented Feb 10, 2019

Added support for socket activation, and added a socket activation version to the printing test to catch such errors.

# Print the file on the client.
$client->succeed("lp $file");
$client->sleep(10);
$client->succeed("lpq") =~ /active.*root.*$fn/ or die;

This comment has been minimized.

@Mic92

Mic92 Feb 10, 2019

Contributor

Would the following work instead of this sleep 10?

$one->waitUntilSucceeds("lpq | grep -q -E '/active.*root.*$fn/'");
# file will stay in the queue forever.
$server->waitForFile("/var/spool/cups/d*-001");
$server->sleep(10);
$server->succeed("lpq -a") =~ /$fn/ or die;

This comment has been minimized.

@Mic92

Mic92 Feb 10, 2019

Contributor

maybe?

$server->waitUntilSucceeds("lpq -a | grep -q -E '$fn'");
$client->succeed("lpq -a") =~ /no entries/;
Machine::retry sub {
return 1 if $server->succeed("lpq -a") =~ /no entries/;
};

This comment has been minimized.

@Mic92

Mic92 Feb 10, 2019

Contributor

Also here:

$server->waitUntilSucceeds("lpq -a | grep -q -E 'no entries'");

@florianjacob florianjacob force-pushed the florianjacob:declarative-printers branch from e22ab6d to a95a565 Feb 14, 2019

@florianjacob

This comment has been minimized.

Copy link
Contributor Author

florianjacob commented Feb 14, 2019

@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 $machine->name() with which I could replace the my name = $machine->succeeds('hostname'); chomp $name; calls inside the testing function.

@florianjacob

This comment has been minimized.

Copy link
Contributor Author

florianjacob commented Feb 14, 2019

@GrahamcOfBorg test printing

@florianjacob florianjacob force-pushed the florianjacob:declarative-printers branch 3 times, most recently from 1e07fa8 to 863830e Feb 14, 2019

@florianjacob florianjacob force-pushed the florianjacob:declarative-printers branch from 863830e to e83f981 Feb 25, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.