NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.53k stars 1.5k forks source link

nix print-dev-env crashes on some naugthy strings #4984

Open thufschmitt opened 3 years ago

thufschmitt commented 3 years ago

Describe the bug

Some special strings cause an error in nix print-dev-env (and nix develop). #4983 does fix some of these, but trying to test this against https://github.com/minimaxir/big-list-of-naughty-strings quickly raises the same error.

Steps To Reproduce

Run nix develop on the following flake:

{
  inputs.blns = {
    url = "github:minimaxir/big-list-of-naughty-strings";
    flake = false;
  };
  outputs = { blns, nixpkgs, ... }:
    let naugthyStrings = builtins.fromJSON (builtins.readFile "${blns}/blns.json"); in
    {
    devShell.x86_64-linux = derivation ({
      name = "test";
      builder = "${nixpkgs.legacyPackages.x86_64-linux.bash}/bin/bash";
      args = [
        (builtins.toFile "builder" ''
          set -exuo pipefail
          echo hier
          echo $FOO > $out
        '')
      ];
      outputs = [ "out" ];
      system = "x86_64-linux";
    } // builtins.listToAttrs (
      builtins.genList (
        idx: { name = "naugthy_${toString idx}"; value = builtins.elemAt naugthyStrings idx; }
      )
      (builtins.length naugthyStrings)
    )
    );
  };
}
$ nix develop
error: shell environment '/nix/store/q7qf6i0ryvk4nllbj278s04zhnbj6fz0-test-env' has unexpected line 'naugthy_100=$'\303\245\303\237\342\210\202\306\222\302\251\3'

Expected behavior

Should work™

nix-env --version output

$ nix --version                                           
nix (Nix) 2.4pre20210519_af4ff64
roblabla commented 3 years ago

It also fails on some not naughty strings with practical use-cases: I need to pass an environment variable containing windowsy path as part of a cross-compilation setup. The following fails:

{
  inputs = {
    nixpkgs.url      = "github:nixos/nixpkgs/nixos-unstable";
    flake-utils.url  = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      rec {
        devShell = nixpkgs.legacyPackages.${system}.mkShell (rec {
          CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS = "-C link-arg=/pdbsourcepath:X:\\source -C link-arg=/pdbaltpath:X:\\output\\%_PDB%";
        });
      }
    );
}

with this error:

error: shell environment '/nix/store/ahf9fdjjy696fy611ia894ifhppnx1ic-nix-shell-env' has unexpected line 'CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS='-C link-arg=/'

nix --version output: nix (Nix) 2.4pre20210601_5985b8b

thufschmitt commented 3 years ago

@roblabla I think this should have been fixed by https://github.com/NixOS/nix/pull/4997. Can you double-check?

NickCao commented 3 years ago

With stdenv: add isMachO helper function merged, naughty strings now find their way into nixpkgs, and breaks nearly every nix develop invocation.

edolstra commented 3 years ago

@NickCao With nix master?

NickCao commented 3 years ago

reproduced on master.

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/ff748a82a5fff004c952f32eacd64604a6f4036f";
    flake-utils.url = "github:numtide/flake-utils";
  };
  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem
      (system:
        let
          pkgs = import nixpkgs { inherit system; };
        in
        {
          devShell = pkgs.mkShell {
            nativeBuildInputs = with pkgs;[ hello ];
          };
        }
      );
}
nix run github:NixOS/nix/1ec4efa6c82fb6d90887c21aa7c7c6f3c644dd65 print-dev-env
winterqt commented 3 years ago

With stdenv: add isMachO helper function merged, naughty strings now find their way into nixpkgs, and breaks nearly every nix develop invocation.

This is due to our use of declare -F to retrieve the loaded functions in get-env.sh.

I opened an issue at https://github.com/NixOS/nix/issues/5262 with further context, but unsure if that should be closed in favor of this one.

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info