cachix / devenv

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

Expand the scope of the `allowUnfree` flag to all the inputs #1090

Open sestrella opened 1 month ago

sestrella commented 1 month ago

Right now, it appears that setting allowUnfree = true only affects the nixpkgs input; a closer look at the generated .devenv.flake.nix file reveals the following code:

pkgs = import nixpkgs {
  inherit system;
  config = {
    allowUnfree = devenv.allowUnfree or false;
    allowBroken = devenv.allowBroken or false;
    permittedInsecurePackages = devenv.permittedInsecurePackages or [ ];
  };
  inherit overlays;
};

So far, it appears that the only way to install "unfree" packages from external flakes is to pass them as overlays to the main nixpkgs input, which may be affected by allowUnfree = true. A workaround I discovered is to prefix all devenv commands with NIXPKGS_ALLOW_UNFREE=1 or to add it directly to the direnv configuration file .envrc, as shown below:

source_url "https://raw.githubusercontent.com/cachix/devenv/95f329d49a8a5289d31e0982652f7058a189bfca/direnvrc" "sha256-d+8cBpDfDBj41inrADaJt+bDWhOktwslgoP5YiGJ1v0="

NIXPKGS_ALLOW_UNFREE=1 use devenv

To avoid this workaround, I am wondering if it makes sense to pass the NIXPKGS_ALLOW_UNFREE=1 environment variable to all nix commands invoked by devenv when allowUnfree is set to true. I'd be willing to submit a PR if the suggested change sounds like a viable solution for the mentioned scenario.

domenkozar commented 1 month ago

Yeah, I've been looking into this a few times, see #792.

It's tricky to fix because we don't want to use impure mode, but each invocation of import nixpkgs { .. } should respect a global config.

SebastianCallh commented 1 month ago

Hi! I am trying to use the proposed workaround with NIXPKGS_ALLOW_UNFREE=1 use devenv in the .envrc and running NIXPKGS_ALLOW_UNFREE=1 devenv shell in a devenv with terraform added as a language, but both approaches fail to resolve the "unfree license (‘bsl11’), refusing to evaluate" error. Can you please advise on why this might be? I would really love to use devenv.

I am on macos but use nixos-darwin for all installations if that is relevant.

domenkozar commented 1 month ago

You also need to enable impure: true in devenv.yaml.

SebastianCallh commented 1 month ago

Thank you for your helpful response, that was indeed the issue. It all works now!