How to use your own derivation?

So I’ve been banging my head on this for a while now and I’m not even sure how to ask the question, but anyway:

Let’s say I have a derivation for a python package looking like so:

{
python,
buildPythonPackage,
fetchFromGitHub,
setuptools,
}:

buildPythonPackage {
pname = “xrt”;
version = “1.6.1”;
src = fetchFromGitHub {
owner = “kklmn”;
repo = “xrt”;
rev = “43a229b98c49669378e2e2127ba00ac9217de451”;
sha256 = “sha256-BfMfAx/sN3Uf/JxY41DzDce0yAotFeI9o//wINeOVEM=”;
};
pyproject = true;
build-system = [ setuptools ];

postInstall = ‘’
makeWrapper $out/bin/xrtQookStart.py $out/bin/xrtQook --run “chmod -R 777 $HOME/.xrt”
makeWrapper ${python.interpreter} $out/bin/xrtBentXtal 
–add-flags “$out/lib/python3.12/site-packages/xrt/gui/xrtBentXtal.py” 
–run “chmod -R 777 $HOME/.xrt”
‘’;
}

This derivation is the first in my future collection of packages that should have the same interface as nixpkgs. I’ve called it glebpkgs and the repo is here: GitHub - glebdovzhenko/glebpkgs · GitHub

But! The only way I figured out how to add this derivation to a dev env flake is so:

let
pkgs = import nixpkgs { inherit overlays system; };
gpkgs = import glebpkgs { };
in
{
devShells.default = pkgs.mkShell {
name = “skif-xrt”;
venvDir = “./.venv”;
nativeBuildInputs = with pkgs; [
qt5.qttools.dev
cmake
blas
];
buildInputs =
with pkgs.python312Packages;
[
  python
  venvShellHook
] ++ [ (callPackage gpkgs.xrt_1 { }) ];
};

What i want is this:

buildInputs =
with pkgs.python312Packages;
[
python
venvShellHook
]
++ [ gpkgs.xrt_1 ];

What am I missing? I feel like there’s just one step left to make, but I don’t have enough experience to even google it. So any help wuld be appreciated and thanks in advance!

You could use an overlay (see also the wiki).

So your grebpkgs/flake.nix would be something like:

{
  outputs = _:
  {
    overlays.default = final: prev: {
      xrt_1 = final.callPackage ./pkgs/xrt/1.nix { };
    };
  };
}

In your development environment flake.nix you would import nixpkgs with your overlay (like inside the let binding below), which makes your packages available via pkgs like any other package:

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11";
    grebpkgs.url = "github:glebdovzhenko/glebpkgs";
  };

  outputs =
    { nixpkgs, grebpkgs, ... }:
    let
      pkgs = import nixpkgs {
        system = "x86_64-linux";
        overlays = [ grebpkgs.overlays.default ]; # Apply your overlay to nixpkgs
      };
    in
    {
      devShells.x86_64-linux.default = pkgs.mkShell {
        # edited for brevity

        buildInputs = [
          pkgs.xrt_1   # This comes from your grebpkgs overlay
        ];
      };
    };
}

Hey!

Thanks a lot for taking the time. I was really intimidated by overlays, but your example has helped, maybe I’ll start using them now. The only thing is that in your overlay definition it has to be final.python3Packages.callPackage, otherwise buildPythonPackage is not passed down. With this change your solution just works, so thanks again!

You are welcome!

I didn’t realise that buildPythonPackage isn’t passed down – every day is a school day!

Another way to fix that would be for your derivation to take python3Packages as an input:

{
  python,
  python3Packages,
  fetchFromGitHub,
  setuptools,
  ...
}:
python3Packages.buildPythonPackage {
  # whatever
}

The proper way was to use python3Packages.callPackages.

2 Likes