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

Use flake --impure example is wrong #181

Closed
scvalex opened this issue May 12, 2022 · 7 comments
Closed

Use flake --impure example is wrong #181

scvalex opened this issue May 12, 2022 · 7 comments

Comments

@scvalex
Copy link

scvalex commented May 12, 2022

The README says to use echo "use flake . --impure" > .envrc.

Experimentally, that doesn't work, but removing the dot does. So, having use flake --impure in my .envrc works. "Works" here means I was able to start a devShell with nixGL in it. I don't understand how nix-direnv works exactly, so I don't know if the README was always wrong, if if became wrong with some nix version, or if I'm mistaken about what I'm seeing.

nix --version
nix (Nix) 2.5.0pre20211206_d1aaa7e
@bbenne10
Copy link
Contributor

What doesn't work for you? Can you share the flake you're trying to get working?

I can attest to it working locally. We have a flake that simply aborts execution if it is missing a particular environment variable (so --impure is necessary) and this flake works just fine.

@scvalex
Copy link
Author

scvalex commented May 12, 2022

Here's a demo: https://gitlab.com/scvalex/direnv-flake-impure-demo

The .envrc is currently use flake. If you direnv allow that, it will fail with this error:

error: attribute 'currentTime' missing

       at /nix/store/b379mn551mj4cx3dsf94vrxj4j12yx3a-source/nixGL.nix:202:18:

          201|           # Add an impure parameter to force the rebuild on each access.
          202|           time = builtins.currentTime;
             |                  ^
          203|           preferLocalBuild = true;
(use '--show-trace' to show detailed location information)

If you change the .envrc to use flake --impure, then it works and nixGL is available to run.

If you change the .envrc to use flake . --impure it fails with the error again.

@scvalex
Copy link
Author

scvalex commented May 12, 2022

What I was trying to get working was nixGL in a flake. Basically this: nix-community/nixGL#90

@bbenne10
Copy link
Contributor

Thank you for a test case! I'll have to test this on a different machine than is my default macOS testbed, but I will get back to you on this this evening.

@scvalex
Copy link
Author

scvalex commented May 12, 2022

It turns out I don't actually need nixGL for what I'm doing, so I'm not in any rush. I'm just reporting the thing that confused me.

@bbenne10
Copy link
Contributor

So I tested this out this morning (making promises to open source projects when I have a 2.5 year old at home is always a mistake...), and it all seems working with a fresh checkout of nix-direnv and a checkout of the demo repo you sent across.

My process:

  1. Clone nix-direnv locally (or fast-forward to master)
  2. Clone your test repository as a direct subdirectory of that nix-direnv clone
  3. modify the nix-direnv clone to echo when it is being sourced as follows:
  # shellcheck shell=bash

+ echo "sourcing correct nix-direnv"
  REQUIRED_DIRENV_VERSION="2.21.3"
  1. Modify the .envrc in the direnv-flake-impure-demo repository to contain only the following
source ../direnvrc
use flake . --impure
  1. Run direnv allow and watch. Notably, this does not throw the error about builtins.currentTime for me, whereas a vanilla use flake does.

Unfortunately, I don't have the time to debug old versions of this tool to see how it might be broken in older revisions.
I am running a newer version of nix than you (2.6pre), but I don't suspect that will change much.

If you're interested, I might suggest the inclusion of a set -x in your .envrc so that you can find out exactly what the nix invocation looks like. You may find that you are running an older version of nix-direnv than you believe, or that there's some other issue with your nix version? I'm not sure what else to do, as I cannot replicate.

@scvalex
Copy link
Author

scvalex commented Jun 6, 2022

Thanks for looking into it.

I updated to NixOS-22.05 with Nix 2.8.1, and I can no longer reproduce this. I guess it must've been something with the old nix version, or something with my 21.11 install.

Closing.

@scvalex scvalex closed this as completed Jun 6, 2022
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

No branches or pull requests

2 participants