Skip to content

Add lib.mkReplitShell for stdenv-free module devShells - #521

Closed
rahultee wants to merge 2 commits into
mainfrom
rahul/mk-replit-shell
Closed

rahultee wants to merge 2 commits into
mainfrom
rahul/mk-replit-shell

Conversation

@rahultee

@rahultee rahultee commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Why

  • Flake-based Replit projects hand-write a raw builtins.derivation devShell that sources each module's nix-support/replit-env and sets SHELL/PATH by hand. A small helper gives the same module-only behavior as .replit modules, without stdenv.

What changed

  • New lib.mkReplitShell { packages ? [ ], shellHook ? "", name ? "replit-devshell" } (pkgs/replit-shell/default.nix), exported next to lib.mkBundle.
  • Module shell packages now carry passthru.replitModuleId (pkgs/moduleit/shell-package.nix). This is metadata only; module outPaths are unchanged.
  • Output: a raw builtins.derivation (no stdenv), with outputs = [ "out" ] (required by nix print-dev-env), SHELL = nixpkgs bash, and no PATH.
  • packages is one list that mixes modules (nm.replit, nm.nodejs-24) and ordinary nixpkgs packages. Non-derivations fail with an assertion.
    • Modules (detected by replitModuleId): nix-support/replit-env is sourced in reverse order, so the first listed module wins, as with mkShell.
    • Ordinary packages are handled like .replit [nix] packages: bin → PATH; lib → REPLIT_LD_LIBRARY_PATH, LDFLAGS/NIX_LDFLAGS (-L); lib/pkgconfig → PKG_CONFIG_PATH(_FOR_TARGET); share → XDG_DATA_DIRS; include → CFLAGS/NIX_CFLAGS_COMPILE (-isystem); lib/girepository-1.0 → GI_TYPELIB_PATH. Uses the bin/lib/dev outputs, the propagatedBuildInputs closure and only existing dirs. Their stdenv setup hooks don't run, so this is not a full mkShell replacement.
    • Ordinary packages are applied after all modules, so they come first on PATH (the legacy order) wherever they appear in the list; among themselves they keep list order.
  • Hook order: module envs, then package exports, then the user shellHook.

Usage:

devShells.x86_64-linux.default = nixmodules.lib.mkReplitShell {
  packages = [ nm.replit nm.nodejs-24 pkgs.jq ];
};

Test plan

  • Passed: nix eval of empty and [ nm.replit nm.nodejs-24 pkgs.jq ] shells (an interleaved order gives the same hook); module outPaths unchanged; nixpkgs-fmt --check; bash -n on the generated hook; git diff --check.
  • Local nix print-dev-env of a fixture flake (nm.replit, nm.nodejs-24, pkgs.jq; the single-list form produces the identical devShell derivation), evaluated as the runtime does: node v24.22.1, pnpm 10.26.1 and jq 1.7.1 on PATH; REPLIT_MODULES, npm_config_prefix and the rtld loader var are set; no compiler vars.
  • In a local Replit workspace with flake mode on (this change on a branch based on the currently pinned nixmodules rev):
    • PATH order: jq, then the nodejs-24 module entries, then system tools. Node, pnpm and jq resolve.
    • npm i bufferutil --build-from-source compiled with the system gcc/make, and the addon loads.
    • Adding pkgs.ripgrep to packages republished the env in about 2 minutes, and rg 14.1.1 worked in new shells.
    • The first boot of a fresh workspace took longer than the runtime's 3-minute wait (cold fetch of the flake inputs) and finished in the background.

Rollout

  • Additive: new lib output only; modules and existing outputs are unchanged.
  • A shell without PATH relies on the Replit runtime accepting it and ignoring Nix's /path-not-set. Consumers should adopt this helper only after that runtime change is live.
  • This is fully backward and forward compatible

~ written by ⠕ Replit

@rahultee rahultee closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant