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/xautolock: fix default defaults/examples, add assertions #34470

Merged
merged 1 commit into from Feb 22, 2018

Conversation

WilliButz
Copy link
Member

@WilliButz WilliButz commented Jan 31, 2018

Motivation for this change

see issue #34371

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-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/)
  • Fits CONTRIBUTING.md.

/cc @fpletz

@grahamc
Copy link
Member

grahamc commented Jan 31, 2018

@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";
Copy link
Member

@Mic92 Mic92 Jan 31, 2018

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Mic92 when I tested this, the expression did not get expanded to a store path in the manpages. (also see #34469)

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 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)

Copy link
Member

@Mic92 Mic92 Feb 1, 2018

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}" == "/";
Copy link
Member

Choose a reason for hiding this comment

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

Can we take @rnhmjoj 's suggestion in #34371 ? i.e. use something like if [[ -x ${cfg."${option}"} ]]
builtins.substring 0 1 cfg."${option}" == "/" won't work if someone want locker = "reboot".

Copy link
Contributor

@rnhmjoj rnhmjoj Feb 1, 2018

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.

Copy link
Member Author

@WilliButz WilliButz Feb 1, 2018

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 :)

Copy link
Member

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.

Copy link
Member Author

@WilliButz WilliButz Feb 1, 2018

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.

Copy link
Member

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!

@joachifm
Copy link
Contributor

Can this be integrated?

@fpletz fpletz merged commit 0dcf5df into NixOS:master Feb 22, 2018
@fpletz fpletz added this to the 18.03 milestone Feb 22, 2018
@WilliButz WilliButz deleted the fix-xautolock branch February 23, 2018 12:12
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

8 participants