How can I augment a default value instead of overriding it?

I would like to add to programs.bash.promptInit but setting that value overrides the useful default configuration. Is there any way I can augment the default instead of overriding it?

1 Like

You may be looking for mkAfter.

Still overrides the default :confused:

Not sure if there is a built in way to merge with the default, but this seems to work for me.

{ modulesPath, options, ... }:

{
  imports = [
    "${modulesPath}/virtualisation/qemu-vm.nix"
  ];

  programs.bash.promptInit = options.programs.bash.promptInit.default + ''
    echo "Extra stuff here"
  '';
}
6 Likes

You can also use lib.mkOptionDefault to set the priority of your value to be equal to that of the option’s default (1500), which will cause the values to be merged together. I prefer @mvnetbiz’s solution though, because the final value has the “default priority” of 100 so it’s less susceptible to being overwritten elsewhere later.

{ lib, ... }:
{
  programs.bash.promptInit = lib.mkOptionDefault ''
    echo 'Hello world!'
  '';
}
1 Like