How to activate multiStdenv.mkDerivation in a nix-shell

TL;DR: How to activate multiStdenv.mkDerivation in a nix-shell. Here is the nix file so fare:

# pip-shell.nix
{ pkgs ? import <nixpkgs> {} }:
(pkgs.buildFHSUserEnv {
  name = "pipzone";
  targetPkgs = pkgs: (with pkgs; [
    python39
    python39Packages.pip
    python39Packages.virtualenv
    # needed for pyrosm:
    libgcc
    binutils
    # https://nixos.wiki/wiki/Packaging/32bit_Applications
  ]);
  runScript = "bash";
}).env

Long Story: I’m pretty new to nixos and want to setup a python project. The project needs the pip package pyrosm, which depends on cykhash, which apparently needs some c compiler stuff. I already got rid of some pip install errors by adding libgcc and binutils. However still have an error /nix/store/1fn92b0783crypjcxvdv6ycmvi27by0j-binutils-2.40/bin/ld: cannot find crti.o: No such file or directory which according to this post could be solved on ubuntu by installing gcc-multilib. On nix it should be possible to solve by adding multiStdenv.mkDerivation, but how do i do so? Thanks for any help!

1 Like

I managed to solve the problem and want to share the solution in case anybody else has the same problem.

  1. First of all, the problem was not missing gcc-multilib but instead the ld could not find the libraries
  2. Defining export LIBRARY_PATH=/usr/lib:/usr/lib64:$LIBRARY_PATH solved the problem
  3. (Adding the necessary packages (e.g. libgcc binutils) to multiPkgs instead of targetPkgs may also helps)
1 Like

But in Nixos there are no such paths /usr/lib and /usr/lib64. Or I misunderstand sth?

UPD:
ahh, I see u use buildFHSUserEnv. Thank u very much, rn everything works properly

1 Like

Appendix: Here is the full script:

# shell.nix
{ pkgs ? import <nixpkgs> {} }:
(pkgs.buildFHSUserEnv {
  name = "pipzone";
  targetPkgs = pkgs: (with pkgs; [
    python39
    python39Packages.pip
    python39Packages.virtualenv
  ]);
  multiPkgs = pkgs: with pkgs; [
    libgcc
    binutils
    coreutils
  ];  
  profile = ''
    export LIBRARY_PATH=/usr/lib:/usr/lib64:$LIBRARY_PATH
    # export LIBRARY_PATH=${pkgs.libgcc}/lib # this may also works, not tested
  '';
  runScript = "bash";
}).env
1 Like