Merging python3.buildEnv between imported files

In a project I have stuctured my Nix files as follows:


The master file simply imports all feat-*.nix files:

imports = [

while the feat-*.nix files themselves package some python libraries that enables some feature of the project:

let ... in {
  environment.systemPackages = [
    (pkgs.python3.buildEnv.override {
      extraLibs = [

Is it possible to merge the different sets of extraLibs between the three files while keeping them as separate files?

my_python = let
  python = python3.override {
    packageOverrides = final: prev: {
      feat-a = final.callPackage feat-a.nix { };
      feat-b = final.callPackage feat-b.nix { };
      feat-c = final.callPackage feat-c.nix { };
    self = python;
in python;

assuming each of the feat_*.nix files are a function for creating a Python package.

Please have a look at the Nixpkgs manual for more examples.

They arent: each feat-*.nix is a set of system configurations because some need to alter the system in different ways (change firewall rules, apply device tree overlays). Each feat-*.nix contain a

  environment.systemPackages = [
    (pkgs.python3.buildEnv.override {
      extraLibs = [ ... ];

and if two imported files have extraLibs = [ a ] and extraLibs = [ b ], I expect the final evaluated python environment to be the equivalent of extraLibs = [ a b ]. Instead the import order is significant and I only get [ a ] or [ b ].

I realize my error now: when using imports = [ a.nix b.nix ] all sets in the imports are merged (//) in the importing file. I expected the same behavior here, but pkgs.python3.buildEnv is a derivation, not a set. I expect that I have two python envs installed in the system environment, just that one preceeds the other in PATH.

So then: is it possible to merge attributes of derivations across imported files? I’d prefer to keep the files separate for the sake of documentation.