Different result on `import ../path/default.nix` in flake.nix vs repl

I’m trying to import a package built by one (local) flake in another. I actually don’t want to have to have it locked, so I’m trying to import it directly. I tried with callPackage, but was told that flake-compat’s default.nix produces derivation directly.

And indeed, when I use nix repl I get:

nix-repl> (import ./utils/aws-bootstrap/default.nix).default          
«derivation /nix/store/ra4c43fmiq4a6vkhlfy0csn0bw9bnfmg-aws-bootstrap-0.1.0.drv»

However, when I do:

  outputs = { self, nixpkgs, flake-utils, flake-compat}:
    flake-utils.lib.eachDefaultSystem (system:
    let
      imp = (import ./utils/aws-bootstrap/default.nix);
      overlay = self: super: {
        aws-bootstrap = builtins.trace ''${imp}'' imp;
      };
      pkgs = import nixpkgs {
        inherit system;
        overlays = [ overlay ];
      };
    in {
      devShell = pkgs.mkShell {
        buildInputs = [
          pkgs.terraform
          pkgs.awscli2
          pkgs.aws-bootstrap
        ];
      };
  });

I get:

trace: /nix/store/pvc2z2jz7p6il74z7dx4p1q4fwia43xg-aws-bootstrap
error: Dependency is not of a valid type: element 3 of buildInputs for nix-shell
(use '--show-trace' to show detailed location information)

Seems like (import ./utils/aws-bootstrap/default.nix) is a path to the source code. It does not have any default key, neither it (or contains) any derivation. How? Why? I am confused why would I get such a different results between my flake and nix repl executed in the same directory.

The reason the trace is a path, is that ''${foo}'' (quoting and then antiquoting) implicitly converts packages to their output paths.

The flake-compat layer creates the default attribute, see here. I’m not sure why it does that, but presumably nix-build expects either a derivation or an attribute set with a default parameter which is the derivation to build.

You have to put a .default somewhere, either in the default.nix itself or in the flake.nix where you import the default.nix.

Also for future reference, if you have a problem involving multiple files, it’s helpful if you put them in a publicly accessible git repository so other people can reproduce the problem and poke around the code.

Wait actually I’ve contradicted myself here. If ''${imp}'' is printing a store path, then it should be a derivation, not a {default = <derivation>;} attrset.

I’m not entirely sure what’s going on there.

Sorry, was tired. Of course.

(my last commit trying to figure it out with tracing: Still not working · rustshop/rustshop@0bfd8e3 · GitHub)

I think it’s because of lack of builtins.currentSystem How to use builtins.currentSystem in flake output?

Impurity is the root of all evil!

Workaround that worked for me: Workaround `flake-compat` bug · rustshop/rustshop@26824e3 · GitHub