Stream: beginners

Topic: Setting up a Roc playground on repl.it


view this post on Zulip Peter Marreck (Sep 30 2024 at 14:40):

So repl.it environments are controlled by a replit.nix file. I'd like to know what to put in there to have a Roc playground I can use from all my computers. I also think this would be useful for others to get up to speed quickly. I took a stab at it (see this gist: https://gist.github.com/pmarreck/b3de701b61ae44720cbbb65dcaf65885) but no dice yet... I know Roc is nix-friendly so I'm sure someone could probably make this work pretty easily...

view this post on Zulip Anton (Sep 30 2024 at 15:00):

I'm not very familiar with replit but the premise sounds cool! Are you currently getting any errors using the gist?

view this post on Zulip Peter Marreck (Sep 30 2024 at 16:24):

nix error: building nix env: exit status 1
Output has been trimmed to the last 20 lines
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'nix-shell'
         whose name attribute is located at /nix/store/pp028rj4l81sm4bs36l9mx80602m8kq4-nixpkgs-24.05-src/pkgs/stdenv/generic/make-derivation.nix:331:7

       … while evaluating attribute 'REPLIT_LD_LIBRARY_PATH' of derivation 'nix-shell'

         at «string»:309:9:

          308|       {
          309|         REPLIT_LD_LIBRARY_PATH = (pkgs.lib.optionalString (env ? REPLIT_LD_LIBRARY_PATH) (env.REPLIT_LD_LIBRARY_PATH + ":")) +
             |         ^
          310|         pkgs.lib.makeLibraryPath deps;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: invalid SRI hash '11yw9xh1719smxbp0ia03kkv6hrvw4l6hhvxjxa4w2i7wc2r6yqy'

path '/home/runner/roc-playground' does not contain a 'flake.nix', searching up
error: unable to find a flake before encountering filesystem boundary at '/home/runner'

view this post on Zulip Peter Marreck (Sep 30 2024 at 16:25):

It's possible I'm not doing it the "replit way" but not sure

view this post on Zulip Peter Marreck (Sep 30 2024 at 16:25):

invalid hash is odd because it's not one I included there

view this post on Zulip Peter Marreck (Sep 30 2024 at 16:26):

I suppose I can just do it with a flake.nix but I was hoping to get something going at the project level (or right above it)

view this post on Zulip Anton (Sep 30 2024 at 16:57):

invalid hash is odd because it's not one I included there

The hash in the error is the one in the gist

view this post on Zulip Anton (Sep 30 2024 at 17:01):

Usually, nix gives you the hash it calculated instead but here it doesn't, perhaps the hash is missing a character?

view this post on Zulip Anton (Sep 30 2024 at 17:04):

I'll sign up to replit and check it out

view this post on Zulip Anton (Sep 30 2024 at 18:03):

I don't get nix errors anymore but it could not use the roc command yet... I can try some more tomorrow.

view this post on Zulip Peter Marreck (Oct 01 2024 at 17:32):

I wonder if PATH is set up correctly in that case, although nix should be taking care of that if it is installing correctly via nix, I should think, since it's an output

view this post on Zulip Anton (Oct 01 2024 at 17:38):

Uhu, I would expect so too. Yeasterday I wrote packages.cl instead of packages.cli and I did not get any nix errors, so something could still be going wrong with nix. I'm now trying a very similar nix setup locally so I can test it properly

view this post on Zulip Peter Marreck (Oct 01 2024 at 21:26):

Thanks for investigating. I still don't understand nix (or replit) well enough to know why the same contents of a flake.nix wouldn't work in a replit.nix.
One thing I was going to try next was to create a few arbitrary replit preconfigured environments, examine their corresponding replit.nix files, and see if I could surmise what was missing that way via deduction

view this post on Zulip Peter Marreck (Oct 01 2024 at 21:52):

It would be nice if roc was simply available on nixpkgs unstable... might also help make it easier to check out for the uninitiated (and I would argue that the nix crowd is a good one...)

view this post on Zulip Anton (Oct 02 2024 at 10:07):

why the same contents of a flake.nix wouldn't work in a replit.nix.

replit.nix does not use the newer flake style, officially they are still experimental, yet very popular :p

view this post on Zulip Anton (Oct 02 2024 at 10:09):

One thing I was going to try next was to create a few arbitrary replit preconfigured environments, examine their corresponding replit.nix files, and see if I could surmise what was missing that way via deduction

I was looking at those too :)
https://github.com/search?q=fetch%20github%20path%3Areplit.nix&type=code

view this post on Zulip Anton (Oct 02 2024 at 10:13):

It would be nice if roc was simply available on nixpkgs unstable... might also help make it easier to check out for the uninitiated (and I would argue that the nix crowd is a good one...)

I've tried that in the past but got stuck on some macos problem. We could start off with linux support only...
Roc is changing fast so we would ideally also want a nix overlay so people can get the most recent version.

view this post on Zulip Anton (Oct 02 2024 at 15:47):

I finally got it to work locally:

let
  pkgs = import <nixpkgs> {};

  rocRepo =
    import (pkgs.fetchFromGitHub {
      owner = "roc-lang";
      repo = "roc";
      rev = "2c62f773efaa08302dd8e765f4dba91a0cdbde8d";
      sha256 = "sha256-kGYrBpSQ4zdPrV10gVemCKk3zKBW6XeC5wROcped8Ms=";
    });

  roc = rocRepo.packages.${pkgs.system}.cli;
in
pkgs.mkShell {
  buildInputs = with pkgs; [
    roc
  ];
}

But when I put the slightly modified version into replit:

let
    pkgs = import (fetchTarball https://github.com/NixOS/nixpkgs/archive/24.05.tar.gz) {} ;

    rocRepo =
        import (pkgs.fetchFromGitHub {
            owner = "roc-lang";
            repo = "roc";
            rev = "2c62f773efaa08302dd8e765f4dba91a0cdbde8d";
            sha256 = "sha256-kGYrBpSQ4zdPrV10gVemCKk3zKBW6XeC5wROcped8Ms=";
        });

    roc = rocRepo.packages.${pkgs.system}.cli;
in
{
    deps = [
        roc
    ];
}

It gives me:

nix error: building nix env: exit status 1
Output has been trimmed to the last 20 lines
       … from call site

         at /nix/store/pp028rj4l81sm4bs36l9mx80602m8kq4-nixpkgs-24.05-src/lib/trivial.nix:895:7:

          894|     { # TODO: Should we add call-time "type" checking like built in?
          895|       __functor = self: f;
             |       ^
          896|       __functionArgs = args;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: assertion '((builtins).isFunction raw)' failed

       at «string»:286:5:

          285|     in
          286|     assert builtins.isFunction raw; (callPackage { inherit pkgs legacyPolygott; } raw);
             |     ^
          287|

I don't think I can show that error not trimmed and I don't know what's wrong based on the trimmed version :(

view this post on Zulip Anton (Oct 02 2024 at 15:53):

I'll revisit this once Roc is on nix #7139


Last updated: Jul 06 2025 at 12:14 UTC