Out-of-nixpkgs package and configuration modules

Let’s say there is a project that comes with a nice default.nix. Is there a way, short of getting it into nixpkgs, to include configuration options with that project?

I.e. I’d like the user to be able to import the project derivation straight off github and enable its services, tweak its configs, etc., in the usual manner. Is that possible? If so, how?

(I avoid experimental features as a matter of policy, so without flakes)

Yes.

You can use fetchers like fetchFromGithub to fetch the repository the the nix code belongs and use it from there like your own local nix files.

Flakes just make fetching dependencies more convenient. Other than that, there shouldn’t be any differences.


For example, there is a Home Manager module defined at the root of the neuron repository. You should be able to use this module with something like:

let
  neuron = fetchFromGitHub {
    owner = "srid";
    repo = "neuron";
    rev = "master";
    sha256 = "sha256-tHvgitxpGDqtLfKEuw3zQcNKd5g0gv/LooAqLt9OKg0=";
  }
in
{
  home-manager = {
    sharedModules = [
      {
        imports = [
          "${neuron}/home-manager-module.nix"
        ];
      }
    ];
  };
}

And then, you can use/configure the module like any other module defined in the Home Manager monorepo.

While this was an example for a Home Manager module, you can use a NixOS module in a similar way.

2 Likes

thank you!
regarding your example: where is pkgs.neuron-notes supposed to come from?
also isn’t the way you bring in the module IFD, and thus somehow bad?

neuron-notes derivation and the module is decoupled right now. services.neuron.package defaults to neuron-notes attribute of pkgs argument passed by the module system, if services.neuron.package is not defined. To use a custom derivation, you can either use an overlay that overwrites neuron-notes attribute of pkgs or you can define services.neuron.package.

For example, if you want to use the neuron derivation from the repository, you can do

{
  services = {
    neuron = {
      package = (import "${neuron}/project.nix" { inherit pkgs; }).neuron;
    };
  };
}

I think it is.

I think the reason IFD’s are looked down upon and not allowed in Nixpkgs is that they reduce Hydra’s parallelism ^1. Nix wiki page about IFD says the following

… As a rule of thumb, if you can avoid IFD by refactoring Nix code or moving your build logic into the derivations themselves, you should do so.

I don’t think it is possible to refactor the above Nix expression to avoid IFD’s, since it is only fetching external files. What we can do is fetch the dependencies before the evaluation starts. This could be done by using Flakes, niv or something similar.