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/printing: set wantedBy to printer.target if startWhenNeeded #358452

Closed
wants to merge 1 commit into from

Conversation

hackerncoder
Copy link
Contributor

Upstream sets wantedBy to [ multi-user.target printer.target ] so old option would always start cups on multi-user.target

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

Upstream sets wantedBy to [ multi-user.target printer.target ] so old option
would always start cups on multi-user.target
@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 6.topic: printing labels Nov 23, 2024
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Nov 24, 2024
@hackerncoder
Copy link
Contributor Author

@matthewbauer You are listed as maintainers, requesting review.

@rnhmjoj
Copy link
Contributor

rnhmjoj commented Dec 1, 2024

I've tested nixosTests.printing-socket, which does startWhenNeeded = true and the cups service seems to behave as expected. The test uses hardware.printers.ensurePrinters to setup printers on boot, so cupsd is started and the printers are configured, but it's stopped soon afterwards. Also, if I remove ensurePrinters cups is never started.

How can I reproduce your issue?

@hackerncoder
Copy link
Contributor Author

Turns out

Note that for drop-in files, if one wants to remove entries from a setting that is parsed as a list (and is not a dependency), such as AssertPathExists= (or e.g. ExecStart= in service units), one needs to first clear the list before re-adding all entries except the one that is to be removed. Dependencies (After=, etc.) cannot be reset to an empty list, so dependencies can only be added in drop-ins. If you want to remove dependencies, you have to override the entire unit.

https://man7.org/linux/man-pages/man5/systemd.unit.5.html

Setting WantedBy in the module is therefore meaningless, WantedBy is always [ multi-user.target printer.target ].

@rnhmjoj
Copy link
Contributor

rnhmjoj commented Dec 2, 2024

I think you're confused by how NixOS handles the installation of units. Specifically, the [Install] section of a unit is wholly ignored because units are never enabled using systemctl enable:

  wantedBy = mkOption {
    default = [];
    type = types.listOf unitNameType;
    description = ''
      Units that want (i.e. depend on) this unit. The default method for
      starting a unit by default at boot time is to set this option to
      `["multi-user.target"]` for system services. Likewise for user units
      (`systemd.user.<name>.*`) set it to `["default.target"]` to make a unit
      start by default when the user `<name>` logs on.

      This option creates a `.wants` symlink in the given target that exists
      statelessly without the need for running `systemctl enable`.
      The `[Install]` section described in {manpage}`systemd.unit(5)` however is
      not supported because it is a stateful process that does not fit well
      into the NixOS design.
    '';
  };

See also #81138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: printing 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants