Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
(id: _: self.packages.x86_64-linux."phony-oci-bundles.${id}")
self.modules;
lib.mkBundle = import ./pkgs/bundle/api.nix { inherit pkgs self; };
lib.mkReplitShell = import ./pkgs/replit-shell { inherit pkgs; };
checks.x86_64-linux.module-shell = import ./pkgs/moduleit/tests.nix { inherit pkgs; };
checks.x86_64-linux.module-registry =
assert import ./scripts/module-registry-test.nix;
Expand Down
5 changes: 4 additions & 1 deletion pkgs/moduleit/shell-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ let
+ lib.optionalString (key == "PATH") "\${PATH:+:}\"$PATH\"")
ordered.result + "\n";
in
runCommand name { } ''
runCommand name
{
passthru.replitModuleId = moduleId;
} ''
mkdir -p "$out/nix-support" "$out/share/replit/modules"
# The IDE finds module metadata through REPLIT_MODULES; its store paths keep LSPs and runners alive.
cp ${module} "$out/share/replit/modules/${moduleId}.json"
Expand Down
59 changes: 59 additions & 0 deletions pkgs/replit-shell/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{ pkgs }:
{ packages ? [ ], shellHook ? "", name ? "replit-devshell" }:
let
inherit (pkgs) lib;
# Explicit module metadata separates module environments from ordinary packages.
inputs = lib.partition (pkg: pkg ? replitModuleId) (map
(pkg:
assert lib.assertMsg (lib.isDerivation pkg)
"mkReplitShell: each packages element must be a derivation";
pkg)
packages);
moduleHook = module: ''
source ${lib.escapeShellArg "${module}/nix-support/replit-env"}
'';
closure = map (entry: entry.pkg) (builtins.genericClosure {
startSet = map (pkg: { key = toString pkg; inherit pkg; }) inputs.wrong;
operator = entry: map
(pkg: { key = toString pkg; inherit pkg; })
(entry.pkg.propagatedBuildInputs or [ ]);
});
dirs = output: suffix: lib.unique (map (pkg: "${output pkg}/${suffix}") closure);
libDirs = dirs lib.getLib "lib";
devDirs = dirs lib.getDev "include";
pkgConfigDirs = lib.unique (dirs lib.getDev "lib/pkgconfig" ++ dirs lib.getLib "lib/pkgconfig");
# Ordinary packages contribute directories only; their stdenv setup hooks never run.
exportDirs = var: separator: prefix: paths: lib.optionalString (paths != [ ]) ''
replit_shell_value=
for replit_shell_dir in ${lib.escapeShellArgs paths}; do
if [[ -d "$replit_shell_dir" ]]; then
replit_shell_value+="''${replit_shell_value:+${separator}}${prefix}$replit_shell_dir"
fi
done
if [[ -n "$replit_shell_value" ]]; then
export ${var}="$replit_shell_value''${${var}:+${separator}}''${${var}-}"
fi
unset replit_shell_value replit_shell_dir
'';
in
builtins.derivation {
inherit name;
outputs = [ "out" ];
system = pkgs.stdenv.hostPlatform.system;
builder = "${pkgs.bash}/bin/bash";
args = [ "-c" ": > $out" ];
SHELL = "${pkgs.bash}/bin/bash";
# No PATH: the workspace runtime accepts a shell without one and ignores Nix's /path-not-set.
shellHook = lib.concatMapStrings moduleHook (lib.reverseList inputs.right)
+ exportDirs "PATH" ":" "" (dirs lib.getBin "bin")
+ exportDirs "REPLIT_LD_LIBRARY_PATH" ":" "" libDirs
+ exportDirs "LDFLAGS" " " "-L" libDirs
+ exportDirs "NIX_LDFLAGS" " " "-L" libDirs
+ exportDirs "PKG_CONFIG_PATH" ":" "" pkgConfigDirs
+ exportDirs "PKG_CONFIG_PATH_FOR_TARGET" ":" "" pkgConfigDirs
+ exportDirs "XDG_DATA_DIRS" ":" "" (dirs (lib.getOutput "out") "share")
+ exportDirs "CFLAGS" " " "-isystem " devDirs
+ exportDirs "NIX_CFLAGS_COMPILE" " " "-isystem " devDirs
+ exportDirs "GI_TYPELIB_PATH" ":" "" (dirs lib.getLib "lib/girepository-1.0")
+ shellHook;
}
Loading