Difference between revisions of "Raku"

From NixOS Wiki
Jump to: navigation, search
(+Examples for Raku Nix shells, extolled for instances here https://irclogs.raku.org/raku-beginner/2025-02-16.html)
(+instructions to resolve "cannot find readline library" error)
Line 5: Line 5:
 
''Rakudo'' is the preferred implementation of Raku, and the ''zef'' the preferred module manager. Install them in a nix shell via
 
''Rakudo'' is the preferred implementation of Raku, and the ''zef'' the preferred module manager. Install them in a nix shell via
  
<syntaxHighlight lang=shell>
+
<syntaxhighlight lang="shell">
 
nix-shell -p rakudo zef
 
nix-shell -p rakudo zef
</syntaxHighlight>
+
</syntaxhighlight>
  
 
or install them permanently system-wide by adding <code>pkgs.rakudo</code> and <code>pkgs.zef</code> to your NixOS configuration file.
 
or install them permanently system-wide by adding <code>pkgs.rakudo</code> and <code>pkgs.zef</code> to your NixOS configuration file.
Line 13: Line 13:
 
To create a Nix user environment on NixOS, run
 
To create a Nix user environment on NixOS, run
  
<syntaxHighlight lang=shell>
+
<syntaxhighlight lang="shell">
 
nix-env -iA nixos.rakudo
 
nix-env -iA nixos.rakudo
</syntaxHighlight>
+
</syntaxhighlight>
  
 
(For environments or flakes on non-NixOS machines, different recommendations apply.<ref name="nixos-package-index">See https://search.nixos.org/packages?channel=25.05&show=rakudo&query=raku under the tab ''nix-env''</ref>)
 
(For environments or flakes on non-NixOS machines, different recommendations apply.<ref name="nixos-package-index">See https://search.nixos.org/packages?channel=25.05&show=rakudo&query=raku under the tab ''nix-env''</ref>)
Line 25: Line 25:
 
When opening an interactive environment (by running <code>rakudo</code>, or its symlink <code>raku</code>, without arguments), you may get an error message like this:
 
When opening an interactive environment (by running <code>rakudo</code>, or its symlink <code>raku</code>, without arguments), you may get an error message like this:
  
<syntaxHighlight>
+
<syntaxhighlight>
 
I ran into a problem while trying to set up Readline: Could not instantiate role 'ReadlineBehavior'; exception details:
 
I ran into a problem while trying to set up Readline: Could not instantiate role 'ReadlineBehavior'; exception details:
 
 
   Cannot locate native library 'libreadline.so.7': libreadline.so.7: cannot open shared object file: No such file or directory
 
   Cannot locate native library 'libreadline.so.7': libreadline.so.7: cannot open shared object file: No such file or directory
 
   in method setup at [...]
 
   in method setup at [...]
 
 
Falling back to Linenoise (if present)
 
Falling back to Linenoise (if present)
 
No line editor found.
 
No line editor found.
Line 37: Line 35:
 
Linenoise`, or `zef install Terminal::LineEditor` or install `rlwrap`
 
Linenoise`, or `zef install Terminal::LineEditor` or install `rlwrap`
 
for a line editor before entering the REPL again.
 
for a line editor before entering the REPL again.
</syntaxHighlight>
+
</syntaxhighlight>
 +
 
 +
And indeed, Readline won't work and editing will feel weirdly. To fix this, append or prepend the location of the Readline library to the environment variable <code>$LD_LIBRARY_PATH</code>. This can be done by adding the following to your NixOS configuration:
 +
 
 +
<syntaxhighlight lang="nix">
 +
{
 +
  #...
 +
  environment.sessionVariables = rec {
 +
    LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
 +
      pkgs.readline70
 +
    ];
 +
  };
 +
  #...
 +
}
 +
</syntaxhighlight>
  
And indeed, keyboard commands like <code>Arrow-up</code> to go through history will not work.
+
For Nix shells, see for instance [https://github.com/rcmlz/Raku-Nix-Shells/blob/main/raku_dev.nix this example].
  
 
== Resources ==
 
== Resources ==
  
* Examples for Raku Nix Shells: https://github.com/rcmlz/Raku-Nix-Shells
+
* Various examples for Raku Nix Shells: https://github.com/rcmlz/Raku-Nix-Shells
  
 
== References ==
 
== References ==

Revision as of 11:23, 28 September 2025

Warning: This article is in a very early stage.

Installing Rakudo and Zef

Rakudo is the preferred implementation of Raku, and the zef the preferred module manager. Install them in a nix shell via

nix-shell -p rakudo zef

or install them permanently system-wide by adding pkgs.rakudo and pkgs.zef to your NixOS configuration file.

To create a Nix user environment on NixOS, run

nix-env -iA nixos.rakudo

(For environments or flakes on non-NixOS machines, different recommendations apply.[1])

No Nix packages currently exist for the Rakudo Star distribution, which bundles Rakudo with a collection of modules the language documentation. Thus, to use it, you need to download and compile it.[2] This way, you'll also always get the latest Rakudo version.

Making the Readline library available

When opening an interactive environment (by running rakudo, or its symlink raku, without arguments), you may get an error message like this:

I ran into a problem while trying to set up Readline: Could not instantiate role 'ReadlineBehavior'; exception details:
  Cannot locate native library 'libreadline.so.7': libreadline.so.7: cannot open shared object file: No such file or directory
  in method setup at [...]
Falling back to Linenoise (if present)
No line editor found.

You may want to exit first and `zef install Readline`, `zef install
Linenoise`, or `zef install Terminal::LineEditor` or install `rlwrap`
for a line editor before entering the REPL again.

And indeed, Readline won't work and editing will feel weirdly. To fix this, append or prepend the location of the Readline library to the environment variable $LD_LIBRARY_PATH. This can be done by adding the following to your NixOS configuration:

{
  #...
  environment.sessionVariables = rec {
    LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ 
      pkgs.readline70
    ];
  };
  #...
}

For Nix shells, see for instance this example.

Resources

References