Sassa
Sassa

Reputation: 2023

Add extra runtime dependencies to Nix Home Manager package

In my Home Manager config, I have the following pkgs:

home.packages = with pkgs; [
    # Development
    emacs

    # Development - Emacs - Base
    ripgrep
    fd
    (nerdfonts.override { fonts = [ "NerdFontsSymbolsOnly" ]; })

    # Development - Emacs - Shell script linting
    shellcheck-minimal

    # Development - Emacs - Web
    html-tidy
    stylelint
    jsbeautifier

    ...

As you can see, all the other packages besides emacs are packages that my emacs config requires as "runtime dependencies".

I wanted to make things more clear and "scoped" by setting all these pkgs as the emacs pkg runtime dependencies.

I tried to do it with this:

    # Development
    (emacs.overrideAttrs (old: rec {
      buildInputs = old.buildInputs ++ [
        # Base
        ripgrep
        fd
        (nerdfonts.override { fonts = [ "NerdFontsSymbolsOnly" ]; })

        # Shell script linting
        shellcheck-minimal

        # Web
        html-tidy
        stylelint
        jsbeautifier
      ];
    }))

But this will actually just build emacs with these dependencies available only at build it, and then they will be "discarded" afterwards since (as far as I understand) the generated binary doesn't explicitly depends on these pkgs.

Is there some way for me to force home manager to see these pkgs as emacs runtime dependencies?

Upvotes: 0

Views: 87

Answers (1)

Loïc Reynier
Loïc Reynier

Reputation: 385

As you mentioned, buildInputs only provide the dependencies at build time. To ensure that dependencies are available at runtime, you should use propagatedBuildInputs.

Alternatively, you can create a wrapper for the program, such as Emacs, to explicitly set the runtime environment. Here’s an example of how to do that:

home.packages = with pkgs; [
  (symlinkJoin {
    name = "emacs";
    paths = [
      emacs
      
      # Dependencies
      ripgrep
      fd
      # ...
    ];
  })
]

Upvotes: -1

Related Questions