cachix / devenv

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

Encountered "Failed to get cachix caches due to evaluation error" when running `devenv shell` command #1043

Closed fangpenlin closed 1 month ago

fangpenlin commented 1 month ago

Describe the bug

I follow the getting started guide and try to run a minimal devenv sample file like this

{ pkgs, ... }: {
  env.GREET = "determinism";

  packages = [ pkgs.git ];

  enterShell = "echo hello $GREET";
}

But I saw output like this

• Building shell ...
• Failed to get cachix caches due to evaluation error

While the devenv shell eventually built all the dependencies and enter the shell successfully, but it seems like the command is not using the cache as it supposes to be. I dug a bit deeper, and I realized that's caused by let ... in syntax used in the generated flake file by these lines:

https://github.com/cachix/devenv/blob/63c7109f20b5ded0bc07f95ece9518bbb7fdea5b/devenv/src/flake.tmpl.nix#L3-L5

And if you looked at the generated flake file .devenv.flake.nix, it's like this

{
  inputs =
    let
      version = "1.0.1";
system = "x86_64-linux";
devenv_root = "/home/fangpen/workspace/playground/try-out-devenv2";
devenv_dotfile = ./.devenv;
devenv_dotfile_string = ".devenv";
container_name = null;
tmpdir = "/run/user/1000/";

        in {
...

Unfortunately, it appears that flake.nix is not using real nix language:

https://github.com/NixOS/nix/issues/4945

As a result, if you take out the generated flake file at .devenv.flake.nix, renamed it as flake.nix and run the same command as in the code.

nix eval  .#devenv.cachix --json
error: expected a set but got a thunk at /nix/store/qny7kiz6ns713q8w2lgmjyrms3hg0jds-source/flake.nix:2:

It will show an error like that. It's the root cause of error message like Failed to get cachix caches due to evaluation error.

To reproduce

To reproduce, simply install devenv 1.0.1, then run devenv shell with sample file such as

{ pkgs, ... }: {
  env.GREET = "determinism";

  packages = [ pkgs.git ];

  enterShell = "echo hello $GREET";
}

Version

devenv 1.0.1 (x86_64-linux)

and the nix version is

nix (Nix) 2.18.1
fangpenlin commented 1 month ago

I read the code of generated flake file by the command, it uses most of the syntax not really supported by flake according to https://github.com/NixOS/nix/issues/4945 or my previous experience with flake, did I miss something when installing devenv? Is there a flag I should turn on for my nix to be able to make devenv uses cache without a problem?

domenkozar commented 1 month ago

That's really strange can you share devenv.lock?

fangpenlin commented 1 month ago

@domenkozar sure, here you go

{
  "nodes": {
    "devenv": {
      "locked": {
        "dir": "src/modules",
        "lastModified": 1711204516,
        "owner": "cachix",
        "repo": "devenv",
        "rev": "a30343f36e7c097d9f78d3387753d06986fdaae3",
        "treeHash": "7df9fc0b242a138ec44552558e179c1e7f072457",
        "type": "github"
      },
      "original": {
        "dir": "src/modules",
        "owner": "cachix",
        "repo": "devenv",
        "type": "github"
      }
    },
    "flake-compat": {
      "flake": false,
      "locked": {
        "lastModified": 1696426674,
        "owner": "edolstra",
        "repo": "flake-compat",
        "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
        "treeHash": "2addb7b71a20a25ea74feeaf5c2f6a6b30898ecb",
        "type": "github"
      },
      "original": {
        "owner": "edolstra",
        "repo": "flake-compat",
        "type": "github"
      }
    },
    "flake-utils": {
      "inputs": {
        "systems": "systems"
      },
      "locked": {
        "lastModified": 1710146030,
        "owner": "numtide",
        "repo": "flake-utils",
        "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
        "treeHash": "bd263f021e345cb4a39d80c126ab650bebc3c10c",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "flake-utils",
        "type": "github"
      }
    },
    "gitignore": {
      "inputs": {
        "nixpkgs": [
          "pre-commit-hooks",
          "nixpkgs"
        ]
      },
      "locked": {
        "lastModified": 1709087332,
        "owner": "hercules-ci",
        "repo": "gitignore.nix",
        "rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
        "treeHash": "ca14199cabdfe1a06a7b1654c76ed49100a689f9",
        "type": "github"
      },
      "original": {
        "owner": "hercules-ci",
        "repo": "gitignore.nix",
        "type": "github"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1710796454,
        "owner": "cachix",
        "repo": "devenv-nixpkgs",
        "rev": "06fb0f1c643aee3ae6838dda3b37ef0abc3c763b",
        "treeHash": "9bb13f7f39e825a5d91bbe4139fbc129243b907d",
        "type": "github"
      },
      "original": {
        "owner": "cachix",
        "ref": "rolling",
        "repo": "devenv-nixpkgs",
        "type": "github"
      }
    },
    "nixpkgs-stable": {
      "locked": {
        "lastModified": 1711124224,
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "56528ee42526794d413d6f244648aaee4a7b56c0",
        "treeHash": "06fc80871a79146d86a73bbefc9a477ecdbce167",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixos-23.11",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "pre-commit-hooks": {
      "inputs": {
        "flake-compat": "flake-compat",
        "flake-utils": "flake-utils",
        "gitignore": "gitignore",
        "nixpkgs": [
          "nixpkgs"
        ],
        "nixpkgs-stable": "nixpkgs-stable"
      },
      "locked": {
        "lastModified": 1710923068,
        "owner": "cachix",
        "repo": "pre-commit-hooks.nix",
        "rev": "e611897ddfdde3ed3eaac4758635d7177ff78673",
        "treeHash": "d7cff0ca3e7cdccd8ea9ef00f8534ef6b425cfc6",
        "type": "github"
      },
      "original": {
        "owner": "cachix",
        "repo": "pre-commit-hooks.nix",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "devenv": "devenv",
        "nixpkgs": "nixpkgs",
        "pre-commit-hooks": "pre-commit-hooks"
      }
    },
    "systems": {
      "locked": {
        "lastModified": 1681028828,
        "owner": "nix-systems",
        "repo": "default",
        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
        "treeHash": "cce81f2a0f0743b2eb61bc2eb6c7adbe2f2c6beb",
        "type": "github"
      },
      "original": {
        "owner": "nix-systems",
        "repo": "default",
        "type": "github"
      }
    }
  },
  "root": "root",
  "version": 7
}
tomtaylor commented 1 month ago

FWIW, I think I’m experiencing the same issue - let me know if I can provide any details too.

domenkozar commented 1 month ago

I'll look into this first thing in the morning tomorrow.

vigneshpai2003 commented 1 month ago

I fixed the error by adding cachix to nix.settings.substituters and nix.settings.trusted-public-keys as described here: https://nixos-and-flakes.thiscute.world/nixos-with-flakes/add-custom-cache-servers.

Not sure if related, but running devenv search <pkg> starts a long build process, the same thing that happened with devenv shell without the above workaround.

brizzbuzz commented 1 month ago

I'm running into what I think is a related problem. I'm going the flake route, and get the following when trying to launch my shell

nix develop --impure                                                                                                                 1 03/24/24 10:15:25 AM
warning: Git tree '/home/ryan/Workspace/brizzbuzz/scroll' is dirty
warning: ignoring untrusted substituter 'https://devenv.cachix.org', you are not a trusted user.
Run `man nix.conf` for more information on the `substituters` configuration option.

it then tries to build everything from source, but I think in my case I will resolve this when i figure out how to add myself as a trusted user in my host flake setup.

domenkozar commented 1 month ago

Can you guys run nix store ping and paste the output?

fangpenlin commented 1 month ago

sure

nix store ping
Store URL: daemon
Version: 2.18.1
Trusted: 0
domenkozar commented 1 month ago

Ah that's the issue, for some reason it's not detecting your user isn't trusted.

fangpenlin commented 1 month ago
  nix.settings = {
    experimental-features = ["nix-command" "flakes"];
    trusted-public-keys = ["devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="];
    substituters = ["https://devenv.cachix.org"];
    trusted-users = ["root" "fangpen"];
  };

I just added my username in trusted-users for nix settings and it seems to be working this time:

$devenv shell
• Building shell ...
• Using Cachix: devenv
• Trusting devenv.cachix.org on first use with the public key devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=
...

pretty awesome.

domenkozar commented 1 month ago

I'm working on a fix so this is properly detected, somehow it slipped in my testing.

domenkozar commented 1 month ago

I'd appreciate if someone can install the dev version nix profile install --accept-flake-config github:cachix/devenv/#devenv and run devenv -v shell which should print the reason it's barfing when setting up caches.

fangpenlin commented 1 month ago

okay, despite that the cache is working now, I think the second eval command is always going to fail regardless:

https://github.com/cachix/devenv/blob/63c7109f20b5ded0bc07f95ece9518bbb7fdea5b/devenv/src/command.rs#L243-L246

because

nix eval  .#devenv.cachix --json
error: expected a set but got a thunk at /nix/store/qny7kiz6ns713q8w2lgmjyrms3hg0jds-source/flake.nix:2:

as mentioned in the issue above, as far as I know flake.nix file is not real nix lang, it's a reduced version of it. the current generated flake contains syntax not included in the reduced version of nix lang. as a result, that command run is always going to fail. to avoid it from failing, we probably need to avoid using those syntax

domenkozar commented 1 month ago

devenv rewrites all nix command calls to it's own Nix that relaxes that constraint on flakes.

It would be helpful if you run the command I mentioned that should print what it barfs on.

fangpenlin commented 1 month ago

oh, okay, interesting, I didn't know devenv is using its own nix implementation. looks like it's not really complaining anything about that indeed:

$devenv -v shell
• Building shell ...
• Using Cachix: devenv
• Running command: nix --show-trace --extra-experimental-features nix-command --extra-experimental-features flakes --option warn-dirty false --option eval-cache false --keep-going --max-jobs 16 print-dev-env --profile /home/fangpen/workspace/playground/try-out-devenv/.devenv/gc/shell --option extra-substituters https://devenv.cachix.org --option extra-trusted-public-keys devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=
• Creating symlink /nix/store/ikgb4hjm3wf2r1zlsriddpy6w45yk99m-devenv-shell-env -> /home/fangpen/.local/share/devenv/gc/1711350483.119756652-shell
✔ Building shell in 0.9s.
• Entering shell
• Running command: nix --show-trace --extra-experimental-features nix-command --extra-experimental-features flakes --option warn-dirty false --option eval-cache false --keep-going --max-jobs 16 develop /home/fangpen/workspace/playground/try-out-devenv/.devenv/gc/shell
hello determinism

I think the problem is addressed, please feel free to close the issue.

domenkozar commented 1 month ago

I'd still like to fix for devenv to warn what you have to do.

For those that it doesn't work I'd appreciate running the development version and also paste the output of nix store ping --json.

tomtaylor commented 1 month ago

@domenkozar I've just started running nix profile install --accept-flake-config github:cachix/devenv/#devenv and it's building a lot of stuff from scratch - is that expected?

$ nix profile install --accept-flake-config github:cachix/devenv/#devenv
warning: ignoring untrusted substituter 'https://devenv.cachix.org', you are not a trusted user.
Run `man nix.conf` for more information on the `substituters` configuration option.
error: interrupted by the user
domenkozar commented 1 month ago

Yeah, you'll have to suffer through that until we fix this issue.

tomtaylor commented 1 month ago

Yeah, you'll have to suffer through that until we fix this issue.

OK, I'll come back to you once 782 packages have built! :)

domenkozar commented 1 month ago

Alright, let me know, I'd like to fix this and then we can release 1.0.2

domenkozar commented 1 month ago

@tomtaylor I found a way to reproduce it myself, fix incoming.

tomtaylor commented 1 month ago

Thanks @domenkozar. So, I removed my existing devenv profile and ran the following, but it's still trying to compile the world. Is that expected?

➜  ~ nix profile install github:cachix/devenv/v1.0.2
do you want to allow configuration setting 'extra-substituters' to be set to 'https://devenv.cachix.org' (y/N)? y
do you want to permanently mark this value as trusted (y/N)? y
do you want to allow configuration setting 'extra-trusted-public-keys' to be set to 'devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=' (y/N)? y
do you want to permanently mark this value as trusted (y/N)? y
warning: ignoring untrusted substituter 'https://devenv.cachix.org', you are not a trusted user.
Run `man nix.conf` for more information on the `substituters` configuration option.
[8/6/322 built, 0.4 MiB DL] building libgit2-1.7.2 (buildPhase): [ 27%] Building C object src/libgit2/CMakeFilerror: interrupted by the user
➜  ~ nix profile install github:cachix/devenv/v1.0.2
warning: ignoring untrusted substituter 'https://devenv.cachix.org', you are not a trusted user.
Run `man nix.conf` for more information on the `substituters` configuration option.
[8/5/316 built] building libpng-apng-1.6.40 (buildPhase): libtool: compile:  clang -DHAVE_CONFIG_H -I. -g -O2 error: interrupted by the user
domenkozar commented 1 month ago

nix profile install nixpkgs#devenv

On Mon, Mar 25, 2024 at 1:04 PM Tom Taylor @.***> wrote:

Thanks @domenkozar https://github.com/domenkozar. So, I removed my existing devenv profile and ran the following, but it's still trying to compile the world. Is that expected?

➜ ~ nix profile install github:cachix/devenv/v1.0.2do you want to allow configuration setting 'extra-substituters' to be set to 'https://devenv.cachix.org' (y/N)? ydo you want to permanently mark this value as trusted (y/N)? ydo you want to allow configuration setting 'extra-trusted-public-keys' to be set to 'devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=' (y/N)? ydo you want to permanently mark this value as trusted (y/N)? y warning: ignoring untrusted substituter 'https://devenv.cachix.org', you are not a trusted user. Run man nix.conf for more information on the substituters configuration option. [8/6/322 built, 0.4 MiB DL] building libgit2-1.7.2 (buildPhase): [ 27%] Building C object src/libgit2/CMakeFilerror: interrupted by the user ➜ ~ nix profile install github:cachix/devenv/v1.0.2 warning: ignoring untrusted substituter 'https://devenv.cachix.org', you are not a trusted user. Run man nix.conf for more information on the substituters configuration option. [8/5/316 built] building libpng-apng-1.6.40 (buildPhase): libtool: compile: clang -DHAVE_CONFIG_H -I. -g -O2 error: interrupted by the user

— Reply to this email directly, view it on GitHub https://github.com/cachix/devenv/issues/1043#issuecomment-2017965163, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA63AYFI57JS6UR2FUO4NTY2AOGPAVCNFSM6AAAAABFED24VWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJXHE3DKMJWGM . You are receiving this because you were mentioned.Message ID: @.***>

lplawlor commented 1 month ago

Just wanted to update in relation to my duplicate issue #1047.

I've been able to get devenv v1.0.2 from the nixos-unstable channel, and was met with the warning about being an untrusted user once I ran devenv init. I added my username to nix.settings.trusted-users in my NixOS config, and the package caching is working now.

Thanks for getting this fixed! 🎉