nix icon indicating copy to clipboard operation
nix copied to clipboard

Add layers to catching IFDs in `nix flake show`

Open ulucs opened this issue 9 months ago • 1 comments

Motivation

Fixes https://github.com/NixOS/nix/issues/13335.

Context

Expands the scope of #12583; allowing recursion into "derivation containers" even when their attributes can't be evaluated due to an IFD, and then catches the IFD error when trying to visit those nodes.

Flake:

{
  outputs = { nixpkgs, ... }:
    let
      system = "aarch64-linux";
      pkgs = import nixpkgs { inherit system; };
    in
    {
      packages.${system} =
        (import (pkgs.writeText "nix-expr" "{}"));
      checks.${system} = {
        test = pkgs.hello;
      };
    };
}

Before:

error:
       … while calling the 'import' builtin
         at /nix/store/4rw0d5agbcz96rhjwkmgx5v3bpjnz8bh-source/build/flake.nix:9:10:
            8|       packages.${system} =
            9|         (import (pkgs.writeText "nix-expr" "{}"));
             |          ^
           10|       checks.${system} = {

       … while realising the context of path '/nix/store/35006aqknvcnq3l5w4dryw1j851qng30-nix-expr'

       error: cannot build '/nix/store/2m3x8phhksw5fl039d0dwv2hk2izapwm-nix-expr.drv^out' during evaluation because the option 'allow-import-from-derivation' is disabled

After:

git+file:///software/nix?dir=build
├───checks
│   └───aarch64-linux
│       └───test omitted (use '--all-systems' to show)
└───packages
    └───aarch64-linux omitted due to use of import from derivation

ulucs avatar Jun 10 '25 13:06 ulucs

@ulucs: Thanks a lot for working on this!

I tried this out (with the example from here) by running nix shell -L github:ulucs/nix/ulucs/push-tsvykuzmosxo#nix and that didn't work as advertised, nix flake show was still crashing. Do I have to also have the nix daemon running from this commit in order for it to work?

soenkehahn avatar Jun 12 '25 16:06 soenkehahn

@soenkehahn yes, I had the daemon also running for the tests

I was also finally able to add the tests on top of the previous tests

ulucs avatar Jun 25 '25 13:06 ulucs

Hello! The tests are added; but I think the message got lost because I also replied to someone else at the same time

ulucs avatar Jul 09 '25 12:07 ulucs

Needs a rebase after the treewide reformat. Please refer to https://github.com/NixOS/nix/issues/13502 for how to handle that.

xokdvium avatar Aug 13 '25 11:08 xokdvium

I'm not using git so that was a bit manual, but should be all good now

ulucs avatar Aug 13 '25 18:08 ulucs

Hello! Are there any additional changes I should make in here?

ulucs avatar Sep 18 '25 15:09 ulucs