NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.51k stars 13.69k forks source link

`quarto` can't build mixed Python and R documents due to `rPackages.reticulate` not finding the Python interpreter #244575

Open bcdarwin opened 1 year ago

bcdarwin commented 1 year ago

Describe the bug

See title.

Steps To Reproduce

git add the following flake.nix to a fresh git repo and run nix build.

{
  description = "Demonstration of `reticulate` being broken unable to find Python interpreter in Quarto";

  outputs = { self, nixpkgs }:
    let pkgs = nixpkgs.legacyPackages.x86_64-linux; in rec {
      packages.x86_64-linux.default = pkgs.stdenv.mkDerivation rec {
        pname = "mixed-python-and-R-quarto-documents-broken";
        version = "0.0.1";

        working = pkgs.writeText "working.qmd"
          ''
          ```{python}
          import numpy as np
      '';

    alsoWorking = pkgs.writeText "also-working.qmd"
      ''
      ```{r}
      2 + 2
      ```
      '';

    broken = pkgs.writeText "broken.qmd"
      ''
      ```{python}
      import numpy as np
      ```
      ```{r}
      2 + 2
      ```
      '';

    src = pkgs.hello;

    buildInputs = with pkgs; [
      (quarto.override {
         extraRPackages = with pkgs.rPackages; [ reticulate ];
         extraPythonPackages = ps: with ps; [ numpy ];
       })
    ];
    preBuild = ''export HOME=$(mktemp -d)'';
    buildPhase = ''
      runHook preBuild
      quarto render ${working} --to html -o working.html
      quarto render ${alsoWorking} --to html -o also-working.html
      quarto render ${broken} --to html -o broken.html
      runHook postBuild
    '';

    installPhase = ''
      runHook preInstall
      mkdir $out
      cp *html $out
      runHook postInstall
    '';
  };
};

}


### Expected behavior
A clear and concise description of what you expected to happen.

### Screenshots
If applicable, add screenshots to help explain your problem.

### Additional context
Add any other context about the problem here.

### Notify maintainers

<!--
Please @ people who are in the `meta.maintainers` list of the offending package or module.
If in doubt, check `git blame` for whoever last touched something.
-->

### Metadata
Please run `nix-shell -p nix-info --run "nix-info -m"` and paste the result.

```console
[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
output here
nixos-discourse commented 5 months ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/calling-python-via-reticulate-in-an-r-markdown-document/43557/2