cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
4.06k stars 305 forks source link

Error when running `nix flake show` and `nix flake check` #528

Open willruggiano opened 1 year ago

willruggiano commented 1 year ago

Describe the bug When running nix flake show and nix flake check, I get the following error:

❯ nix flake check
error:
       … while checking flake output 'packages'

         at «none»:0: (source not available)

       … while checking the derivation 'packages.x86_64-linux.container-'

         at «none»:0: (source not available)

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: To build the container, you need to add the following to your devenv.yaml:

       inputs:
         nix2container:
           url: github:nlewo/nix2container
           inputs:
             nixpkgs:
               follows: nixpkgs
         mk-shell-bin:
           url: github:rrbutani/nix-mk-shell-bin

Similarly for nix flake show:

❯ nix flake show
git+file:///home/bombadil/dev/neovim.drv?ref=refs/heads/main&rev=146b18d263d0e3236c7e73ed466f23d1a0f4fff1
├───apps
│   └───x86_64-linux
│       ├───default: app
│       └───update-grammars: app
├───checks
│   └───x86_64-linux
│       └───pre-commit: derivation 'pre-commit-run'
├───devShells
│   └───x86_64-linux
│       └───default: development environment 'devenv-shell'
└───packages
    └───x86_64-linux
error:
       … while evaluating the attribute 'optionalValue.value'

         at /nix/store/7m0y4s8bd0pj7mazwdxrwa2m14hplims-source/lib/modules.nix:770:5:

          769|
          770|     optionalValue =
             |     ^
          771|       if isDefined then { value = mergedValue; }

       … while evaluating a branch condition

         at /nix/store/7m0y4s8bd0pj7mazwdxrwa2m14hplims-source/lib/modules.nix:771:7:

          770|     optionalValue =
          771|       if isDefined then { value = mergedValue; }
             |       ^
          772|       else {};

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: To build the container, you need to add the following to your devenv.yaml:

       inputs:
         nix2container:
           url: github:nlewo/nix2container
           inputs:
             nixpkgs:
               follows: nixpkgs
         mk-shell-bin:
           url: github:rrbutani/nix-mk-shell-bin

To Reproduce See this flake.nix. It's clearly a very simple usage. The error goes away if I add nix2container to my flake's inputs, but I don't think that should be a requirement if I do not define any dev containers?

Version

https://github.com/willruggiano/neovim.drv/blob/236d94ff0502bd89699021b4d9911bb932f6aa24/flake.lock#L10-L16

willruggiano commented 1 year ago

Here is the full trace:

❯ nix flake check --show-trace
error:
       … while checking flake output 'packages'

         at «none»:0: (source not available)

       … while checking the derivation 'packages.x86_64-linux.container-'

         at «none»:0: (source not available)

       … while calling anonymous lambda

         at /nix/store/7m0y4s8bd0pj7mazwdxrwa2m14hplims-source/lib/types.nix:546:29:

          545|       merge = loc: defs:
          546|         zipAttrsWith (name: defs:
             |                             ^
          547|           let merged = mergeDefinitions (loc ++ [name]) elemType defs;

       … while calling anonymous lambda

         at /nix/store/7m0y4s8bd0pj7mazwdxrwa2m14hplims-source/lib/modules.nix:738:28:

          737|         # Process mkMerge and mkIf properties.
          738|         defs' = concatMap (m:
             |                            ^
          739|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))

       … while evaluating definitions from `/nix/store/fgq96ksc454xjys9bh0hb9lwnybvqsw7-source/modules/transposition.nix':

       … from call site

         at /nix/store/7m0y4s8bd0pj7mazwdxrwa2m14hplims-source/lib/modules.nix:739:137:

          738|         defs' = concatMap (m:
          739|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))
             |                                                                                                                                         ^
          740|         ) defs;

       … while calling 'dischargeProperties'

         at /nix/store/7m0y4s8bd0pj7mazwdxrwa2m14hplims-source/lib/modules.nix:810:25:

          809|   */
          810|   dischargeProperties = def:
             |                         ^
          811|     if def._type or "" == "merge" then

       … while calling anonymous lambda

         at /nix/store/7m0y4s8bd0pj7mazwdxrwa2m14hplims-source/lib/types.nix:546:29:

          545|       merge = loc: defs:
          546|         zipAttrsWith (name: defs:
             |                             ^
          547|           let merged = mergeDefinitions (loc ++ [name]) elemType defs;

       … while calling anonymous lambda

         at /nix/store/7m0y4s8bd0pj7mazwdxrwa2m14hplims-source/lib/modules.nix:738:28:

          737|         # Process mkMerge and mkIf properties.
          738|         defs' = concatMap (m:
             |                            ^
          739|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))

       … while evaluating definitions from `/nix/store/xp2cwi9fissm20h670la3cybffdvx3ai-source/flake-module.nix':

       … from call site

         at /nix/store/7m0y4s8bd0pj7mazwdxrwa2m14hplims-source/lib/modules.nix:739:137:

          738|         defs' = concatMap (m:
          739|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))
             |                                                                                                                                         ^
          740|         ) defs;

       … while calling 'dischargeProperties'

         at /nix/store/7m0y4s8bd0pj7mazwdxrwa2m14hplims-source/lib/modules.nix:810:25:

          809|   */
          810|   dischargeProperties = def:
             |                         ^
          811|     if def._type or "" == "merge" then

       … while calling 'g'

         at /nix/store/m57a8xcfd0c0l7gln4gngqgx0nk04arh-source/lib/attrsets.nix:535:19:

          534|           g =
          535|             name: value:
             |                   ^
          536|             if isAttrs value && cond value

       … from call site

         at /nix/store/m57a8xcfd0c0l7gln4gngqgx0nk04arh-source/lib/attrsets.nix:538:20:

          537|               then recurse (path ++ [name]) value
          538|               else f (path ++ [name]) value;
             |                    ^
          539|         in mapAttrs g;

       … while calling anonymous lambda

         at /nix/store/m57a8xcfd0c0l7gln4gngqgx0nk04arh-source/lib/modules.nix:270:72:

          269|           # For definitions that have an associated option
          270|           declaredConfig = mapAttrsRecursiveCond (v: ! isOption v) (_: v: v.value) options;
             |                                                                        ^
          271|

       … while evaluating the option `perSystem.x86_64-linux.devenv.shells.default.containers."".derivation':

       … while calling anonymous lambda

         at /nix/store/m57a8xcfd0c0l7gln4gngqgx0nk04arh-source/lib/modules.nix:753:19:

          752|           # Avoid sorting if we don't have to.
          753|           if any (def: def.value._type or "" == "order") defs''.values
             |                   ^
          754|           then sortProperties defs''.values

       … from call site

         at /nix/store/xp2cwi9fissm20h670la3cybffdvx3ai-source/src/modules/containers.nix:143:19:

          142|         internal = true;
          143|         default = mkDerivation config;
             |                   ^
          144|       };

       … while calling 'mkDerivation'

         at /nix/store/xp2cwi9fissm20h670la3cybffdvx3ai-source/src/modules/containers.nix:35:18:

           34|   '';
           35|   mkDerivation = cfg: nix2container.nix2container.buildImage {
             |                  ^
           36|     name = cfg.name;

       error: To build the container, you need to add the following to your devenv.yaml:

       inputs:
         nix2container:
           url: github:nlewo/nix2container
           inputs:
             nixpkgs:
               follows: nixpkgs
         mk-shell-bin:
           url: github:rrbutani/nix-mk-shell-bin
MrFoxPro commented 1 year ago

Same issue, but adding nix2container.url = "github:nlewo/nix2container"; to inputs doesn't make error go away

MrFoxPro commented 1 year ago

I figured out that devenv.shells.<name>.containers = lib.mkForce {}; removes error

And

    nix2container = {
      url = "github:nlewo/nix2container";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    mk-shell-bin.url = "github:rrbutani/nix-mk-shell-bin";

also