Search code examples
attributessetdefaultnixos

How to use the default value for an attribute set in nixos, and extend it


The default value for programs.zsh.shellAliases is

 { l = "ls -alh"; ll = "ls -l"; ls = "ls --color=tty"; }

which is nice.

I want to extend the attribute set with

{ xclip = "xclip -selection clipboard"; paste = "xclip -out"; }

I know I can merge attribute sets with // and, because I know the default, I can just write down my desired attribute set explicitly.

But is it possible to keep the default and extend it like this:

 programs.zsh.shellAliases = [default] // { ... };

?


Solution

  • The default value is available in options.programs.zsh.shellAliases.default.

    You can play around with it in nix-repl:

    nix-repl> (import <nixpkgs/nixos> { configuration = {lib, options, ...}: { config.programs.zsh.shellAliases = options.programs.zsh.shellAliases.default // { xclip = "xclip -selection clipboard"; paste = "xclip -out"; }; }; }).config.programs.zsh.shellAliases
    { l = "ls -alh"; ll = "ls -l"; ls = "ls --color=tty"; paste = "xclip -out"; xclip = "xclip -selection clipboard"; }