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

Add NixOS module: xidlehook #76063

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

chkno
Copy link
Member

@chkno chkno commented Dec 19, 2019

Motivation for this change

xautolock has been unmaintained since 2007 and has bugs. xidlehook is the new hotness. This module is intended to be a drop-in replacement for xautolock -- users can just replace all occurrences of xautolock with xidlehook in their configs & be switched over†.

† (And delete nowlocker, which has no counterpart, but was typically just the same thing as locker.)

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • 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 nix-review --run "nix-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)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @WilliButz @Ma27

Copy link
Member

@Ma27 Ma27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Haven't tested it yet (I don't use xautolock anymore since I switched to Wayland a while ago), but may be able to do this next week unless somebody is faster. Apart from the two, minor comments, some additional thoughts about this:

  • I'd recommend to add an entry to the release-notes (those can be found in nixos/doc/manual/release-notes/rl-2003.xml) to encourage users to switch.
  • This module needs to be included by adding it to nixos/modules/module-list.nix.
  • There's a fairly simple test for xautolock. Could you please adapt this one for xidlehook?
  • I don't think that we want to have the drop-in options forever. I haven't found a simple way to mark options as deprecated, but I'd mark those as deprecated (at least by noting this in the description).

nixos/modules/services/x11/xidlehook.nix Outdated Show resolved Hide resolved
nixos/modules/services/x11/xidlehook.nix Show resolved Hide resolved
@chkno chkno force-pushed the nixos-module-xidlehook branch 3 times, most recently from eb96a35 to e2648a3 Compare December 19, 2019 22:53
@chkno
Copy link
Member Author

chkno commented Dec 19, 2019

Release note: Done.
module-list.nix: Done.
Test: Done.
Default in config to avoid documentation rebuilds: Done.
Why uniq?: I added a note.

  • I don't think that we want to have the drop-in options forever. I haven't found a simple way to mark options as deprecated, but I'd mark those as deprecated (at least by noting this in the description).

I don't want the xautolock-compatibility options to ever be more-deprecated than xautolock itself is; I want the path from xautolock -> xidlehook-with-compat-options -> xidlehook-trigger-list to be monotonically encouraging. Also, separately, I have a lot of sympathy for people being busy & not wanting to mess with config that is working for them, & thus I wouldn't mind the xautolock-compatibility options sticking around for many years. It's a bit weird that xautolock would leave a legacy imprint on xidlehook configuration even after it is long gone, but it doesn't seem terrible.

... Other than the seconds vs. minutes inconsistency in the threshold options. That part is terrible. But I feel so excited about making the path from xautolock to xidlehook as smooth as possible that I'm reluctant to introduce even the modest extra step of "Oh, now convert your notify threshold from seconds to fractional minutes (or convert your lock and kill times to seconds) so that they're all in consistent units." It makes sense to me to defer that churn to later -- maybe along with the removal of the xautolock module after its deprecation.

(Responses to review comments are visible as separate commits here: https://github.com/chkno/nixpkgs/commits/nixos-module-xidlehook-review-responses )

Thanks!

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some things to improve. Also the manual doesn't build, check with nix-build nixos/release.nix -A manual.x86_64-linux

nixos/modules/services/x11/xidlehook.nix Outdated Show resolved Hide resolved
assertion = builtins.substring 0 1 timer.command == "/";
message = "Please specify canonical paths for `services.xserver.xidlehook.timers` commands";
}) cfg.timers) ++ (map (timer: {
assertion = (timer.canceller or "") != "" -> builtins.substring 0 1 timer.command == "/";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be timer.canceller?

And this shouldn't be necessary if you set the type of canceller to nullOr path. Same for the other options, specifying the path type automatically ensures an initial /

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be timer.canceller?

Yes! Fixed. Thanks!

And this shouldn't be necessary if you set the type of canceller to nullOr path. Same for the other options, specifying the path type automatically ensures an initial /

It's not a path, though. It's a command -- it's a path up to the first space, and then not. In addition to being misleading as documentation, this would break if the path type later gained additional validation like checking path name component length (chars between /s) or normalizations like replacing /./ with /


killer = mkOption {
default = null; # default according to `man xautolock` is none
example = "${pkgs.systemd}/bin/systemctl suspend";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs exampleText = "\${pkgs.systemd}/bin/systemctl suspend", same for other default's that have ${} in them

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is exampleText?

I tried adding \ to the $s in these examples. They still didn't render well in the manual:

-Example: ''''${pkgs.libnotify}/bin/notify-send "Locking in 10 seconds"''
+Example: ''''${pkgs.libnotify}/bin/notify-send "Locking in ''${toString cfg.notify} seconds"''

So I switched them all to literalExample. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, I mixed it up with defaultText. Looking good now

command = cfg.killer;
}));

environment.systemPackages = optional cfg.enable pkgs.xidlehook;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed in the system environment? E.g. do users need to call the binary themselves for some reason? If not this can be removed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary to get xidlehook-client in $PATH, which is the equivalent of xscreensaver-command & is used for things like lock-now keyboard shortcuts.

# be brought to the attention of the user. Just appending one to the other
# usually would not make sense and definitely should not be done implicitly and
# silently.
type = types.uniq (types.listOf (types.submodule {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, the list type should be avoided if possible. And in this case this can work well by just having to name the timers such that this can be attrsOf submodule. This then also won't clear timers specified with the compatibility options if users set them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't make sense to me to ever merge timer lists because the durations are relative -- inserting a timer entry delays all the timers after it. For example, if you wish screens to lock after 10 minutes of inactivity and then wish to insert something before this entry that happens after 3 minutes of inactivity, you must modify the screen-lock timer's duration from 10 minutes to 7 minutes, because it is specified relative to the previous timer.

Contemplating a hypothetical for just a moment: We could make the Nix configuration use absolute timer durations and convert these to relative durations to pass them to xidlehook. But this diverges from how xidlehook is normally used & would confuse users trying to move existing xidlehook configuration to NixOS. Also, it opens up the question of how to merge cancellers. If the Nth timer's action both undoes the previous timer's action and performs its own (as in upstream's xrandr-dimmer example) what happens when another timer is inserted between them? One could imagine providing a merge-friendly interface that does stack unwinding, automatically adding each timer's canceller onto the next timer's action such that timers could be inserted at any point and still have everything chained correctly. This is now mergable, but it is very different than the normal semantics of xidlehook.

Instead, I think it makes sense to treat one timer-list as one opaque value. If two timer-lists are specified, this should raise an error that can be resolved by choosing one of them with mkForce.

xautolock has been unmaintained since 2007.
(xss-lock, the other contender, has been unmaintained since 2014.)
xidlehook is the new deal.  It oughta have at least as much support
in NixOS as xautolock has.  In the long run, it might make sense to
deprecate the xautolock module in favor of this one.
Omitted: `nowlocker`, which has no counterpart in xidlehook, and was
usually just set to the same value as `locker`.
machine.start()
machine.wait_for_x()
machine.fail("pgrep xlock")
machine.sleep(120)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to reduce this time? (just to be sure Hydra won't timeout on this test in future)

@stale
Copy link

stale bot commented Jun 20, 2020

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 20, 2020
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 20, 2024
@wegank wegank marked this pull request as draft March 20, 2024 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants