Integration of setup.py and bash shell script

I’m trying to integrate this package into my current project by following the shell script examples in my flake.nix file (the shell script has to run first to install the SDK before setup.py can be run). However, I keep getting into errors (generated by the shell script) as shown:

error: builder for '/nix/store/vwnw5l4p7b45wyqyrmm22043iixkjzx2-PyVCAM-sdk.drv' failed with exit code 127;
       last 3 log lines:
       > This OS doesn't seem to be Debian-based
       > /nix/store/xvagqjd5pbpv9zfwghwhi0sqpgdkwh5z-pvcam-sdk__install_helper-Ubuntu.sh: line 14: ls: command not found
       > /nix/store/xvagqjd5pbpv9zfwghwhi0sqpgdkwh5z-pvcam-sdk__install_helper-Ubuntu.sh: line 14: tail: command not found
       For full logs, run 'nix log /nix/store/vwnw5l4p7b45wyqyrmm22043iixkjzx2-PyVCAM-sdk.drv'.
error: 1 dependencies of derivation '/nix/store/2jh6lix6wsbv6d4pglzfw0qmly8q0ax1-python3.10-PyVCAM-0.0.1.drv' failed to build
error: 1 dependencies of derivation '/nix/store/9j6nh42nr3rijwjpdb04ajagjzqyvq4l-python3-3.10.9-env.drv' failed to build
error: 1 dependencies of derivation '/nix/store/j5d67azpgh3119whh3l2mvd99z8v66ky-PyVCAM-dev-shell-env.drv' failed to build

The following is a sample of my flake.nix file (I’ve tried commenting and uncommenting pieces to see what would work, but they’re running into the same issue)

{
  description = "Development environment for PyVCAM package.";

  outputs = { self, nixpkgs }:
    let
      pkgs = import nixpkgs { system = "x86_64-linux"; };
      # PyVCAM-sdk = ( with pkgs; stdenv.mkDerivation rec {
      #   name = "PyVCAM-sdk";
      #   # disable unpackPhase etc
      #   phases = "buildPhase";
      #   # builder = ./builder.sh;
      #   builder = pvcam-sdk/pvcam-sdk__install_helper-Ubuntu.sh;
      #   nativeBuildInputs = (with python3Packages; [ numpy bash ]);
      #   PATH = lib.makeBinPath nativeBuildInputs;
      #   # only strings can be passed to builder
      #   # someString = "hello";
      #   # someNumber = builtins.toString 42;
      #   # someJson = builtins.toJSON { dst = "world"; };
      # });

      # or another alternative:

      PyVCAM-sdk = (with pkgs; runCommand "PyVCAM-sdk" {
        # nativeBuildInputs = [ coreutils jq ];
        # only strings can be passed to builder
        # someString = "hello";
        # someNumber = builtins.toString 42;
        # someJson = builtins.toJSON { dst = "world"; };
      } (builtins.readFile pvcam-sdk/pvcam-sdk__install_helper-Ubuntu.sh));

      PyVCAM = (with pkgs; python3Packages.buildPythonApplication rec {
        pname = "PyVCAM";
        version = "0.0.1"; # TODO: single-source version
        src = ./.;
        buildInputs = (
          (with python3Packages; [ setuptools ]) ++ [ bash PyVCAM-sdk ]);
        propagatedBuildInputs = (with python3Packages; [ importlib-resources numpy ]);
        # checkInputs = (with python3Packages; [ pytest ]);
        # doCheck = true;
        # format = "pyproject";
        meta = with lib; {
          description = "PyVCAM";
          # maintainers = [ "my name" ];
          # homepage = "github url";
          license = "TODO"; # TODO
        };
      });
    in
    rec {
      packages.x86_64-linux = {
        inherit PyVCAM;
        default = pkgs.python3.withPackages (ps: [ PyVCAM ]);
      };
      # default shell for 'nix develop'
      devShells.x86_64-linux.default = pkgs.mkShell {
        name = "PyVCAM-dev-shell";
        buildInputs = [
          # Python packages
          (pkgs.python3.withPackages (ps: [
            PyVCAM
            PyVCAM.buildInputs
            PyVCAM.propagatedBuildInputs
            # testing
            ps.pytest
            ps.numpy

            # formatting/linting
            # ps.autopep8
            # ps.flake8
          ]))
          # non-Python packages
        ];
      };
      formatter.x86_64-linux = pkgs.nixpkgs-fmt;
    };
}

Is the source of __install_helper-Ubuntu.sh available?

I have also copied my entire flake.nix file for better context.

NixOS uses nix, not apt (Debian’s package manager). That line checks if apt is installed and then exits with an error if it’s not, which will always be the case on NixOS.

This script is completely incompatible with NixOS, there’s no way to work around it.

You’ll need to read it, understand what it does, and reimplement it without using apt or dpkg.

That said, all it seems to do is install some dependencies, and call a script found using ls -1v pvcam-sdk_?*.?*.?*.?*.run | tail -n1. If you find that script and run it instead of this install helper you can basically skip it; assuming you can find the dependencies and manually add them to buildInputs.

Those are nasty… Those can itself be shell scripts (with a broken shebang), statically linked binaries or dynamically linked (with “broken” interpreter).

And they may even be some selfextracting garbage which again run other stuff incompatible with nixos…

This doesn’t sound easy.

1 Like