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/environment: make default shell aliases overridable #28072

Closed
wants to merge 2 commits into from

Conversation

TomSmeets
Copy link
Contributor

Motivation for this change

This fixes issue #24560 by moving the predefined shellAliases to the environment.shellAliases option definition.

I also used a custom merge function, such that the defaults only get overridden when the user defines an alternative.

Things done

Please check what applies. Note that these are not hard requirements but merely serve as information for reviewers.

  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • 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.

This fixes issue [NixOS#24560](NixOS#24560)
by moving the predefined shellAliases to the `environment.shellAliases`
option definition.

I also used a custom merge function, such that the defaults only get
overridden when the user defines an alternative.
@mention-bot
Copy link

@TomSmeets, thanks for your PR! By analyzing the history of the files in this pull request, we identified @shlevy, @oxij and @edolstra to be potential reviewers.

type = types.attrs // {
# merge aliases defined by the user and the defaults
merge = loc: defs: default // types.attrs.merge loc defs;
};
Copy link
Member

@infinisil infinisil Aug 9, 2017

Choose a reason for hiding this comment

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

I'm not sure about this, it forces the user to have these aliases. If one wants to keep the defaults while adding more, they could always do shellAliases = { gst = "git status"; } // options.environment.shellAliases.default; instead.

Copy link
Contributor Author

@TomSmeets TomSmeets Aug 9, 2017

Choose a reason for hiding this comment

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

yes, I was not sure what to do here.
But to me it seems a bit strange that if you just want to add a new alias, that the defaults disappear.

Maybe we should move these entirely to example? (this would affect existing systems)
Or maybe add something like a environment.useDefaultShellAliases option, which is set to true by default.

Copy link
Member

Choose a reason for hiding this comment

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

Another option would be an extraAliases option, which has already become somewhat standard for config files (config/extraConfig).

But I ultimately don't think it's worth adding another option just for this rare use case. Just adding a section to the manual on how to refer to the default values (with this as an example) would be sufficient imo.

ls = "ls --color=tty";
ll = "ls -l";
l = "ls -alh";
};
example = { ll = "ls -l"; };
Copy link
Member

Choose a reason for hiding this comment

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

Maybe something other than a default could be used here, e.g. example = { gst = "git status"; }

I also added some documentation and a better example expression.
@TomSmeets
Copy link
Contributor Author

@infinisil
I have applied your second suggestion from this comment with d0511d2.

I saw no need to add an extra section to the nixos manual.
The description is very specific to environment.shellAliases.
This is why i added the documentation to the option description.

Please tell me what you think.

description = ''
An attribute set that maps aliases (the top level attribute names in
this option) to command strings or directly to build outputs. The
aliases are added to all users' shells.

<note><para>
Copy link
Contributor

Choose a reason for hiding this comment

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

You changed description, have you tried building manual?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@danbst
Yes I have build the manual, and everything looks good.
However, I couldn't find any documentation on the available tags.
I used existing options as a reference.

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.

Nitpick change included or not, I think this should be merged, it's long overdue and a very reasonable change

<code>
environment.shellAliases = {
gst = "git status";
} // options.environment.shellAliases.default;
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: would be better to use

environment.shellAliases = options.environment.shellAliases.default // {
  gst = "git status";
}

because otherwise the default aliases would override your customized ones.

'';
type = types.attrs; # types.attrsOf types.stringOrPath;
type = types.attrs;
Copy link
Member

Choose a reason for hiding this comment

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

This should use types.attrsOf types.str or something slightly less restrictive if necessary. That will make merges work like expected and I think also enables using mkDefault for attributes, like this:

{
    environment.shellAliases =
      { ls = mkDefault "ls --color=tty";
        ll = mkDefault "ls -l";
        l  = mkDefault "ls -alh";
      };
}

@TomSmeets
Copy link
Contributor Author

A similar pull request has been merged: #44441
Closing

@TomSmeets TomSmeets closed this Oct 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants