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/xautolock: fix default defaults/examples, add assertions #34470
Conversation
e855785
to
c2fa5f1
Compare
@GrahamcOfBorg eval (a commit broke master, and it is now fixed.) |
example = "i3lock -i /path/to/img"; | ||
type = types.string; | ||
default = "${pkgs.xlockmore}/bin/xlock"; # default according to `man xautolock` | ||
example = "${pkgs.i3lock}/bin/i3lock -i /path/to/img"; |
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.
Using the literalExample
function would make sense here. Otherwise it will put the store path into the manual.
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.
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.
This is from my man configuration.nix
services.xserver.xautolock.locker
The script to use when automatically locking the computer.
Type: string
Default: "\${pkgs.xlockmore}/bin/xlock"
Example: "\${pkgs.i3lock}/bin/i3lock -i /path/to/img"
Declared by:
<nixpkgs/nixos/modules/services/x11/xautolock.nix>
(note the escaped '$', that's a part of what the above mentioned PR is about)
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.
Ok. The store path does not get expanded.
] ++ (lib.flip map [ "locker" "notifier" "nowlocker" "killer" ] | ||
(option: | ||
{ | ||
assertion = cfg."${option}" != null -> builtins.substring 0 1 cfg."${option}" == "/"; |
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.
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.
Yes, I think this should be done using a shell script.
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.
I agree that using "reboot" would not work just like that. Though one could easily specify an absolute path:
services.xserver.xautlock.locker = "${pkgs.systemd}/bin/reboot";
Also this way it can be done using just nix itself and the path can be found by using readlink $(which someCommand)
for example. I'm still open to suggestions :)
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.
Maybe there are some users already happily use xautolock service by setting locker = "poweroff"
. If we only allow absolute path, this PR will force them to change their configuration.nix
.
Also there is no downside if we uses if [[ -x ${cfg."${option}"} ]]
to check if the value is an executable or not, right?
However, I think you are right and this is just a subtle improvement. The service will still work fine without the executable testing technique.
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.
@sifmelcara as far as I know this would not work just like that, as the -x
flag checks if the following 'file' exists and is executable (see man bash
). "poweroff"
itself is neither a file nor executable in that context and therefore the condition would evaluate to false:
if [[ -x poweroff ]]; then echo "it works"; else echo "it doesn't work"; fi
On the other hand, this would work if poweroff
was replaced with "$(which poweroff)"
in the condition.
I think that changing the module to expect absolute paths wouldn't be much of a problem as the message in the assertion should give enough information on why the evaluation failed for someone who has something like "poweroff"
in the config.
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.
Oh you are definitely right. Anyway, thank you for your great works!
Can this be integrated? |
Motivation for this change
see issue #34371
Things done
build-use-sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)/cc @fpletz