Development environments with Nix

Similar to detailed in Python - NixOS Wiki

Using the Nixpkgs Python infrastructure via shell.nix (recommended)

I would like to set up a development environment for rakudo with additional packages zef rlwrap gnuplot.

Downloads - Rakudo Compiler for Raku Programming Language suggest nix-env -iA nixos.rakudo. I would prefer a shell.nix setup, though, as recommended for python.

As I am fairly new, I would like to ask for help.

With what exactly?

What have you tried so far, what is the error you get, or what is not working as expected?

In most cases just dumping whatever you need into mkShells packages list is totally sufficient.

I am not sure how to modify the python example i.e. which tarball to fetch for a start.

# shell.nix
let
  # We pin to a specific nixpkgs commit for reproducibility.
  # Last updated: 2024-04-29. Check for new commits at https://status.nixos.org.
  pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/cf8cc1201be8bc71b7cbbbdaf349b22f4f99c7ae.tar.gz") {};
in pkgs.mkShell {
  packages = [
    (pkgs.python3.withPackages (python-pkgs: with python-pkgs; [
      # select Python packages here
      pandas
      requests
    ]))
  ];
}

Do you actually need to pin nixpkgs? Or is just using <nixpkgs> sufficient?

If pinning is indeed important to you, I expect you to know what commit you want to pin to.

1 Like
# shell.nix
pkgs.mkShell {
  packages = [
    (pkgs.rakudo.withPackages (rakudo-pkgs: with rakudo-pkgs; [
      zef
      rlwrap
      gnuplot
    ]))
  ];
}

This is a rakudo adaption of the recommended python version from above. It fails with:

[user@nixos:~]$ nix-shell raku-shell.nix
error: undefined variable 'pkgs'
       at /home/user/raku-shell.nix:2:1:
            1| # shell.nix
            2| pkgs.mkShell {
             | ^
            3|   packages = [

You have to define pkgs somehow. You can not just leave away the let/in.

let
  pkgs = import <nixpkgs> {};
in
  pkgs.mkShell {
    packages = [
      pkgs.rakudo
      pkgs.zef
      pkgs.rlwrap
      pkgs.gnuplot
    ];
  }

This built succesfully for me.

rakudo doesn’t seem to have a withPackages, and also all the attributes are toplevel anyway and not some rakudo packages.

1 Like

Yes, it works. I bought you a coffee.

As described here GitHub · Where software is built zef install Chart::Gnuplot falls over and I do not know how to expedite fixing it, as it is supposed to work in Ubuntu.

I just took a look, and it seems as if the Chart::Gnuplot package has native dependencies, and a really messy/stupid config phase… It spits out errors and warnings about missing libs, and instead of giving you a reasonable output about those, it just starts to compile and fails.

Also I see it seems to require qt components. Those are sometimes a bit messy to deal with.

I am not sure if I am able to help from here on.

1 Like

If you run

zef install --debug Chart::Gnuplot

you see that Chart::Gnuplot is installing Gnuplot (and even a very specific version) “manually” in a “traditional” way with some options in a “custom” path.

chdir("gnuplot-5.2.6");
shell("./configure --prefix=$prefix --with-latex --with-texdir={$prefix}/share/texmf/tex/latex/gnuplot");
shell("make");
shell("make install");

and later uses in line 48 of https://github.com/titsuki/raku-Chart-Gnuplot/blob/490a4b7a15975742a0438d66de3753879836b2d8/lib/Chart/Gnuplot.pm6

my $prefix = "$HOME/.p6chart-gnuplot";
$gnuplot = "$prefix/bin/gnuplot";

That is probably not what you want - especially not on Nix.

So, if you need that package in Raku, one way to make it work would be to

  • fetch the repo (fetchFromGithub)
  • patch META6.json and remove Chart::Gnuplot::CustomBuilder
  • patch Gnuplot.pm6 on line 46 and set gnuplot executable
  • and then run zef install --debug --/build . from the patched repo

I was playing around a bit and arrived that “work in progress” here:

Maybe it helps. Maybe you encourage the owner of Chart::Gnuplot to improve on the build process of the library to make it more generic and stable and rely perhaps on the system-installed gnuplot - if that is avialable.

Good luck.

1 Like
===> Extracting: Chart::Gnuplot
[Chart::Gnuplot] Command: tar -zt -f ./Chart%3A%3AGnuplot%3Aver%3C0.0.21%3E%3Aauth%3Ccpan%3ATITSUKI%3E.tar.gz
[Chart::Gnuplot] Extracting with plugin: Zef::Service::Shell::tar
[Chart::Gnuplot] Command: tar -zxvf ./Chart%3A%3AGnuplot%3Aver%3C0.0.21%3E%3Aauth%3Ccpan%3ATITSUKI%3E.tar.gz -C ../Chart%3A%3AGnuplot%3Aver%3C0.0.21%3E%3Aauth%3Ccpan%3ATITSUKI%3E.tar.gz
===> Extraction [OK]: Chart::Gnuplot to /tmp/nix-shell-3471-0/.zef.1755445905.4258/Chart%3A%3AGnuplot%3Aver%3C0.0.21%3E%3Aauth%3Ccpan%3ATITSUKI%3E.tar.gz
===> Filtering: Chart::Gnuplot:ver<0.0.21>
===> Filtering [OK] for Chart::Gnuplot:ver<0.0.21>
===> Staging Chart::Gnuplot:ver<0.0.21>
===SORRY!=== Error while compiling /home/th6mas/home#sources/4174EAB6BD2C66DF2A17784F6762B929977CAE73 (Chart::Gnuplot::CustomBuilder)
Could not find Zef in:
    /tmp/nix-shell-3471-0/.zef.1755445905.4258/1755445914.4258.8405.301831814433
    /home/th6mas/.raku
    /nix/store/askcsz9flbapplghdf7zhzd7ngfgbcvq-rakudo-2025.04/share/perl6/site
    /nix/store/askcsz9flbapplghdf7zhzd7ngfgbcvq-rakudo-2025.04/share/perl6/vendor
    /nix/store/askcsz9flbapplghdf7zhzd7ngfgbcvq-rakudo-2025.04/share/perl6/core
    CompUnit::Repository::AbsolutePath<4014057444264>
    CompUnit::Repository::NQP<4013960397000>
    CompUnit::Repository::Perl5<4013960397040>
at /home/th6mas/home#sources/4174EAB6BD2C66DF2A17784F6762B929977CAE73 (Chart::Gnuplot::CustomBuilder):7

is expected. The developer responds on github. I do not have the knowledge (yet) to make it work.

I am afraid this problem Could not find Zef in is most likely on Nix side.

My guess is that the install process run by Chart::Gnuplot in Raku is creating new Shells, and that new Shells do not know how to find zef.

Maybe you could try one of the two ways

a.) not-so-nix-like-I-guess

  • install rakudo/zef globally (configuration.nix), before Chart::Gnuplot
  • make “PATH = $HOME/.raku/bin:$PATH” also a global configuration

OR

b.) I-do-not-know-how-to-do-that

  • find out how to make sure that subsequently created shells during installation inherit PATH and packages etc.

For b.) I tried

buildInputs = buildEnvPackages;
propagatedBuildInputs = buildEnvPackages;

but that apparently did not work.

I am also a beginner in Nix. Maybe someone with more experience or ChatGPT & Co. can help with b.)?

However, I guess that improving the CustomBuilder.pm6 module itself - maybe re-considering the hard-coded approach of installing gnuplot - even when it is already installed on the sytem - would benefit the module in general. And finaly maybe setting up a github action to validate, if the module can be installed on Linux/Mac/Windows and Nix, would help potential users of Chart::Gnuplot.

1 Like