Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot look up '<nixpkgs>' in pure evaluation mode #30

Closed
codygman opened this issue Dec 15, 2020 · 13 comments · Fixed by #33
Closed

cannot look up '<nixpkgs>' in pure evaluation mode #30

codygman opened this issue Dec 15, 2020 · 13 comments · Fixed by #33

Comments

@codygman
Copy link
Contributor

[cody@nixos:~]$ nix flake new -t "github:nrdxp/nixflk" flk # 2bdead324bbf15685db291cdd15c961d9d0d51a9
[cody@nixos:~]$ cd flk/ 
direnv: loading ~/flk/.envrc
direnv: using flake
direnv: export +AR +AS +CC +CONFIG_SHELL +CXX +HOST_PATH +IN_NIX_SHELL +LD +NIX_BINTOOLS +NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_BUILD_CORES +NIX_BUILD_TOP +NIX_CC +NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_CFLAGS_COMPILE +NIX_ENFORCE_NO_NATIVE +NIX_HARDENING_ENABLE +NIX_INDENT_MAKE +NIX_LDFLAGS +NIX_STORE +NM +OBJCOPY +OBJDUMP +RANLIB +READELF +SIZE +SOURCE_DATE_EPOCH +STRINGS +STRIP +TEMP +TEMPDIR +TMP +TMPDIR +buildInputs +builder +configureFlags +depsBuildBuild +depsBuildBuildPropagated +depsBuildTarget +depsBuildTargetPropagated +depsHostHost +depsHostHostPropagated +depsTargetTarget +depsTargetTargetPropagated +doCheck +doInstallCheck +dontAddDisableDepTrack +name +nativeBuildInputs +nobuildPhase +out +outputs +patches +phases +propagatedBuildInputs +propagatedNativeBuildInputs +shell +shellHook +stdenv +strictDeps +system ~PATH ~XDG_DATA_DIRS

[cody@nixos:~/flk]$ rebuild NixOS test
[sudo] password for cody: 
building the system configuration...
error: --- ThrownError ------------------------------------------------------------------- nix
at: (217:11) in file: /nix/store/wkjaivy3f1viwbj574n7p30wvd6llssi-source/modules/modules.nix

   216|         else
   217|           <nixpkgs>);
      |           ^
   218|       _module.args.pkgs = lib.mkDefault pkgs;

cannot look up '<nixpkgs>' in pure evaluation mode (use '--impure' to override)
(use '--show-trace' to show detailed location information)

Shouldn't everyone that uses this flake be getting this error? It seems like it's only me but that defeats the purpose of flakes having more hermetic builds right?

@codygman
Copy link
Contributor Author

Maybe my config.home.stateVersion is messed up?

That way it tries to load nixpkgs is from:

      _module.args.pkgsPath = lib.mkDefault (
        if versionAtLeast config.home.stateVersion "20.09" then
          pkgs.path
        else
          <nixpkgs>);

@mcbeth
Copy link

mcbeth commented Dec 16, 2020

You're not alone, I've spent a lot of time fighting this this morning...

@nathanshelly
Copy link

As mentioned in the referenced home-manager issue 20.09 is the first home-manager state version to officially support flakes. The first, probably best option, is to change your state version to 20.09 (making sure to update anything you need to based on the 20.09 release notes and older releases if you're updating your state version from something before 20.03).

You can also run your flake command with --impure but then home-manager will use whatever nixpkgs is available globally on your system for it's pkgs.

@nrdxp
Copy link
Collaborator

nrdxp commented Dec 16, 2020

I have resolved this in my config here. However, this is not an ideal solution as it must be applied on a per user basis. Unfortunately, updating system.stateVersion doesn't help and it must be set per user.

Does anyone know of a simple way to define a default value for this for any give user?

@codygman
Copy link
Contributor Author

I have resolved this in my config here. However, this is not an ideal solution as it must be applied on a per user basis. Unfortunately, updating system.stateVersion doesn't help and it must be set per user.

Does anyone know of a simple way to define a default value for this for any give user?

I think it's alright to add the newer state version to the NixOS demo user most people probably copy to create their user.

As far as overriding the home manager module default state version... I'm not sure. override and mkForce come to mind though.

@kcwx
Copy link

kcwx commented Dec 17, 2020

After quite some time, this solved this issue for me:

  home-manager = {
    useGlobalPkgs = true;
  };

I've set it in my user config for now, as that's where my home-manager config is, but it could also be set on a system level.

@codygman
Copy link
Contributor Author

After quite some time, this solved this issue for me:

  home-manager = {
    useGlobalPkgs = true;
  };

I've set it in my user config for now, as that's where my home-manager config is, but it could also be set on a system level.

The source for useGlobalPkgs says:

        using the system configuration's <literal>pkgs</literal>
        argument in Home Manager. This disables the Home Manager
        options <option>nixpkgs.*</option>

Is that desirable? I'm having a hard time parsing those docs right now.

@nrdxp
Copy link
Collaborator

nrdxp commented Dec 18, 2020

@codygman, If I am understand correctly, this sidesteps the problem of importing nixpkgs entirely by simply using the pkgs attribute defined by the nixos system configuration. Since we don't make any serious changed to nixpkgs beside importing the defined overlays, I don't think we lose anything, and this is probably the simplest solution.

Confusingly though, this still doesn't solve the problem when trying to build the iso with rebuild iso, however, even setting home.stateVersion doesn't work in that case so I'll have to figure that out separately and merge this asap to help new users.

@codygman
Copy link
Contributor Author

If I am understand correctly, this sidesteps the problem of importing nixpkgs entirely by simply using the pkgs attribute defined by the nixos system configuration.

But then you aren't using the nixpkgs defined by flakes. I'm guessing most users want their system based on flake inputs and not the nixpkgs channel their system previously had.

@nrdxp
Copy link
Collaborator

nrdxp commented Dec 18, 2020

After following the code, I don't think thats what it's doing. I believe it is pulling in the pkgs defined here, unless I am mistaken. I'll leave the PR unmerged until everyone is confident.

@codygman
Copy link
Contributor Author

After following the code, I don't think thats what it's doing. I believe it is pulling in the pkgs defined here, unless I am mistaken. I'll leave the PR unmerged until everyone is confident.

Maybe you are right... couldn't we test which is the case by adding something to pkgs in flake.nix and trying to use it from the home manager module?

Maybe I can get the time to try this later or a different test if someone suggests it.

@nrdxp
Copy link
Collaborator

nrdxp commented Dec 19, 2020

Okay, so after reviewing the code one more time, and after viewing home-managers own README.md's section on flakes, it states that both:

home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;

should be set when using flakes. It would be impossible for home-manager to use the previous generations nixpkgs, as that would also require it to pull something externally. I see that, when useGlobalPkgs is set, the nixpkgs module is skipped in home-manager and the NixOS pkgs attribute is used instead. This is exactly what we want, and adding both these lines has resolved the issue in all cases on my machine.

I am gonna go ahead and merge the PR. I feel it is safe at this point, and I don't want to frustrate new users any more than we need to.

@nrdxp nrdxp closed this as completed in #33 Dec 19, 2020
@codygman
Copy link
Contributor Author

Okay, so after reviewing the code one more time, and after viewing home-managers own README.md's section on flakes, it states that both:

home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;

should be set when using flakes. It would be impossible for home-manager to use the previous generations nixpkgs, as that would also require it to pull something externally. I see that, when useGlobalPkgs is set, the nixpkgs module is skipped in home-manager and the NixOS pkgs attribute is used instead. This is exactly what we want, and adding both these lines has resolved the issue in all cases on my machine.

I am gonna go ahead and merge the PR. I feel it is safe at this point, and I don't want to frustrate new users any more than we need to.

Totally reasonable. Thanks for looking again, I just didn't want this template to get bad PR for subverting flakes or breaking any guarantees.

As soon as I figure out how to migrate to flakes I plan on writing some documentation I hope will help others do the same more smoothly if I can squeeze out the time

blaggacao pushed a commit to blaggacao/devos that referenced this issue Jul 6, 2021
Pacman99 added a commit that referenced this issue Feb 26, 2022
30: Create new option, importables, and properly deprecate profiles/suites r=Pacman99 a=Pacman99

I used this opportunity to make the changes from #29 backwards compatible. But if you use the old method of profiles creation, you get hit with various deprecation messages. One to explain the new format of `rakeLeaves` and the other to explain how to create `suites` and `profiles` in `importables`.

Co-authored-by: Pacman99 <pachum99@myrdd.info>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants