Search code examples
nixnix-flake

Why do I get " PermissionError: [Errno 13] Permission denied: '/homeless-shelter'Q when installing 'jina-hubble-sdk' with Nix Flake


To build a my virtual environment with a nix flake, I have to add some python packages that are not in the nix package manager. I have a problem installing "jina-hubble-sdk"

I run

nix develop

in the directory containing flake.nix that looks like that:

{  description = "Python environment with ollama";

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

 outputs = { self, nixpkgs, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system: let
      pkgs = nixpkgs.legacyPackages.${system};
      
      # Define Python package jina-hubble-sdk
      jina-hubble-sdk = with pkgs.python3Packages;
        buildPythonPackage rec {
          pname = "jina-hubble-sdk";
          version = "0.39.0";

          src = pkgs.fetchPypi {
            inherit pname version;
            sha256 = "9021417794a6d3cf3fad8a880cf668a3a986b9d53d5be5fa391aae1767a5b9b0";
          };

          nativeBuildInputs = [
          ];

          propagatedBuildInputs = [
            pip
            requests
            aiohttp
            rich
            importlib-metadata
            filelock
            pathspec
            docker
            pyyaml
            python-jose
          ];
        };
   
      # Define Python environment with necessary packages
      pythonEnv = pkgs:
        pkgs.python3.withPackages (ps:
          with ps; [
             jina-hubble-sdk # Include jina in the environment
          ]);
    in {
      devShells.default = pkgs.mkShell {
        buildInputs = with pkgs; [
          curl
          (pythonEnv pkgs)
        ];
      };
    }); }

and I get the following error message:

error: builder for '/nix/store/d4ncmq68cjksfzdhz2klsrr1wm5jm9aj-python3.11-jina-hubble-sdk-0.39.0.drv' failed with exit code 1; last 10 log lines: > os.mkdir(self, mode) > PermissionError: [Errno 13] Permission denied: '/homeless-shelter' > > > ---------------------------------------------------------------------- > Ran 1 test in 0.002s > > FAILED (errors=1) > Test failed: <unittest.runner.TextTestResult run=1 errors=1 failures=0> > error: Test failed: <unittest.runner.TextTestResult run=1 errors=1 failures=0> For full logs, run 'nix-store -l /nix/store/d4ncmq68cjksfzdhz2klsrr1wm5jm9aj-python3.11-jina-hubble-sdk-0.39.0.drv'. error: 1 dependencies of derivation '/nix/store/5p0ffk9xjmb3zx73d1gzab0pjngmasbh-python3-3.11.8-env.drv' failed to build error: 1 dependencies of derivation '/nix/store/g9qd2rvp2fkbz47mzbjnqzlfnkk6hvjm-nix-shell-env.drv' failed to build

It come from jina-hubble-sdk-0.39.0.drv. I read this message that speak about a problem similar and speak about HOME and TMPDIR. Thefore I give you their value in a similar environment that the environment I want to create.

$HOME

bash: /home/nixos: Is a directory

$TMPDIR

bash: /tmp/nix-shell.QHZzjA: Is a directory


Solution

  • As highlighted in Charles Duffy's comments, adjusting the $HOME variable is required within the build process, not in your environment.

    In nixpkgs when a package build needs a writable home, we usually use export HOME=$(mktemp -d). To avoid conflicting with the pre-configured buildPhase for Python packages, you should export your variable in the preBuild phase:

    src = { ... };
    
    preBuild = ''
      export HOME=$(mktemp -d)
    '';
    
    nativeBuildInputs = [ ... ];