I’m working on a Bash script that can evaluate a Nix expression with nix eval. This is all happening inside of a Flake. The Nix expression needs a reference to nixpkgs. I could use fetchTarball to get a copy of Nixpkgs, however I would rather somehow get a reference to the derivation loaded as an input for the flake. Is there a way to do this?
Here’s some pseudo-nix to convey the idea. obviously coercing the nixpkgs input directly wouldn’t work, but is there a way to find its derivation?
Why not? The stringifying is implicitly accessing nixpkgs.outPath. It’s just weird to do whatever you’re trying to do at runtime (relying on a nix eval command), when it could be done at build-time - you’re already writing nix code, so you already have access to the nix evaluator.
There’s no “derivation” involved though; flake inputs are fetched using builtins.fetchTree. There’s nothing to build with respect to fetching nixpkgs, so there’s no “derivation” associated with nixpkgs.
Somehow I see a deep misunderstanding of what nix is doing here, so I agree that you should tell us what you’re actually trying to accomplish instead of tunnel-visioning on a solution that doesn’t make sense at first glance.
More specifically: what is the content of other_nix_file.nix?
Ahh, you’re right, I was mixing up the nixpkgs input with the imported nixpkgs object. That would work.
I’ve since reached the conclusion that I don’t need nix eval. What I was trying to do was provide a script to pass as the --filter option to Pandoc (to apply a transform to a document tree). But I figured out that I can split up the Pandoc call into two steps, one to parse a document, then I can transform the results with nix, then call Pandoc again on the transformed document tree to produce the output document format.
In addition to the outputs of each input, each input in inputs also contains some metadata about the inputs. These are:
outPath: The path in the Nix store of the flake’s source tree. This way, the attribute set can be passed to import as if it was a path, as in the example above (import nixpkgs).