nix support for racket (experimental)
Go to file
xenia 6e53c706b9 update readme 2025-10-10 11:33:55 -04:00
racket only wrap elf binaries and not scripts 2025-09-27 00:34:01 -04:00
racket-catalog update catalog with fixes 2025-10-09 20:20:58 -04:00
.gitignore init racket at nixpkgs/f8a7597 2025-09-26 21:17:32 -04:00
README.md update readme 2025-10-10 11:33:55 -04:00
build-racket-package.nix implement initial racket2nix script 2025-10-09 01:58:26 -04:00
flake.lock init racket at nixpkgs/f8a7597 2025-09-26 21:17:32 -04:00
flake.nix refactor 2025-09-29 22:00:43 -04:00
make-racket-env.nix update some jank 2025-09-29 21:47:23 -04:00
overlay.nix implement initial racket2nix script 2025-10-09 01:58:26 -04:00
racket-catalog-overrides.rktd add some packages from the catalog 2025-10-09 01:59:08 -04:00
racket-install-hook.nix implement racket packaging and environments 2025-09-28 20:27:04 -04:00
racket-install-hook.sh implement initial racket2nix script 2025-10-09 01:58:26 -04:00
racket2nix.rkt implement command line 2025-10-09 22:26:01 -04:00

README.md

nix support for racket

implements nix helpers for building racket packages and environments

this is a complete new implementation of this functionality. i did not use racket2nix because racket2nix is messy and hasn't been updated for a while. this is a significantly simpler implementation owning to better use of stdenv utilities and racket features

how to use

make nix packages for racket packages

pkgs.racketPackages.callPackage (
  {
    lib,
    buildRacketPackage,
    fetchFromGitHub,
  }: buildRacketPackage {
    pname = "ansi-color";
    version = "0.2";

    src = final.fetchFromGitHub {
      owner = "renatoathaydes";
      repo = "ansi-color";
      rev = "0.2";
      hash = "sha256-7WDW+4R9K+XLb9nMNGQlU+zAi2Gq7cUqzO3csN+AJvI=";
    };
  }
) {}

automatic conversion from pkgs.racket-lang.org

racket2nix.rkt implements fetching catalog information for a package, converting the info to a nix expression, building the expression, and then refining the final expression with the source hash (TOFU), and other metadata from info.rkt

racket racket2nix.nix <pkgs> ...

this will create new files in racket-catalog which will then become available via eg nix build .#racketPackages.mypackage

build a racket environment

unfortunately, due to racket limitations, nix-shell/nix develop will not work at all for racket packages that are created using this nix code. instead, similar to python.buildEnv / python.withPackages, you can create a racket environment with a given set of packages in it. this functions somewhat like a python "virtualenv" for racket. it is implemented by creating a "tethered installation" -- see https://docs.racket-lang.org/raco/tethered-install.html.

with pkgs.racketPackages; makeRacketEnv {
  packages = [
    ansi-color
  ];
};

the resulting environment will have a bin/racket executable which has the declared packages available

future work

  • add native library support to racket2nix
  • allow using either racket or racket-minimal as a base (currently only racket non-minimal is supported)
  • instead of having 2 separate packages, rework racket to be a layered installation on top of racket-minimal, reducing duplication. this is similar to how guix does it
  • split outputs into bin/lib/doc/man etc