Recommendations for code reuse between flake outputs

While, in general, the various outputs of a flake could be completely independent, in practice ones such as checks, packages and devShells will have much in common.

Can you recommend some scheme for sharing code between these?

As a concrete example, there is probably going to be a huge overlap between the buildInputs[1] in all of the above. What is a good way of sharing these? There are bound to be more things that aren’t so immediately obvious to me.

[1] or nativeBuildInputs: every time I try to brush up on the difference between this and buildInputs, after much reading I go away with the feeling that I still don’t get it.


I think @magthe provides a nice example of reuse in

devShell = mkShell {
    inputsFrom = builtins.attrValues self.packages.${system};

you can reference flake’s output via “self.XXX” as described in the previous post, or some flakes declare everything in an overlay and then inherit the flake attribute from the overlay like

  outputs = { self, nixpkgs, flake-utils, ... }:
    flake-utils.lib.eachSystem ["x86_64-linux"] (system: let
      pkgs = import nixpkgs {
        inherit system;
        overlays =  [
    in {
     packages = {
            inherit (pkgs) toto;
}) // {
    overlay = final: prev: {
   toto = ...