on-nix/python

glibc-2.32-54/lib/libc.so.6: version `GLIBC_2.33' not found

Closed this issue · 2 comments

Using a default.nix (nixpkgs on latest 21.05 channel) with the contents at the end and after cd-ing into the containing dir with .envrc from direnv, I get no error from Python on Nix and I can find the python packages and executables (e.g. jupyter) sure enough, but when starting an Emacs via emacs& I get this error (it works outside this derivation):

/nix/store/2v03l28821nl0gxffwyq3azh8qlq4lgv-emacs-27.2/bin/emacs: /nix/store/jsp3h3wpzc842j0rz61m5ly71ak6qgdn-glibc-2.32-54/lib/libc.so.6: version `GLIBC_2.33' not found (required by /nix/store/vyqnqbp3yczrzjx2byk6p680q3mzanyw-gcc-10.3.0-lib/lib64/libstdc++.so.6)

Any ideas on how to debug this further? Maybe related NixOS/nixpkgs#131979 (comment)?

let
  # import projects as explained in previous sections
  nixpkgs = import <nixpkgs> {};
  pythonOnNix = import (builtins.fetchGit {
    # Use `main` branch or a commit from this list:
    # https://github.com/on-nix/python/commits/main
    ref = "main";
    url = "https://github.com/on-nix/python";
  });

  # Create a Python on Nix environment as explained in previous sections
  env = pythonOnNix.python39Env {
    name = "lg";
    projects = {
      numpy = "latest";
      pandas = "latest";
      jupyter-core = "latest";
    };
  };
in
nixpkgs.stdenv.mkDerivation {
  buildInputs = [ env ];
  builder = builtins.toFile "builder.sh" ''
    source $stdenv/setup

    set -x

    python --version
    python -c 'import numpy; print(numpy.__version__)'
    python -c 'import pandas; print(pandas.__version__)'
    python -c 'import jupyter; print(jupyter.__version__)'

    touch $out

    set +x
  '';
  name = "lg";
}

Yes, I know why this happens. it's because the glibc version we use on Python on Nix is different than the one you are using on your Emacs, the trick is to make Emacs and Python on Nix use the same nixpkgs

I just made a few tweaks to the project so this is possible now:

let
  # Use here the same nixpkgs you use for Emacs
  nixpkgs = import <nixpkgs> { };

  pythonOnNix = import
    (builtins.fetchGit {
      ref = "main";
      url = "https://github.com/on-nix/python";
    })
    {
      # Python on Nix will use the same nixpkgs as your `emacs` now
      inherit nixpkgs;
    };

  # Create a Python on Nix environment as explained in previous sections
  env = pythonOnNix.python39Env {
    name = "lg";
    projects = {
      numpy = "latest";
      pandas = "latest";
      jupyter-core = "latest";
    };
  };
in
nixpkgs.stdenv.mkDerivation {
  buildInputs = [ env ];
  builder = builtins.toFile "builder.sh" ''
    source $stdenv/setup

    set -x

    python --version
    python -c 'import numpy; print(numpy.__version__)'
    python -c 'import pandas; print(pandas.__version__)'
    python -c 'import jupyter; print(jupyter)'

    touch $out

    set +x
  '';
  name = "lg";
}

please let me know if it worked!

Thanks a lot for the super fast fix, it works!