[Nix-dev] [***SPAM***] Dynamic Dependency Management by Calling External Programs from Nix

Shea Levy shea at shealevy.com
Wed Oct 26 17:49:14 CEST 2011


On 10/26/11 11:38 AM, Eelco Dolstra wrote:
> On 10/26/2011 05:30 PM, Shea Levy wrote:
>
>>> However, you don't want this most of the time, certainly not in Nixpkgs, because
>>> it causes query operations like "nix-env -qa" to do a build.  Which is a bad
>>> thing.  Actually, since "nix-env -qa" runs in read-only mode, it won't even work
>>> (but it will work for "nix-env -i", "nix-instantiate" or "nix-build").
>> Presumably, most of the packages that want this ability will end up being
>> functions (e.g. a function that takes a Haskell package name and evaluates to
>> derivation that builds that package with its dependencies as separate
>> derivations). What will nix-env -qa do when faced with something like
>> pkgs.haskellPackage as a function?
> It barfs ungracefully:
>
> $ nix-env -f . -qa \* --drv-path
> error: cannot import `/nix/store/1ll18rx1gvcvacdhwbrwzg5xg760i933-x', since path
> `/nix/store/23jzna04rkcrpfflhg9w09d6y5g4h60f-x.drv' is not valid
> (use `--show-trace' to show detailed location information)
>
> (So if the output of the derivation already exists, it will actually work.)

So if I have an attribute in all-packages.nix called haskellPackage that 
is a function that takes a string, nix-env -qa will try to somehow 
evaluate it? Won't it just evaluate to a lambda and be ignored?

>> Maybe it would be desirable to make it so tools that evaluate/instantiate only
>> (nix-env -qa, nix-instantiate, --dry-run, etc.) gracefully ignore
>> store-dependent imports unless given a specific flag to build them (or unless
>> the required output has already been built)?
> But that would mean that if we use this to compute packages on the fly (e.g. to
> solve dependencies dynamically), then "nix-env -qa" won't show those packages.

Would it be possible to have the "graceful ignore" print out the 
information that CAN be determined, e.g. if I ask for the derivation 
path in a query and the name can be determined without a build but the 
full derivation can't, output 
/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-name.drv or some such?

>> So we're already doing this in nixpkgs? How do nix-env -qa and the like respond?
> No, these functions are not actually used by any package in Nixpkgs.  But
> they're used (e.g.) by Hydra jobs.
>

Ah, ok.

Thanks,
Shea


More information about the nix-dev mailing list