NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.87k stars 13.94k forks source link

wantedBy not working when used from upstream systemd units #81138

Open worldofpeace opened 4 years ago

worldofpeace commented 4 years ago

Describe the bug I've noticed on several occasions, and again with a PR https://github.com/NixOS/nixpkgs/pull/81087 which has a unit

# tlp - systemd startup/shutdown service
#
# Copyright (c) 2020 Thomas Koch <linrunner at gmx.net> and others.
# This software is licensed under the GPL v2 or later.

[Unit]
Description=TLP system startup/shutdown
After=multi-user.target NetworkManager.service
Before=shutdown.target
Documentation=https://linrunner.de/tlp

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/nix/store/42m41jbsvbc7qh25k42cdc5jf2yjsf87-tlp-1.3.1/sbin/tlp init start
ExecStop=/nix/store/42m41jbsvbc7qh25k42cdc5jf2yjsf87-tlp-1.3.1/sbin/tlp init stop

[Install]
WantedBy=multi-user.target

The wantedBy didn't do anything when it was included with systemd.packages.

We had to add it manually like:

systemd.services.tlp.wantedBy =  [ "multi-user.target" ];

Looking at nixpkgs, it seems like others have noticed this.

worldofpeace commented 4 years ago

Similarly, we had to do wants manually in gnome-settings-daemon https://github.com/NixOS/nixpkgs/blob/954d44f875c20069478c05b1c81c11da7669944e/nixos/modules/services/desktops/gnome3/gnome-settings-daemon.nix#L50. But everything has the links in the package.

lheckemann commented 4 years ago

I'm guessing that the [Install] section, which is put into effect by systemctl enable which in turn creates symlinks in /etc/systemd/system/multi-user.target.wants (for instance), is not currently respected by systemd.packages. EDIT: i.e. we need to use or emulate the behaviour of systemctl enable

stale[bot] commented 4 years ago

Hello, I'm a bot and I thank you in the name of the community for opening this issue.

To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.

If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.

Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.

worldofpeace commented 4 years ago

this is still really important

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

aanderse commented 3 years ago

Still relevant.

nixos-discourse commented 3 years ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/disable-a-systemd-service-while-having-it-in-nixoss-conf/12732/3

ElvishJerricco commented 1 year ago

Can't we just run systemctl enable --root=where/ever * or something?

aanderse commented 1 year ago

@ElvishJerricco can you elaborate on the --root=where/ever part?

ElvishJerricco commented 1 year ago

@aanderse When building the generateUnits derivation, we could do something along the lines of for x in ${units}; do systemctl enable --root=$out $x; done. The --root arg makes it operate on a different root tree and not on any running daemon, so all it will do is create necessary symlinks and implement the [Install] section.