dream2nix icon indicating copy to clipboard operation
dream2nix copied to clipboard

Create a Racket `devShell` with dependencies for local development.

Open zainab-ali opened this issue 2 years ago • 1 comments
trafficstars

The default nix build for Racket builds a project. If the project source is broken (let's say there's a syntax error in the code), this fails. While this is perfectly fine for CI builds, it would be very helpful to have a dev shell for local development in which we could run the build.

This shell could include all project dependencies as buildInputs, but not the project source.

I’ve managed to achieve this by using nix-filter to create a dependencies derivation that excludes all source code:

dependencies = (dream2nix.lib.makeFlakeOutputs {
  systems = ["x86_64-linux"];
  config.projectRoot = ./.;
  source = nix-filter.lib.filter {
    root = ./.;
    # Exclude everything but the `info.rkt` that lists dependencies.
    include = [./info.rkt];
  };
  projects = ./projects.toml;
}).packages.${system};

This can then be used in a shell:

devShells.default = pkgs.mkShell {
  buildInputs = [dependencies.default];
};

We can enter the shell to build the project and fix any bugs

nix develop
> raco test .
foo.rkt:3:0: foo: unbound identifier # An example of a bug

Let me know if there's already a way to achieve this. I'd be happy to add docs on it.

zainab-ali avatar Jan 23 '23 17:01 zainab-ali

I can see that the nodejs builder provides a devShell for a similar purpose. I suspect it wouldn't be too tricky to make one for Racket. I'll look into it when I have the time.

zainab-ali avatar Jan 24 '23 15:01 zainab-ali