Make local custom derivation available in NixOS

Hi,
I would like to know if there are any approaches to make a custom written package (not on nixpkgs) available for system/user wide reuse. The question is not about how to write the derivation and include in `environment.systemPackages`/`home.packages` but how to reuse later in a different derivation without much effort.

That is:

  1. write a derivation that is compatible with `callPackage`
  2. make that available dynamically (without changing the `nixosSystem`)
  3. reuse in a separate `default.nix`/`shell.nix`

I think this is more about a impure approach that I want to know if anyone has any good ideas for developer experience.I know some things that might be useful (or not) such as

  1. the `NIX_PATH` env var (is it useful?)
  2. the `~/.config/nixpkgs/overlays.nix` file

Any ideas or workflow examples would be appreciated.

Bonus question: Can the same be done with simple function like an extra lib?

1 Like

One useful piece of a good solution to this may be lib.makeScope pkgs.newScope. That allows you to make your own package set with a callPackage that can supply packages from nixpkgs as well as from the package set itself.

Thanks for the tip, I’m going to look into that.

What I have found useful in my workflow so far is changing the ~/.config/nixpkgs/overlays.nix to add a desired custom package:

[
  (self: super: {
  my-package = # ...
  })
]

and use it wether in a default.nix/shell.nix

let pkgs = import <nixpkgs> {}; in
  pkgs.mkShell {
    packages = [
      pkgs.my-package
    ];
  }

with nix-build ./nix-shell . or without those files with nix build --impure nixpkgs#my-package/nix shell --impure nixpkgs#my-package