NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.38k stars 13.61k forks source link

chrootenv fails with main: execvp(*argv, argv): No such file or directory #200721

Open hgl opened 1 year ago

hgl commented 1 year ago

Describe the bug

When using direnv and pkgs.buildFHSUserEnv, it fails with

** (process:2145): ERROR **: 15:36:44.639: main: execvp(*argv, argv): No such file or directory

I traced the error to chrootenv

Steps To Reproduce

Run

/nix/store/x242zl40s779s96zr02qbidxdyxvqwk0-chrootenv/bin/chrootenv echo

Expected behavior

No error

Screenshots

** (process:2202): ERROR **: 15:38:30.010: main: execvp(*argv, argv): No such file or directory

Additional context

I think this is the code causing this error: https://github.com/NixOS/nixpkgs/blob/492d2256f4ad1450da8861063e97af2d0c0f94b9/pkgs/build-support/build-fhs-userenv/chrootenv/src/chrootenv.c#L152

I use Nixpkgs unstable commit 72d8853228c9758820c39b8659415b6d89279493 I use this flake.nix with direnv as a test case

{
  inputs.nixpkgs.url = "nixpkgs";
  inputs.utils.url = "flake-utils";

  outputs = { self, nixpkgs, utils }:
    utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
        fhs = pkgs.buildFHSUserEnv {
          name = "openwrt-env";
          targetPkgs = pkgs: with pkgs; [
            unzip
          ];
          multiPkgs = null;
          extraOutputsToInstall = [ "dev" ];
          profile = ''
            export hardeningDisable=all
          '';
          runScript = "bash";
        };
      in
      { devShells.default = fhs.env; }
    );
}

Notify maintainers

@yanalunaterra

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.


- system: `"x86_64-linux"`
 - host os: `Linux 5.15.77, NixOS, 22.11 (Raccoon), 22.11.20221110.72d8853`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.11.0`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos````
hgl commented 1 year ago

@yanalunaterra After checking chrootenv's source code I realized the cause was that I had mounted something on /host. Maybe chrootenv could create some flag file to make the detection a little more resilient? The current error message is a little cryptic to debug.