Passing Flake outputs to derivations on the command line?

Hi everyone!

Suppose I have a library called mylib that defines a flake.

I defined a standalone Nix file which does a distribution test for the library (compiles a program against it). It’s in test_dist/default.nix and looks something like this:

{ mylib, stdenv }:

stdenv.mkDerivation {
    name = "mylib-test-dist";
    # [compile a program against mylib]...

In my flake, I can define this as a “check”:

checks.${system}.dist = import ./test_dist { mylib = self; inherit stdenv };

and I can execute it either with

$ nix flake check


$ nix build .#checks.x86_64-linux.dist

How can I execute it “outside the scope” of my flake?

I want to do something like

$ nix build -f test_dist/default.nix --input mylib ${what_do}

but I’m not sure how, or even if it’s a reasonable thing to do.

Any advice? Thanks!