Providing custom derivations

Hi everyone,

I’m still relatively new so bear with me if I don’t use the right terminology.

I’d like to use Nix from a tool that I’m developing, Tuist, to help developers set up their environment for developing apps for Apple platforms. For that, I plan to define derivations that they’ll need to have access to. My question then is, should I define a custom packages channel that I configure in their Nix environment? If so, will I be able to consume derivations from the nixpkgs channel?

Thanks in advance.

Hello and welcome!

I find channels confusing because they require dealing with the environment. If I understand the recent development around “flakes“ correctly, the notion of channels is getting deprecated anyway.

Why not just declare a function that takes nixpkgs and returns a set of your derivations based on that specific nixpkgs? That is essentially how overlays work. It allows consumers of your collection to just plug it on top of their nixpkgs, e.g. in their environment managed by nix, or where they depend on it in some package they create.

We have many internally used tools which are provided as custom packages/derivations. As @fricklerhandwerk mentioned, we are using overlays to achieve that. Our particular use case can be described as following

  1. Create an overlay git repository that contains all the custom derivations
  2. Apply the overlay in the main configuration with
    nixpkgs.overlays = let weride-overlay = builtins.fetchGit {
      url = "";
      rev = "f0c3f85f73d29fc0f48893cxxc7bb4577f697958";
    }; in [
      (import "${weride-overlay}/default.nix")

This adds (to be more specific, overrides if there are ones with the same name) the custom packages into pkgs so that your can just use them as if they are already in pkgs, without playing with channels.

The overlay git repo has a default.nix that looks like

self: super:

  weride-docker-tools = self.callPackage ./pkgs/weride-docker-tools {};
  cudatoolkit = super.cudatoolkit_10_0;

In this particular case, this overlay provides a custom package called weride-docker-tools, as well as overrides the default cuda version.

1 Like