ES-Nix / poetry2nix-examples

Examples of usage of nix + flakes + poetry2nix
MIT License
4 stars 1 forks source link

The python pandas error libstdc++.so.6: cannot open shared object #3

Open PedroRegisPOAR opened 3 years ago

PedroRegisPOAR commented 3 years ago

TL;DR

It is an really hard problem, an NP-hard problem...

The gist is that neovim is just a C project, therefore doesn't link against C++. However, many plugins do use C++. And when the plugins are downloaded as pre-compiled binaries, there was no previous loading of C++ libraries and no good "convention" on where to find them. This wouldn't be an issue on FHS systems, as the library in question libstdc++.so.6 is likely to exist.

Ultimately, it's an anti-pattern to try and distribute binaries outside of a system-compatible package manager. The issue of C++ abi is just waiting to blow off someone's foot. It's "works on my computer today", tomorrow it could be "can't run any C++ application". Refs.:

[ ... ] This is something of a digression, but it does relate - has it been confirmed that the “crashing issue” isn’t simply a case of code triggering undefined C++ behaviour in a way that would happen even if the exact same compiler was used throughout? I’m thinking specifically of the static initialization order ‘fiasco’ which can cause crashes in completely statically linked programs compiled with a single compiler.

We’re getting to a point here where we are presuming that “something needs to be included” in the specs for this issue. But if there’s still a realistic possibility that this is just badly written C++ code that triggers undefined behaviour completely within the C++ language sense (i.e., even if we ignore dynamic linking and libstdc++), then we may be expecting too much from the PEPs.

The C++ standard says nothing about dynamic linking, or how runtime support is loaded into a program. So we’re way into the area of undefined behaviour here. The C++ standards say nothing about mixing compilers, or dynamic linking, and C++ is known not to guarantee ABI-level compatibility between compilers, so at a theoretical level, any version of manylinux has to mandate that the same compiler is used for all compatible wheels. But we’re looking for a practical standard here, not a theoretically-perfect one… [ ... ] Refs.:

LD_PRELOAD cannot be used because the glibc dynamic linker (sometimes called ld.so or the program interpreter; the location on disk is platform-specific) is only compatible with libc.so.6 (and the rest of the libraries) from the same glibc build.

You can use an explicit loader invocation of the other glibc, along with library path settings that cause the loader to load the glibc objects from a separate directory, and not the system directories. https://stackoverflow.com/a/55186835

The wheel’s binary executables or shared objects may not link against externally-provided libraries except those in the following list:

libgcc_s.so.1
libstdc++.so.6
libm.so.6
libdl.so.2
librt.so.1
libc.so.6
libnsl.so.1
libutil.so.1
libpthread.so.0
libresolv.so.2
libX11.so.6
libXext.so.6
libXrender.so.1
libICE.so.6
libSM.so.6
libGL.so.1
libgobject-2.0.so.0
libgthread-2.0.so.0
libglib-2.0.so.0

Refs.:

TODOs

Re read it: https://stackoverflow.com/a/47149524

TODO: join all that is linked here, might be enough, to fix this painfull problem!!

https://github.com/ES-Nix/environments/issues/1

++

Document how to work around dynamic linking problems caused by glibc updates

++ TODO: help there https://ask.replit.com/t/cant-build-package-because-it-needs-glibc-2-34-older-than-what-is-installed/39215/4 ++

export NIXPKGS_ALLOW_UNFREE=1
nix \
develop \
--impure \
--expr \
'
  (
    let
      # nixpkgs = (builtins.getFlake "github:NixOS/nixpkgs/683f2f5ba2ea54abb633d0b17bc9f7f6dede5799");
      nixpkgs = (builtins.getFlake "github:NixOS/nixpkgs/ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b");
      pkgs = import nixpkgs {};
    in
      pkgs.stdenv.mkDerivation {
        name = "python-env";
        dontUnpack = true; 
        buildInputs = with pkgs; [ (python3.withPackages (pyPkgs: with pyPkgs; [ gtts ])) vlc ];

        buildPhase = "mkdir $out";
        dontInstall = true;
        # https://github.com/ES-Nix/environments/issues/1
        LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath ([ 
            # Deprecated?
            # pkgs.pythonManylinuxPackages.manylinux1Package
            pkgs.pythonManylinuxPackages.manylinux2010Package
            pkgs.pythonManylinuxPackages.manylinux2014Package

            pkgs.addOpenGLRunpath
            pkgs.glib.out
            pkgs.libglvnd
            pkgs.stdenv.cc.cc.lib 
            # pkgs.steam-run
            pkgs.xorg.libX11 
            pkgs.zlib
        ]
        ++
       (with pkgs; [

        # python2
        (curl.override { gnutlsSupport = true; opensslSupport = false; })
        (writeShellScriptBin "sudo" "true") # suid wrappers messing with suff
        SDL
        SDL2
        SDL2_image
        SDL2_mixer
        SDL2_ttf
        SDL_image
        SDL_mixer
        SDL_ttf
        alsa-lib
        at-spi2-atk
        at-spi2-core
        atk
        bashInteractive
        bzip2
        cairo
        cups
        dbus
        dbus-glib
        desktop-file-utils
        e2fsprogs
        expat
        flac
        fontconfig
        freeglut
        freetype
        fribidi
        fuse
        fuse3
        gdk-pixbuf
        glew110
        glib
        gmp
        gnome.zenity
        gnome2.GConf
        gsettings-desktop-schemas
        gst_all_1.gst-plugins-base
        gst_all_1.gst-plugins-ugly
        gst_all_1.gstreamer
        gtk2
        gtk3
        harfbuzz
        hicolor-icon-theme # dont show a gtk warning about hicolor not being installed
        iana-etc
        keyutils.lib
        krb5
        libGL
        libGLU
        libappindicator-gtk2
        libcaca
        libcanberra
        libcap
        libdrm
        libgcrypt
        libgpg-error
        libidn
        libjack2
        libjpeg
        libmikmod
        libogg
        libpng12
        librsvg
        libsamplerate
        libtheora
        libtiff
        libtool.lib # for Synfigstudio
        libudev0-shim
        libusb1
        libuuid
        libvdpau
        libvorbis
        libvpx
        libxkbcommon
        mesa
        nspr
        nss
        openssl
        p11-kit
        pango
        perl
        pixman
        pulseaudio
        speex
        tbb
        udev
        wayland
        which
        xdg-utils
        xorg.libICE
        xorg.libSM
        xorg.libX11
        xorg.libXScrnSaver
        xorg.libXcomposite
        xorg.libXcursor
        xorg.libXdamage
        xorg.libXext
        xorg.libXfixes
        xorg.libXft
        xorg.libXi
        xorg.libXinerama
        xorg.libXmu
        xorg.libXrandr
        xorg.libXrender
        xorg.libXt
        xorg.libXtst
        xorg.libXxf86vm
        xorg.libpciaccess
        xorg.libxcb
        xorg.libxshmfence # for apple-music-electron
        xorg.xcbutil
        xorg.xcbutilimage
        xorg.xcbutilkeysyms
        xorg.xcbutilrenderutil
        xorg.xcbutilwm
        xorg.xkeyboardconfig
        xorg.xrandr
        zlib
      ]))
      ;
    }
  )
'

Refs.:

Some references

TODO:

podman run -it --rm quay.io/pypa/manylinux1_x86_64

mkdir /output /opt/python/cp36-36mu/pip wheel /src -w output

auditwheel repair /output/mylibrary*whl -w /output Refs.: https://opensource.com/article/19/2/manylinux-python-wheels

TODO:

See how to check for wheels:

pip download pandas==2.0.0 --platform=manylinux2014_aarch64 --only-binary=:all: --python-version=3.9 --implementation=cp

Refs.:

Inspecting binaries

# nix shell nixpkgs#which nixpkgs#binutils nixpkgs#gnugrep
readelf --program-headers "$(which id)" | grep interpreter

Refs.:

What package provides libstdc++.so.6?

TODO:

ls -al $(nix build --no-link --print-out-paths --print-build-logs nixpkgs#gfortran.cc.lib)/lib/libstdc++.so.

1)

nix build --no-link nixpkgs#gcc-unwrapped.lib \
&& readlink -f $(nix eval --raw nixpkgs#gcc-unwrapped.lib)/lib/libstdc++.so.6

Refs.:

2)

nix build --no-link nixpkgs#stdenv.cc.cc.lib \
&&  readlink -f $(nix eval --raw nixpkgs#stdenv.cc.cc.lib)/lib/libstdc++.so.6

3)

nix build --no-link nixpkgs#pythonManylinuxPackages.manylinux1Package \
&& readlink -f $(nix eval --raw nixpkgs#pythonManylinuxPackages.manylinux1Package)/lib/libstdc++.so.6

4)

nix build --no-link nixpkgs#pythonManylinuxPackages.manylinux2010Package \
&& readlink -f $(nix eval --raw nixpkgs#pythonManylinuxPackages.manylinux1Package)/lib/libstdc++.so.6

5)

nix build --no-link nixpkgs#pythonManylinuxPackages.manylinux2014Package \
&& readlink -f $(nix eval --raw nixpkgs#pythonManylinuxPackages.manylinux1Package)/lib/libstdc++.so.6

6)

nix build --no-link nixpkgs#glibc.out \
&& file $(nix eval --raw nixpkgs#glibc.out)/lib/ld-linux-x86-64.so.2 \
&& ldd $(nix eval --raw nixpkgs#glibc.out)/lib/ld-linux-x86-64.so.2

7)

nix build --no-link github:NixOS/nixpkgs/nixpkgs-unstable#stdenv.cc.bintools \
&& file $(nix eval --raw github:NixOS/nixpkgs/nixpkgs-unstable#stdenv.cc.bintools.dynamicLinker) \
&& ldd $(nix eval --raw github:NixOS/nixpkgs/nixpkgs-unstable#stdenv.cc.bintools.dynamicLinker)

8) TODO: re-reead it and make more examples

objdump -T /lib/x86_64-linux-gnu/libgcc_s.so.1|grep -F '*UND*'

Refs.:

objdump -T /lib/x86_64-linux-gnu/libgcc_s.so.1|grep -F '*UND*'
nix \
shell \
nixpkgs#auditwheel \
nixpkgs#binutils.out \
nixpkgs#glibc.bin \
nixpkgs#patchelf \
nixpkgs#python3Packages.pip \
nixpkgs#python3Packages.wheel \
nixpkgs#python3Packages.wheel-filename  \
nixpkgs#python3Packages.wheel-inspect \
nixpkgs#readelf \
nixpkgs#twine 

TODO: https://stackoverflow.com/questions/4133674/glibcxx-versions?rq=3

readelf -a and objdump -x

TODO: https://stackoverflow.com/a/3436360

objdump -T 
nix build --no-link github:NixOS/nixpkgs/nixpkgs-unstable#stdenv.cc.bintools \
&& file $(nix eval --raw github:NixOS/nixpkgs/nixpkgs-unstable#stdenv.cc.bintools.dynamicLinker) \
&& ldd $(nix eval --raw github:NixOS/nixpkgs/nixpkgs-unstable#stdenv.cc.bintools.dynamicLinker)

TODO

# nix flake metadata nixpkgs --json | jq --join-output '.url'                                            
# github:NixOS/nixpkgs/8c7576622aeb4707351a17e83429667f42e7d91
nix show-derivation nixpkgs#pythonManylinuxPackages.manylinux2014Package | jq -r '.[].env.buildCommand'
export LD_LIBRARY_PATH="${pkgsAllowUnfree.pythonManylinuxPackages.manylinux2014Package}"/lib:"${pkgsAllowUnfree.zlib}"/lib
python -c 'import pandas as pd; pd.DataFrame()'

TODO:

Make something like this work:

libPythonManylinuxPackagesPath = lib.makeLibraryPath with pythonManylinuxPackages; [ 
  manylinux1Package
  manylinux2010Package
  manylinux2014Package
];
libPath = lib.makeLibraryPath [ xorg.libX11 xorg.libXtst glib libglvnd openssl gtk3 cairo pango curl ];

https://github.com/NixOS/nixpkgs/blob/fe76645aaf2fac3baaa2813fd0089930689c53b5/pkgs/applications/editors/sublime/4/common.nix#L26

combined with

      for binary in ${ builtins.concatStringsSep " " binaries }; do
        patchelf \
          --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
          --set-rpath ${libPath}:${stdenv.cc.cc.lib}/lib${lib.optionalString stdenv.is64bit "64"} \
          $binary
      done

https://github.com/NixOS/nixpkgs/blob/fe76645aaf2fac3baaa2813fd0089930689c53b5/pkgs/applications/editors/sublime/4/common.nix#L63-L68

combined with

  propagatedBuildInputs = [
    pkgs.pythonManylinuxPackages.manylinux2014Package
  # pkgs.python38Packages.tkinter
  ];

  # Add .so to the linker path
  # https://github.com/NixOS/nixpkgs/blob/09078fd022f1e1ca5272c22c5f2a2d6ceac0845f/nixos/doc/manual/release-notes/rl-2405.section.md#other-notable-changes-sec-release-2405-notable-changes
  LD_LIBRARY_PATH = "/run/opengl-driver/lib:${
    pkgs.pythonManylinuxPackages.manylinux2014Package
  }/lib";

https://github.com/archaict/Project/blob/b117de8260eb00008d9a148d12b5edb9c75fac8d/NixOS/incantation/python/shell.nix#L11-L19

combined with

https://github.com/Mic92/nix-ld/tree/29f15b1f7e37810689974ef169496c51f6403a1b#my-pythonnodejsrubyinterpreter-libraries-do-not-find-the-libraries-configured-by-nix-ld

combined with

nix run github:nixified-ai/flake/0c58f8cba3fb42c54f2a7bf9bd45ee4cbc9f2477#koboldai-nvidia

LD_LIBRARY_PATH

List:

TODO: watch and make examples

NIX_LDFLAGS, NIX_CFLAGS_COMPILE, NIX_CFLAGS_LINK

https://stackoverflow.com/questions/77487821/nixos-newer-glibc-version-forced-by-environment-outside-nix-shell

Seriouslly?

    echo $NIX_LDFLAGS
    echo $NIX_CFLAGS_COMPILE
    echo $NIX_CFLAGS_LINK

LD_PRELOAD

List:

file $(ldd $(which id) | tail -n1 | cut -d' ' -f1)
$(ldd $(which id) | tail -n1 | cut -d' ' -f1) --version

patchelf --print-needed $(which id)

ldd $(which id)
nix run nixpkgs#nixpkgs-fmt **/*.nix *.nix

ldd

TODO: Linkers, Loaders and Shared Libraries in Windows, Linux, and C++ - Ofek Shilon - CppCon 2023 triage it!

You should learn to never use ldd on your patched binary, as it will lie to you. https://stackoverflow.com/a/57500916

https://reverseengineering.stackexchange.com/questions/6657/why-does-ldd-and-gdb-info-sharedlibrary-show-a-different-library-base-addr#comment19796_6665

https://i.stack.imgur.com/FF1Zv.png https://reverseengineering.stackexchange.com/a/14639

libgcc_s

  # Explicitly link against libgcc_s, to work around the infamous
  # "libgcc_s.so.1 must be installed for pthread_cancel to work".
  LDFLAGS = lib.optionalString stdenv.isLinux "-lgcc_s";

https://github.com/NixOS/nixpkgs/blob/cf28ee258fd5f9a52de6b9865cdb93a1f96d09b7/pkgs/tools/networking/iftop/default.nix#L12-L14

strace

Running strace -vfefile on the wrapped executable, looking for libraries that can't be found.

sudo \
strace \
-v \
-s 4096 \
-f \
-o trace.txt \
id

chroot

% chroot . ./test.static
Hello, world!

% chroot . ./test.dynamic
chroot: failed to run command './test.dynamic': No such file or directory

Refs.:

nm

Everything you need to build your own nm and otool

nm --demangle --dynamic --defined-only --extern-only --with-symbol-versions $(which nix) | wc -l

Refs.:

TODOs:

DT_RPATH vs DT_RUNPATH

List:

readelf -d a.out | grep 'R.*PATH'

Refs.:

objdump -x binary-or-library | grep 'R.*PATH'

Refs.:

readelf -d binary-or-library | head -20

Refs.:

chrpath -l binary-or-library

Refs.:

The C macros GLIBC and __GLIBC_MINOR__

TODO:

nix \
shell \
--ignore-environment \
github:NixOS/nixpkgs/release-20.03#{bashInteractive,coreutils,gcc,gnugrep} \
--command \
bash \
-c \
"
echo '#include <errno.h>' \
| gcc -xc - -E -dM \
| grep -E '^#define __GLIBC(|_MINOR)__ ' \
| sort
"

nix \
shell \
--ignore-environment \
github:NixOS/nixpkgs/release-23.05#{bashInteractive,coreutils,gcc,gnugrep} \
--command \
bash \
-c \
"
echo '#include <errno.h>' \
| gcc -xc - -E -dM \
| grep -E '^#define __GLIBC(|_MINOR)__ ' \
| sort
"

nix \
shell \
--ignore-environment \
github:NixOS/nixpkgs/nixpkgs-unstable#{bashInteractive,coreutils,gcc,gnugrep} \
--command \
bash \
-c \
"
echo '#include <errno.h>' \
| gcc -xc - -E -dM \
| grep -E '^#define __GLIBC(|_MINOR)__ ' \
| sort
"
echo '#include <errno.h>' \
| gcc -xc - -E -dM \
| grep -E '^#define __GLIBC(|_MINOR)__ ' \
| sort

Refs.:

How to find dlopen calls?

LD_DEBUG=files,libs CMD

Refs.:

For example:

LD_DEBUG=files,libs pycharm-community

Refs.:

C example: https://unix.stackexchange.com/a/462710

strace -e trace=open,openat myprogram

Refs.:

ltrace -S CMD

Refs.:

TODO: https://stackoverflow.com/questions/25785212/how-to-print-all-the-shared-objects-in-memory-at-a-particular-time

lsof -p $PID | grep mem

Refs.:

https://docs.rs/dlopen/latest/dlopen/

Python libs for tests

TODO: the polars lib https://search.nixos.org/packages?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=polars

python310Packages.pwntools

cryptography

nix build --print-out-paths --print-build-logs nixpkgs#python3Packages.localstack.dist

Mixed

List:

Maybe it is another way to have the same error?

First, regarding the address of main: It seems one would have to use the Section Headers to find out the address of main. Doing it just using the dynamic section seems not possible. Running readelf -D -s and readelf -D --dyn-sym does not give the address of main either.

PedroRegisPOAR commented 3 years ago

WIP: retried it all

Details

nix profile install nixpkgs#python3
nix profile install --no-write-lock-file github:nix-community/poetry2nix/869580c729e658ffe74d8d1d0c3cb132d33a6126#poetry

mkdir -p ~/troubleshoot-pandas-flake \
&& cd ~/troubleshoot-pandas-flake \
&& poetry config virtualenvs.in-project true \
&& poetry config virtualenvs.path . \
&& poetry init --no-interaction  \
&& poetry lock \
&& poetry show --tree \
&& poetry add pandas==1.5.0
mkdir -p "$HOME"/troubleshoot-pandas-flake \
&& cd "$HOME"/troubleshoot-pandas-flake 
cat <<WRAP > "$HOME"/troubleshoot-pandas-flake/flake.nix
{
  description = "A usefull description";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.poetry2nix-src.url = "github:nix-community/poetry2nix/869580c729e658ffe74d8d1d0c3cb132d33a6126";

  outputs = { self, nixpkgs, flake-utils, poetry2nix-src }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgsAllowUnfree = import nixpkgs {
          system = "x86_64-linux";
          config = { allowUnfree = true; };
        };

        pkgs = import nixpkgs { inherit system; overlays = [ poetry2nix-src.overlay ]; };
        env = pkgsAllowUnfree.poetry2nix.mkPoetryEnv {
          poetrylock = ./poetry.lock;
          projectDir = ./.;
          python = pkgsAllowUnfree.python3;
        };
      in
      {
        devShell = pkgsAllowUnfree.mkShell {
          buildInputs = with pkgsAllowUnfree; [
            poetry
            env
          ];

          shellHook = ''
            unset SOURCE_DATE_EPOCH
          '';
        };
      });
}
WRAP

command -v nix 1> /dev/null 2> /dev/null || echo 'The nix binary was not found'
test -x git || nix profile install nixpkgs#git

git init 
git add .

# Lock it, time passes and things get out of synchronization
# nix flake update --override-input nixpkgs nixpkgs/dca55d9a451fba34c87e8adea7a3782d667149fa
nix flake lock

git add .

poetry config virtualenvs.in-project true \
&& poetry config virtualenvs.path . \
&& poetry init --no-interaction  \
&& poetry lock \
&& poetry show --tree \
&& poetry add pandas==1.5.0  \
&& poetry lock \
&& poetry show --tree

git add .

nix develop --command python -c 'import pandas'

Other

nix profile install nixpkgs#poetry nixpkgs#python3 nixpkgs#gcc nixpkgs#stdenv.cc.cc.lib
mkdir -p ~/troubleshoot-pandas \
&& cd ~/troubleshoot-pandas \
&& poetry config virtualenvs.in-project true \
&& poetry config virtualenvs.path . \
&& poetry init --no-interaction  \
&& poetry lock \
&& poetry show --tree \
&& poetry add pandas==1.1.5
nix profile install nixpkgs#poetry nixpkgs#python3 nixpkgs#gcc
mkdir -p ~/troubleshoot-pandas \
&& cd ~/troubleshoot-pandas \
&& poetry config virtualenvs.in-project true \
&& poetry config virtualenvs.path . \
&& poetry init --no-interaction  \
&& poetry lock \
&& poetry show --tree \
&& poetry add pandas==1.1.5
nix profile install nixpkgs/7138a338b58713e0dea22ddab6a6785abec7376a#poetry nixpkgs#python3
mkdir -p ~/troubleshoot-pandas \
&& cd ~/troubleshoot-pandas \
&& poetry config virtualenvs.in-project true \
&& poetry config virtualenvs.path . \
&& poetry init --no-interaction  \
&& poetry lock \
&& poetry show --tree \
&& poetry add pandas==1.1.5
mkdir -p ~/troubleshoot-pandas \
&& cd ~/troubleshoot-pandas \
&& poetry config virtualenvs.in-project true \
&& poetry config virtualenvs.path . \
&& poetry init --no-interaction  \
&& poetry lock \
&& poetry show --tree \
&& poetry add pandas==1.1.5  \
&& poetry lock \
&& poetry show --tree \
&& poetry run python -c 'import pandas; print(pandas.__package__)'
python -c 'import pandas'

Test


mkdir -p "$HOME"/troubleshoot-pandas-flake \
&& cd "$HOME"/troubleshoot-pandas-flake

curl http://ix.io/49FS > flake.nix
curl http://ix.io/49FQ > flake.lock
curl http://ix.io/49FR > pyproject.toml
curl http://ix.io/49FT > poetry.lock

git init
git add .

nix develop --command python -c 'import pandas'
mkdir -p "$HOME"/troubleshoot-pandas-flake \
&& cd "$HOME"/troubleshoot-pandas-flake 
cat <<WRAP > "$HOME"/troubleshoot-pandas-flake/flake.nix
{
  description = "A usefull description";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.poetry2nix-src.url = "github:nix-community/poetry2nix";

  outputs = { self, nixpkgs, flake-utils, poetry2nix-src }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgsAllowUnfree = import nixpkgs {
          system = "x86_64-linux";
          config = { allowUnfree = true; };
        };

        pkgs = import nixpkgs { inherit system; overlays = [ poetry2nix-src.overlay ]; };
        env = pkgsAllowUnfree.poetry2nix.mkPoetryEnv {
          poetrylock = ./poetry.lock;
          projectDir = ./.;
          python = pkgsAllowUnfree.python3;
        };
      in
      {
        devShell = pkgsAllowUnfree.mkShell {
          buildInputs = with pkgsAllowUnfree; [
            poetry
            env
          ];

          shellHook = ''
            unset SOURCE_DATE_EPOCH
          '';
        };
      });
}
WRAP

command -v nix 1> /dev/null 2> /dev/null || echo 'The nix binary was not found'
test -x git || nix profile install nixpkgs#git
test -x poetry || nix profile install nixpkgs#poetry

git init 
git add .

# Lock it, time passes and things get out of synchronization
nix flake update --override-input nixpkgs nixpkgs/dca55d9a451fba34c87e8adea7a3782d667149fa
nix flake lock

git add .

poetry config virtualenvs.in-project true \
&& poetry config virtualenvs.path . \
&& poetry init --no-interaction  \
&& poetry lock \
&& poetry show --tree \
&& poetry add pandas==1.1.5  \
&& poetry lock \
&& poetry show --tree

git add .

nix develop --command python -c 'import pandas'

buildInputs

mkdir -p "$HOME"/troubleshoot-pandas-flake \
&& cd "$HOME"/troubleshoot-pandas-flake 
cat <<WRAP > "$HOME"/troubleshoot-pandas-flake/flake.nix
{
  description = "A usefull description";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.poetry2nix-src.url = "github:nix-community/poetry2nix";

  outputs = { self, nixpkgs, flake-utils, poetry2nix-src }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgsAllowUnfree = import nixpkgs {
          system = "x86_64-linux";
          config = { allowUnfree = true; };
        };

        pkgs = import nixpkgs { inherit system; overlays = [ poetry2nix-src.overlay ]; };
        env = pkgsAllowUnfree.poetry2nix.mkPoetryEnv {
          poetrylock = ./poetry.lock;
          projectDir = ./.;

          python = pkgsAllowUnfree.python3;

          overrides = [
            pkgsAllowUnfree.poetry2nix.defaultPoetryOverrides
            (self: super: {
              pandas = super.pandas.overridePythonAttrs (old: {
                buildInputs = old.buildInputs ++ [
                  self.stdenv.cc.cc.lib
                ];
              });
            })
          ];
        };
      in
      {
        devShell = pkgsAllowUnfree.mkShell {
          buildInputs = with pkgsAllowUnfree; [
            poetry
            env
          ];

          shellHook = ''
            unset SOURCE_DATE_EPOCH
          '';
        };
      });
}
WRAP

command -v nix 1> /dev/null 2> /dev/null || echo 'The nix binary was not found'
test -x git || nix profile install nixpkgs#git
test -x poetry || nix profile install nixpkgs#poetry

git init 
git add .

# Lock it, time passes and things get out of synchronization
nix flake update --override-input nixpkgs nixpkgs/dca55d9a451fba34c87e8adea7a3782d667149fa
nix flake lock

git add .

poetry config virtualenvs.in-project true \
&& poetry config virtualenvs.path . \
&& poetry init --no-interaction  \
&& poetry lock \
&& poetry show --tree \
&& poetry add pandas==1.1.5  \
&& poetry lock \
&& poetry show --tree

git add .

nix develop --command python -c 'import pandas'

nativeBuildInputs

mkdir -p "$HOME"/troubleshoot-pandas-flake \
&& cd "$HOME"/troubleshoot-pandas-flake 
cat <<WRAP > "$HOME"/troubleshoot-pandas-flake/flake.nix
{
  description = "A usefull description";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.poetry2nix-src.url = "github:nix-community/poetry2nix";

  outputs = { self, nixpkgs, flake-utils, poetry2nix-src }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgsAllowUnfree = import nixpkgs {
          system = "x86_64-linux";
          config = { allowUnfree = true; };
        };

        pkgs = import nixpkgs { inherit system; overlays = [ poetry2nix-src.overlay ]; };
        env = pkgsAllowUnfree.poetry2nix.mkPoetryEnv {
          poetrylock = ./poetry.lock;
          projectDir = ./.;

          python = pkgsAllowUnfree.python3;

          overrides = [
            pkgsAllowUnfree.poetry2nix.defaultPoetryOverrides
            (self: super: {
              pandas = super.pandas.overridePythonAttrs (old: {
                nativeBuildInputs = old.nativeBuildInputs ++ [
                  self.stdenv.cc.cc.lib
                ];
              });
            })
          ];
        };
      in
      {
        devShell = pkgsAllowUnfree.mkShell {
          buildInputs = with pkgsAllowUnfree; [
            poetry
            env
          ];

          shellHook = ''
            unset SOURCE_DATE_EPOCH
          '';
        };
      });
}
WRAP

command -v nix 1> /dev/null 2> /dev/null || echo 'The nix binary was not found'
test -x git || nix profile install nixpkgs#git
test -x poetry || nix profile install nixpkgs#poetry

git init 
git add .

# Lock it, time passes and things get out of synchronization
nix flake update --override-input nixpkgs nixpkgs/dca55d9a451fba34c87e8adea7a3782d667149fa
nix flake lock

git add .

poetry config virtualenvs.in-project true \
&& poetry config virtualenvs.path . \
&& poetry init --no-interaction  \
&& poetry lock \
&& poetry show --tree \
&& poetry add pandas==1.1.5  \
&& poetry lock \
&& poetry show --tree

git add .

nix develop --command python -c 'import pandas'
nix develop --command poetry init --no-interaction \
&& poetry show --tree \
&& poetry add pandas==1.1.5 \
&& poetry lock \
&& poetry show --tree \
&& poetry run python -c 'import pandas; print(pandas.__package__)'

Maybe with: propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ self.stdenv.cc.cc.lib ];

mkdir -p "$HOME"/troubleshoot-pandas-flake \
&& cd "$HOME"/troubleshoot-pandas-flake 
cat <<WRAP > "$HOME"/troubleshoot-pandas-flake/flake.nix
{
  description = "A usefull description";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.poetry2nix-src.url = "github:nix-community/poetry2nix";

  outputs = { self, nixpkgs, flake-utils, poetry2nix-src }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgsAllowUnfree = import nixpkgs {
          system = "x86_64-linux";
          config = { allowUnfree = true; };
        };

        pkgs = import nixpkgs { inherit system; overlays = [ poetry2nix-src.overlay ]; };

        env = pkgsAllowUnfree.poetry2nix.mkPoetryEnv {
          poetrylock = ./poetry.lock;
          projectDir = ./.;

          python = pkgsAllowUnfree.python3;

          overrides = [
            pkgsAllowUnfree.poetry2nix.defaultPoetryOverrides
            (self: super: {
              pandas = super.pandas.defaultPythonOverrides (old: {
                propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ self.stdenv.cc.cc.lib ];
              });
            })
          ];
        };
      in
      {
        devShell = pkgsAllowUnfree.mkShell {
          buildInputs = with pkgsAllowUnfree; [
            poetry
            # env
          ];

          shellHook = ''
            unset SOURCE_DATE_EPOCH
          '';
        };
      });
}
WRAP

command -v nix 1> /dev/null 2> /dev/null || echo 'The nix binary was not found'
test -x git || nix profile install nixpkgs#git
test -x poetry || nix profile install nixpkgs#poetry

git init 
git add .

# Lock it, time passes and things get out of synchronization
nix flake update --override-input nixpkgs nixpkgs/dca55d9a451fba34c87e8adea7a3782d667149fa
# nix flake lock

command -v sed 1> /dev/null 2> /dev/null || echo 'The sed binary was not found'
sed -i 's/# env/env/' flake.nix

git add .

poetry config virtualenvs.in-project true \
&& poetry config virtualenvs.path . \
&& poetry init --no-interaction  \
&& poetry lock \
&& poetry show --tree \
&& poetry add pandas==1.1.5  \
&& poetry lock \
&& poetry show --tree

git add .

nix develop --command python -c 'import pandas as pd; pd.DataFrame(); print(pd.__version__)'
PedroRegisPOAR commented 3 years ago
python -c 'import pandas as pd; pd.DataFrame()'
poetry cache list
PedroRegisPOAR commented 2 years ago

May be this helps:

PedroRegisPOAR commented 2 years ago

Using an Alpine OCI image ran with podman

Creating an environment to play inside:

cat > Containerfile << 'EOF'
FROM alpine:3.16.1
RUN apk add --no-cache \
     ca-certificates \
     curl \
     shadow \
     tar \
     xz \
 && echo 'Creating user' \
 && groupadd abcgroup \
 && useradd -g abcgroup -s /bin/sh -m -c 'Eva User' abcuser \
 && echo 'abcuser:123' | chpasswd \
 && echo abcuser:10000:5000 > /etc/subuid \
 && echo abcuser:10000:5000 > /etc/subgid \
 && mkdir -m 0755 /nix && chown abcuser /nix

USER abcuser
WORKDIR /home/abcuser
ENV USER="abcuser"
ENV PATH=/home/abcuser/.nix-profile/bin:/home/abcuser/.local/bin:"$PATH"

EOF

podman \
build \
--file=Containerfile \
--tag=unprivileged-alpine3161 .
nix run nixpkgs#xorg.xhost -- +
podman \
run \
--device=/dev/fuse \
--device=/dev/kvm \
--env="DISPLAY=${DISPLAY:-:0.0}" \
--interactive=true \
--privileged=true \
--rm=true \
--tty=true \
--volume=/tmp/.X11-unix:/tmp/.X11-unix:ro \
localhost/unprivileged-alpine3161:latest \
sh
nix run nixpkgs#xorg.xhost -- -
nix run nixpkgs#xorg.xhost -- +                                           
podman \
run \
--detach=true \
--device=/dev/fuse:rw \
--device=/dev/kvm:rw \
--env="DISPLAY=${DISPLAY:-:0.0}" \
--interactive=false \
--name=conteiner-alpine \
--privileged=true \
--rm=false \
--tty=true \
--volume=/tmp/.X11-unix:/tmp/.X11-unix:ro \
localhost/unprivileged-alpine3161:latest \
sh
nix run nixpkgs#xorg.xhost -- -

Getting an shell in the running container. It can be used in multiple terminals.

podman \
exec \
--interactive=true \
--tty=true \
conteiner-alpine \
sh

Removes the container:

podman rm -f conteiner-alpine

The mmh3

Note: works on my machine :upside_down:

mkdir -p "$HOME"/troubleshoot-mmh3-flake \
&& cd "$HOME"/troubleshoot-mmh3-flake

cat <<WRAP > "$HOME"/troubleshoot-mmh3-flake/flake.nix
{
  description = "A usefull description";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.poetry2nix-src.url = "github:nix-community/poetry2nix/869580c729e658ffe74d8d1d0c3cb132d33a6126";

  outputs = { self, nixpkgs, flake-utils, poetry2nix-src }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgsAllowUnfree = import nixpkgs {
          system = "x86_64-linux";
          config = { allowUnfree = true; };
        };

        pkgs = import nixpkgs { inherit system; overlays = [ poetry2nix-src.overlay ]; };
        env = pkgsAllowUnfree.poetry2nix.mkPoetryEnv {
          poetrylock = ./poetry.lock;
          projectDir = ./.;
          python = pkgsAllowUnfree.python3;
        };
      in
      {
        devShell = pkgsAllowUnfree.mkShell {
          buildInputs = with pkgsAllowUnfree; [
            poetry
            # env
          ];

          shellHook = ''
          '';
        };
      });
}
WRAP

test -x git || nix profile install nixpkgs#git

git init 
git add .

# Lock it, time passes and things get out of synchronization
nix flake update --override-input nixpkgs nixpkgs/dca55d9a451fba34c87e8adea7a3782d667149fa
nix flake lock

git add .

nix develop --command sh<<COMMANDS
poetry config virtualenvs.in-project true \
&& poetry config virtualenvs.path . \
&& poetry init --no-interaction  \
&& poetry lock \
&& poetry show --tree \
&& poetry add mmh3==3.0.0  \
&& poetry lock \
&& poetry show --tree
COMMANDS

git add .

command -v sed 1> /dev/null 2> /dev/null || echo 'The sed binary was not found'
sed -i 's/# env/env/' flake.nix

git add .

nix develop --command python -c 'import mmh3; print(mmh3.hash128(bytes(123)))'

The numpy

Note: IT IS BROKEN

mkdir -p "$HOME"/troubleshoot-numpy-flake \
&& cd "$HOME"/troubleshoot-numpy-flake

cat <<WRAP > "$HOME"/troubleshoot-numpy-flake/flake.nix
{
  description = "A usefull description";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.poetry2nix-src.url = "github:nix-community/poetry2nix/869580c729e658ffe74d8d1d0c3cb132d33a6126";

  outputs = { self, nixpkgs, flake-utils, poetry2nix-src }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgsAllowUnfree = import nixpkgs {
          system = "x86_64-linux";
          config = { allowUnfree = true; };
        };

        pkgs = import nixpkgs { inherit system; overlays = [ poetry2nix-src.overlay ]; };
        env = pkgsAllowUnfree.poetry2nix.mkPoetryEnv {
          poetrylock = ./poetry.lock;
          projectDir = ./.;
          python = pkgsAllowUnfree.python3;
        };
      in
      {
        devShell = pkgsAllowUnfree.mkShell {
          buildInputs = with pkgsAllowUnfree; [
            poetry
            # env
          ];

          shellHook = ''
            echo abc
          '';
        };
      });
}
WRAP

test -x git || nix profile install nixpkgs#git

git init 
git add .

# Lock it, time passes and things get out of synchronization
nix flake update --override-input nixpkgs nixpkgs/dca55d9a451fba34c87e8adea7a3782d667149fa
nix flake lock

git add .

nix develop --command sh<<COMMANDS
poetry config virtualenvs.in-project true \
&& poetry config virtualenvs.path . \
&& poetry init --no-interaction  \
&& poetry lock \
&& poetry show --tree \
&& poetry add numpy==1.20.1  \
&& poetry lock \
&& poetry show --tree
COMMANDS

git add .

command -v sed 1> /dev/null 2> /dev/null || echo 'The sed binary was not found'
sed -i 's/# env/env/' flake.nix

git add .

nix develop --command python -c 'import numpy as np; np.dot([2j, 3j], [2j, 3j])'

The pandas

Note: IT IS BROKEN

mkdir -p "$HOME"/troubleshoot-pandas-flake \
&& cd "$HOME"/troubleshoot-pandas-flake

cat <<WRAP > "$HOME"/troubleshoot-pandas-flake/flake.nix
{
  description = "A usefull description";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.poetry2nix-src.url = "github:nix-community/poetry2nix/869580c729e658ffe74d8d1d0c3cb132d33a6126";

  outputs = { self, nixpkgs, flake-utils, poetry2nix-src }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgsAllowUnfree = import nixpkgs {
          system = "x86_64-linux";
          config = { allowUnfree = true; };
        };

        pkgs = import nixpkgs { inherit system; overlays = [ poetry2nix-src.overlay ]; };
        env = pkgsAllowUnfree.poetry2nix.mkPoetryEnv {
          poetrylock = ./poetry.lock;
          projectDir = ./.;
          python = pkgsAllowUnfree.python3;
        };
      in
      {
        devShell = pkgsAllowUnfree.mkShell {
          buildInputs = with pkgsAllowUnfree; [
            poetry
            # env
          ];

          shellHook = ''
          '';
        };
      });
}
WRAP

test -x git || nix profile install nixpkgs#git

git init 
git add .

# Lock it, time passes and things get out of synchronization
nix flake update --override-input nixpkgs nixpkgs/dca55d9a451fba34c87e8adea7a3782d667149fa
nix flake lock

git add .

nix develop --command sh<<COMMANDS
poetry config virtualenvs.in-project true \
&& poetry config virtualenvs.path . \
&& poetry init --no-interaction  \
&& poetry lock \
&& poetry show --tree \
&& poetry add pandas==1.5.0  \
&& poetry lock \
&& poetry show --tree
COMMANDS

git add .

command -v sed 1> /dev/null 2> /dev/null || echo 'The sed binary was not found'
sed -i 's/# env/env/' flake.nix

git add .

nix develop --command python -c 'import pandas as pd; pd.DataFrame(); print(pd.__version__)'

Note: IT IS BROKEN


mkdir -p "$HOME"/troubleshoot-pandas-flake \
&& cd "$HOME"/troubleshoot-pandas-flake

curl http://ix.io/49FS > flake.nix
curl http://ix.io/49FQ > flake.lock
curl http://ix.io/49FR > pyproject.toml
curl http://ix.io/49FT > poetry.lock

git init
git add .

nix develop --command python -c 'import pandas as pd; pd.DataFrame(); print(pd.__version__)'

The output of the error:

error: builder for '/nix/store/cwsib0ap5y9miv40qdrk5d6r79pjq1a4-python3.8-numpy-1.23.2.drv' failed with exit code 1;
       last 10 log lines:
       >     - `git clean -xdf` (cleans all files)
       >     - `git clean -Xdf` (cleans all versioned files, doesn't touch
       >                         files that aren't checked into the git repo)
       >
       >   Add `--force` to your command to use it anyway if you must (unsupported).
       >
       >   ----------------------------------------
       >   ERROR: Failed cleaning build dir for numpy
       > Failed to build numpy
       > ERROR: Failed to build one or more wheels
       For full logs, run 'nix log /nix/store/cwsib0ap5y9miv40qdrk5d6r79pjq1a4-python3.8-numpy-1.23.2.drv'.
error: 1 dependencies of derivation '/nix/store/mrz9xr0fkiplmmn47g6jbq9hizqgpgxk-python3-3.8.9-env.drv' failed to build
error: 1 dependencies of derivation '/nix/store/d16a2cwxx3qyyq0fg5mgd20rdkpb1jsc-nix-shell-env.drv' failed to build

Old stuff

It is not so good, IMO, to first have to install things in an nix profile.

mkdir -p "$HOME"/troubleshoot-mmh3-flake \
&& cd "$HOME"/troubleshoot-mmh3-flake

command -v nix 1> /dev/null 2> /dev/null || echo 'The nix binary was not found'
# nix profile install --no-write-lock-file github:nix-community/poetry2nix/869580c729e658ffe74d8d1d0c3cb132d33a6126#poetry
nix profile install --no-write-lock-file nixpkgs/nixos-22.05#poetry
nix profile install nixpkgs#python3

poetry config virtualenvs.in-project true \
&& poetry config virtualenvs.path . \
&& poetry init --no-interaction  \
&& poetry lock \
&& poetry show --tree \
&& poetry add mmh3==3.0.0  \
&& poetry lock \
&& poetry show --tree

# python -c 'import mmh3; print(mmh3.hash128(bytes(123)))'
poetry run python -c 'import mmh3; print(mmh3.hash128(bytes(123)))'

## 

test -x git || nix profile install nixpkgs#git

git init 
git add .

cat <<WRAP > "$HOME"/troubleshoot-mmh3-flake/flake.nix
{
  description = "A usefull description";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.poetry2nix-src.url = "github:nix-community/poetry2nix/869580c729e658ffe74d8d1d0c3cb132d33a6126";

  outputs = { self, nixpkgs, flake-utils, poetry2nix-src }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgsAllowUnfree = import nixpkgs {
          system = "x86_64-linux";
          config = { allowUnfree = true; };
        };

        pkgs = import nixpkgs { inherit system; overlays = [ poetry2nix-src.overlay ]; };
        env = pkgsAllowUnfree.poetry2nix.mkPoetryEnv {
          poetrylock = ./poetry.lock;
          projectDir = ./.;
          python = pkgsAllowUnfree.python3;
        };
      in
      {
        devShell = pkgsAllowUnfree.mkShell {
          buildInputs = with pkgsAllowUnfree; [
            poetry
            env
          ];

          shellHook = ''
            unset SOURCE_DATE_EPOCH
          '';
        };
      });
}
WRAP

git add .

# Lock it, time passes and things get out of synchronization
nix flake update --override-input nixpkgs nixpkgs/dca55d9a451fba34c87e8adea7a3782d667149fa
nix flake lock

nix develop --command python -c 'import mmh3; print(mmh3.hash128(bytes(123)))'
PedroRegisPOAR commented 2 years ago

Whisper and others

ASR state-of-the-art: Wav2Vec, Whisper, DeepSpeech

nix \
shell \
--impure \
--expr \
'
  (
    let 
      pkgs = (builtins.getFlake "github:NixOS/nixpkgs/683f2f5ba2ea54abb633d0b17bc9f7f6dede5799").legacyPackages.${builtins.currentSystem}; 
    in 
      [ (pkgs.python3.withPackages (p: with p; [ gtts ])) pkgs.vlc pkgs.ffmpeg ]
    )
' \
--command \
sh \
<<'COMMANDS'
python3 \
-c \
'
# Import the required module for text
# to speech conversion
from gtts import gTTS

# This module is imported so that we can
# play the converted audio
import os

# The text that you want to convert to audio
mytext = """
I will speak this text
"""

# Language in which you want to convert
language = "en"

# Passing the text and language to the engine,
# here we have marked slow=False. Which tells
# the module that the converted audio should
# have a high speed
myobj = gTTS(text=mytext, lang=language, slow=False)

# Saving the converted audio in a mp3 file named
# welcome
myobj.save("example.mp3")

# Playing the converted file
os.system("cvlc --play-and-exit example.mp3")
'
COMMANDS
nix \
shell \
--impure \
--expr \
'
  (
    let 
      pkgs = (builtins.getFlake "github:NixOS/nixpkgs/683f2f5ba2ea54abb633d0b17bc9f7f6dede5799").legacyPackages.${builtins.currentSystem}; 
    in 
      [ (pkgs.python3.withPackages (p: with p; [ gtts openai-whisper ])) pkgs.vlc pkgs.ffmpeg ]
    )
' \
--command \
sh \
<<'COMMANDS'
python3 \
-c \
'
import whisper
model = whisper.load_model("base")

result = model.transcribe("example.mp3")
print(result["text"])

with open("example.txt", "w") as f:
    f.write(result["text"])
'
COMMANDS

Refs.:

nix \
shell \
--impure \
--expr \
'
  (
    let 
      pkgs = (builtins.getFlake "github:NixOS/nixpkgs/683f2f5ba2ea54abb633d0b17bc9f7f6dede5799").legacyPackages.${builtins.currentSystem}; 
    in 
      [ (pkgs.python3.withPackages (p: with p; [ gtts ])) pkgs.vlc pkgs.ffmpeg ]
    )
' \
--command \
sh \
<<'COMMANDS'
python3 \
-c \
'
# Import the required module for text
# to speech conversion
from gtts import gTTS

# This module is imported so that we can
# play the converted audio
import os

# The text that you want to convert to audio
mytext = """
LEI Nº 14.026, DE 15 DE JULHO DE 2020 

Art. 3º Para fins do disposto nesta Lei, considera-se:

I - saneamento básico: conjunto de serviços públicos, infraestruturas e instalações operacionais de:

a) abastecimento de água potável: constituído pelas atividades e pela disponibilização e 
manutenção de infraestruturas e instalações operacionais necessárias ao abastecimento público de 
água potável, desde a captação até as ligações prediais e seus instrumentos de medição;

b) esgotamento sanitário: constituído pelas atividades e pela disponibilização e manutenção de 
infraestruturas e instalações operacionais necessárias à coleta, ao transporte, ao tratamento 
e à disposição final adequados dos esgotos sanitários, desde as ligações prediais até sua 
destinação final para produção de água de reúso ou seu lançamento de forma adequada no meio ambiente;

c) limpeza urbana e manejo de resíduos sólidos: constituídos pelas atividades e pela disponibilização 
e manutenção de infraestruturas e instalações operacionais de coleta, varrição manual e mecanizada, 
asseio e conservação urbana, transporte, transbordo, tratamento e destinação final ambientalmente 
adequada dos resíduos sólidos domiciliares e dos resíduos de limpeza urbana; e

d) drenagem e manejo das águas pluviais urbanas: constituídos pelas atividades, pela infraestrutura 
e pelas instalações operacionais de drenagem de águas pluviais, transporte, detenção ou retenção 
para o amortecimento de vazões de cheias, tratamento e disposição final das águas pluviais drenadas, 
contempladas a limpeza e a fiscalização preventiva das redes;
"""

# Language in which you want to convert
language = "pt"

# Passing the text and language to the engine,
# here we have marked slow=False. Which tells
# the module that the converted audio should
# have a high speed
myobj = gTTS(text=mytext, lang=language, slow=False)

# Saving the converted audio in a mp3 file named
# welcome
myobj.save("saneamento.mp3")

# Playing the converted file
os.system("cvlc --play-and-exit saneamento.mp3")
'
COMMANDS

Refs.:

Other

PedroRegisPOAR commented 2 years ago

pandas 1.1.5 installed with nix, poetry2nix and poetry 1.1.14

mkdir -p "$HOME"/troubleshoot-pandas-flake \
&& cd "$HOME"/troubleshoot-pandas-flake

curl http://ix.io/4d52 > flake.nix
curl http://ix.io/4d66 > flake.lock
curl http://ix.io/4d69 > pyproject.toml
curl http://ix.io/4d68 > poetry.lock

command -v nix 1> /dev/null 2> /dev/null || echo 'The nix binary was not found'
test -x git || nix profile install nixpkgs#git
git init
git add .

nix develop --command python -c 'import pandas as pd; pd.DataFrame(); print(pd.__version__)'
nix flake update --override-input nixpkgs github:NixOS/nixpkgs/65fae659e31098ca4ac825a6fef26d890aaf3f4e
          shellHook = ''
            # TODO: note que se PYTHONPATH tiver algum valor está sendo ignorado
            # export PYTHONPATH="${pkgsAllowUnfree.python3}/${pkgsAllowUnfree.python3.sitePackages}"
            # https://nixos.wiki/wiki/Python
            export PYTHONPATH="${env}/${pkgsAllowUnfree.python3.sitePackages}"
          '';
python -c 'import pandas as pd; pd.DataFrame(); print(pd.__version__)'
poetry config virtualenvs.in-project true \
&& poetry config virtualenvs.path . \
&& poetry install \
&& . .venv/bin/activate
python -c 'import pandas as pd; pd.DataFrame(); print(pd.__version__)'
poetry run python -c 'import pandas as pd; pd.DataFrame(); print(pd.__version__)'

echo 'source ~/.bashrc' >> ~/.profile

PedroRegisPOAR commented 2 years ago

TODO: https://stackoverflow.com/questions/71755641/why-is-a-statically-linked-hello-world-program-so-big-over-650-kb

https://stackoverflow.com/questions/20534436/how-to-use-alternate-glibc-with-existing-libstdc

mkdir -p "$HOME"/test-ok \
&& cd "$HOME"/test-ok

cat <<'EOF1' > flake.nix
{
  description = "";

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

  outputs =
    inputs@{ self
    , nixpkgs
    , flake-utils
    }:
    let
      name = "test-ok";
      system = "x86_64-linux";

      pkgsAllowUnfree = import nixpkgs {
        inherit system;
        config = { allowUnfree = true; };
      };

      packages_ = (import ./default.nix { pkgs = pkgsAllowUnfree; });
    in
    {

      packages."${system}" = packages_;

      apps."${system}".ok = flake-utils.lib.mkApp {
        name = "ok";
        drv = self.packages."${system}".ok;
      };

      devShells."${system}".default = pkgsAllowUnfree.mkShell {
        buildInputs = with pkgsAllowUnfree; [
          hello
          curl
          gnumake
        ];

        shellHook = ''
          export TMPDIR=/tmp
        '';
      };
    };
}
EOF1

cat <<'EOF2' > flake.lock
{
  "nodes": {
    "flake-utils": {
      "locked": {
        "lastModified": 1659877975,
        "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
        "owner": "numtide",
        "repo": "flake-utils",
        "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "flake-utils",
        "type": "github"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1665732960,
        "narHash": "sha256-WBZ+uSHKFyjvd0w4inbm0cNExYTn8lpYFcHEes8tmec=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "4428e23312933a196724da2df7ab78eb5e67a88e",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixos-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "flake-utils": "flake-utils",
        "nixpkgs": "nixpkgs"
      }
    }
  },
  "root": "root",
  "version": 7
}
EOF2

cat <<'EOF3' > default.nix
{ pkgs ? import <nixpkgs> {} }: {

  ok = pkgs.callPackage ./ok.nix { };

}
EOF3

cat <<'EOF4' > ok.cpp
#include <iostream>
int main()
{
    std::cout << "ok\n";
    return 0;
}
EOF4

cat <<'EOF5' > ok.cpp
#include <iostream>
int main()
{
    std::cout << "ok\n";
    return 0;
}
EOF5

cat <<'EOF6' > ok.nix
{ pkgs ? import <nixpkgs> { }}:
pkgs.stdenv.mkDerivation {
  name = "ok";
  src = builtins.path { path = ./.; name = "ok"; };
  phases = [ "installPhase" "postInstallPhase" ];

  buildInputs = [ pkgs.makeWrapper ];

  unpackPhase = ":";

  installPhase = ''
    mkdir -p $out/bin
    g++ -o $out/bin/ok $src/ok.cpp
  '';

  postInstallPhase = ''
    wrapProgram $out/bin/ok --prefix LD_LIBRARY_PATH : ${pkgs.stdenv.cc.cc.lib}/lib
  '';

}
EOF6

command -v nix 1> /dev/null 2> /dev/null || echo 'The nix binary was not found'
test -x git || nix profile install nixpkgs#git

git init 
git add .
nix run .#ok
PedroRegisPOAR commented 2 years ago

Main refs.:

mkdir -p "$HOME"/troubleshoting-pytest-runner \
&& cd "$HOME"/troubleshoting-pytest-runner

cat <<'EOF' > flake.nix
{
  description = "";

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

  outputs =
    inputs@{ self
    , nixpkgs
    , flake-utils
    }:
    let
      name = "troubleshoting-pytest-runner";
      system = "x86_64-linux";

      pkgsAllowUnfree = import nixpkgs {
        inherit system;
        config = { allowUnfree = true; };
      };

      env = pkgsAllowUnfree.poetry2nix.mkPoetryEnv {
        poetrylock = ./poetry.lock;
        projectDir = ./.;
        python = pkgsAllowUnfree.python3;

        overrides = [
          poetry2nix.defaultPoetryOverrides
          (self: super: {
            faker = super.faker.overridePythonAttrs(old: {
              buildInputs = old.buildInputs ++ [
                self.pytestrunner
              ];
            });
            })
          ];
      };
    in
    {

      devShells."${system}".default = pkgsAllowUnfree.mkShell {
        buildInputs = with pkgsAllowUnfree; [
          hello
          curl
          gnumake
          env
        ];

        shellHook = ''
          echo "In nix shell"
        '';
      };
    };
}
EOF
git init 
git add .
nix develop .#
PedroRegisPOAR commented 1 year ago

https://lazamar.co.uk/nix-versions/

export NIXPKGS_ALLOW_INSECURE=1 \
&& nix \
shell \
--ignore-environment \
--impure \
--override-flake \
nixpkgs \
github:NixOS/nixpkgs/ae2fc9e0e42caaf3f068c1bfdc11c71734125e06 \
nixpkgs#pkgsStatic.busybox-sandbox-shell \
nixpkgs#python \
github:NixOS/nixpkgs/fefb0df7d2ab2e1cabde7312238026dcdc972441#python36 \
github:NixOS/nixpkgs/fefb0df7d2ab2e1cabde7312238026dcdc972441#python37 \
github:NixOS/nixpkgs/fefb0df7d2ab2e1cabde7312238026dcdc972441#python38 \
nixpkgs#python39 \
nixpkgs#python310 \
nixpkgs#python311 \
nixpkgs#python312 \
nixpkgs#python313 \
--command \
sh \
-c \
'
python2 --version \
&& python3.6 --version  \
&& python3.7 --version  \
&& python3.8 --version  \
&& python3.9 --version  \
&& python3.10 --version \
&& python3.11 --version \
&& python3.12 --version \
&& python3.13 --version
'
nix \
shell \
--impure \
--expr \
'
  (
      let
        nixpkgs = (builtins.getFlake "github:NixOS/nixpkgs/ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b");
        pkgs = import nixpkgs { };    
      in
        with pkgs; [ 
          pkgsStatic.busybox-sandbox-shell
          (python3.withPackages (pyPkgs: with pyPkgs; [
                                         beautifulsoup4 
                                         jupyter 
                                         matplotlib
                                         pandas 
                                         requests 
                                         lxml
                                     ]
                          )
                        )
    ]
  )
' \
--command \
sh \
-c \
'jupyter-notebook'

https://mayeut.github.io/manylinux-timeline/ https://pythonwheels.com/

nix \
shell \
--ignore-environment \
--keep HOME \
--keep USER \
--impure \
--expr \
'
  (
      let
        nixpkgs = (builtins.getFlake "github:NixOS/nixpkgs/ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b");
        pkgs = import nixpkgs { };    
      in
        with pkgs; [ 
          bashInteractive
          coreutils

          # Solvers
          ipopt
          bonmin
          z3
          opensmt
          nlopt
          CoinMP
          cbc
          clp
          glpk
          picosat
          csdp
          ecos

          julia-bin

          # cplex # Not in nixpkgs cache due to license?
          # gurobi # Not in nixpkgs cache due to license?

          (python3.withPackages (pyPkgs: with pyPkgs; [
                                         beautifulsoup4 
                                         jupyter 
                                         matplotlib
                                         pandas 
                                         requests 
                                         lxml

                                         rdkit # https://www.youtube.com/watch?v=9Z9XM9xamDU

                                         nix-kernel
                                         bash_kernel

                                         pyomo
                                         z3
                                         pycosat
                                         ecos
                                         # daqp
                                         # gurobipy # Not in nixpkgs cache due to license?
                                     ]
                          )
                        )
    ]
  )
' \
--command \
bash \
-c \
'jupyter-notebook'

Refs.: