How to merge bashrc in home-manager

I want to keep my bashrc as a stand-alone file, but still require some extra variables when using hm. But it seems it’s writing the same file.

{
  programs.bash = {
    enable = true;
    sessionVariables = {
      EDITOR = "nvim";
      XDG_RUNTIME_DIR = "$HOME/.cache/";
    };
  };

  home.file.".bashrc" = {
    source = ../../dotfiles/.bashrc;
  };

  home.file.".inputrc" = {
    source = ../../dotfiles/.inputrc;
  };
}
error: The option `home.file.".bashrc".source' has conflicting definition values:
       - In `/nix/store/n04dfzl1vr8vfgr0a8v7wcisq1qxiab5-source/modules/programs/bash.nix': <derivation bashrc>
       - In `/nix/store/zq3wj9xz0pr64mza67ndhj7wvvm11wyc-source/packages/shell/bash.nix': /nix/store/zq3wj9xz0pr64mza67ndhj7wvvm11wyc-source/dotfiles/.bashrc
       Use `lib.mkForce value` or `lib.mkDefault value` to change the priority on any of these definitions.

You’re getting the error b/c hm will attempt to create the .bashrc for you since you have programs.bash.enable = true. Instead of home.file.“.bashrc” you could try

programs.bash.initExtra =  builtins.readFile ../../dotfiles/.bashrc;

or programs.bash.bashrcExtra if you want the contents to be run only for interactive shells.

1 Like