• GeneralARTIQ
  • How can I add my own python packages to the artiq nix file

Hi,

I have searched the internet about this issue but had no luck so far. Only useful hint that I found is to create a venv, but I thought this might be possible more straight forward.

Essentially I adopted the shell-dev.nix file from the artiq-fast repo for my nix shell and I want to add the pyDigitalWaveTools package to this shell.

Where do I put "pyDigitalWaveTools" in the file?


# main nix package manager
{ pkgs ? import <nixpkgs> {}}:

let
    artiqpkgs = import ./artiq.nix { inherit pkgs; };
    vivado = import ./vivado.nix { inherit pkgs; };
in    
    pkgs.mkShell {  
    buildInputs = [
        vivado     
        pkgs.gnumake        
        (pkgs.python3.withPackages(
            pyDigitalWaveTools <-- doesnt work syntax error
            ps: (
                with ps; [ 
                    # add your own python packages here
                    jinja2 
                    jsonschema 
                    numpy 
                    paramiko                  
                    pyDigitalWaveTools <-- doesnt work, it says unknown variable                      
                ]) 
                ++ (
                # python artiq packages
                with artiqpkgs; [ 
                    migen 
                    microscope 
                    misoc 
                    jesd204b 
                    migen-axi 
                    artiq 
                ])
            )
        )
        # non-python artiq packages, from above import
        artiqpkgs.cargo
        artiqpkgs.rustc
        artiqpkgs.binutils-or1k
        artiqpkgs.binutils-arm
        artiqpkgs.llvm-or1k
        artiqpkgs.openocd 
    ];
    # target architecture
    TARGET_AR="or1k-linux-ar";
  }

Thanks,
Jonas

    jonasmanthey pyDigitalWaveTools <-- doesnt work, it says unknown variable

    That's the correct syntax, but pyDigitalWaveTools isn't in nixpkgs.

    You can package it with something like:

    let
        artiqpkgs = import ./artiq.nix { inherit pkgs; };
        vivado = import ./vivado.nix { inherit pkgs; };
        pyDigitalWaveTools = pkgs.python3Packages.buildPythonPackage rec {
          pname = "pyDigitalWaveTools";
          version = "...";
    
          src = pkgs.python3Packages.fetchPypi {
            inherit pname version;
            sha256 = "..."
          };
    
          buildInputs = [ ... ];
          propagatedBuildInputs =  [ ... ];
    
         ...
      };
    in    
        pkgs.mkShell {  
    ...

    Thanks, in principle it worked even though retrieving the SHA256 hash somehow was weird, nix-prefetch-url --unpack showed a different hash than what was expected. The PyPi hash is base-16 I think.

    However I could just use the hash that was printed when starting the shell.

    In the end it failed because a test file missing from the tarball so the unit tests fail. So now it is package problem. I will post again with my final .nix file when this is resolved.

    The PyPi hash is base-16 I think.

    Isn't the SHA256 hash available in the source downloads section in PyPI what you're looking for?

    so the unit tests fail

    If wanted, you can skip the unit tests with doCheck = false; in the rec set.

      airwoodix Isn't the SHA256 hash available in the source downloads section in PyPI what you're looking for?

      Yeah but it seems nix is expecting the hash to be in ASCII (?) whereas PyPI shows it in hexadecimal.

      nix: 055q48zsc5g9kcar5r3n9jwqq68djb96vr95rxsgsnfnr7dz7c5l
      PyPI: c7f0e06f7ed543a2f5f7110a4a8f2aae9e3ae328bb67ebd5b2a6db862efe7d33

      airwoodix If wanted, you can skip the unit tests with doCheck = false; in the rec set.

      Ah that's what I was looking for. Luckily the author of the package already released a new version where the issue is fixed.

      Yeah but it seems nix is expecting the hash to be in ASCII (?) whereas PyPI shows it in hexadecimal.

      This works for me (nix 2.3.10):

      with import <nixpkgs> {};
      
      let
        pyDigitalWaveTools = python3Packages.buildPythonPackage rec {
          pname = "pyDigitalWaveTools";
          version = "1.1";
      
          src = python3Packages.fetchPypi {
            inherit pname version;
            sha256 = "c7f0e06f7ed543a2f5f7110a4a8f2aae9e3ae328bb67ebd5b2a6db862efe7d33";
          };
      
        };
      in
      mkShell {
        buildInputs = [
          (python3.withPackages(ps:
            [ pyDigitalWaveTools ]
          ))
        ];
      }