nix-community / lorri

Your project’s nix-env [maintainer=@Profpatsch,@nyarly]
Apache License 2.0
677 stars 24 forks source link

env not passed to lorri direnv? #83

Open mmlb opened 2 years ago

mmlb commented 2 years ago

Describe the bug

While using direnv and cd-ing into a directory lorri fails to build due to an unfree derivation even though I have NIXPKGS_ALLOW_UNFREE=1 set.

To Reproduce Steps to reproduce the behavior:

  1. Have an unfree package in shell.nix (in my case _1password)
  2. Try NIXPKGS_ALLOW_UNFREE=1 lorri direnv
  3. See lorri complaining about an unfree package in journalctl --user -fu lorri.service
  4. Try NIXPKGS_ALLOW_UNFREE=1 lorri watch --once
  5. Works

Expected behavior

I expected lorri direnv to see NIXPKGS_ALLOW_UNFREE=1 in the env when being run and thus correctly building my shell.nix

Metadata

[manny@zennix:~/t/lorri-bug]$ lorri info --shell-file shell.nix 
lorri version: 1.5
GC roots do not exist. Has the project been built with lorri yet?
$ uname -a
Linux zennix 5.17.1 #1-NixOS SMP PREEMPT Mon Mar 28 08:03:22 UTC 2022 x86_64 GNU/Linux

Additional context

Test shell.nix I used for the lorri info above:

let _pkgs = import <nixpkgs> { };
in { pkgs ? import (_pkgs.fetchFromGitHub {
  owner = "NixOS";
  repo = "nixpkgs";
  #branch@date: nixpkgs-unstable@2021-11-03
  rev = "a5ac0a33a70f4a0200daa517e9bdf0e39c3441df";
  sha256 = "0a30yj5xgzbhi7y240rj038jdpbrc02ff85xp7bplh4m7dr4fnhj";
}) { } }:

with pkgs;

mkShellNoCC { buildInputs = [ _1password ]; }
mmlb commented 2 years ago

I've worked around this for now by hacking my direnvrc to:

use_nix() {
    lorri watch --once &>/dev/null
    eval "$(lorri direnv)"
}

but this is probably going to not be great (blocking direnv in the foreground?)

mmlb commented 2 years ago

This may be less blocky

use_nix() {
    [[ ${NIXPKGS_ALLOW_UNFREE:-} == 1 ]] && lorri watch --once &>/dev/null
    eval "$(lorri direnv)"
}