Skip to content

Commit ff75b34

Browse files
committed
Replace recursive-nix with IFD for -env job generation
The -env jobs previously used recursive-nix to run `nix print-dev-env` inside a derivation, but this fails on remote builders with: "recursive-nix is not supported yet by external derivation builders" This commit replaces that approach with Import From Derivation (IFD): - Read the mkShell output directly at evaluation time via builtins.readFile - Filter out the self-referencing $out variable to break circular deps - Embed the environment content directly in the wrapper script The mkShell output already contains "declare -x VAR=value" lines which is exactly what's needed. This approach: - Avoids the recursive-nix requirement entirely - Still includes all runtime dependencies (GHC, cabal, tools, etc.) - Works on remote builders without special configuration
1 parent 8ddd9d2 commit ff75b34

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

flake.nix

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,23 @@
208208
} "touch $out";
209209
} // (pkgs.lib.mapAttrs' (name: drv:
210210
pkgs.lib.nameValuePair "${name}-env" (
211-
# We need to use unsafeDiscardOutputDependency here, as it will otherwise
212-
# pull in a bunch of dependenceis we don't care about at all from the .drvPath
213-
# query.
214-
let env = pkgs.runCommand "${name}-env.sh" {
215-
requiredSystemFeatures = [ "recursive-nix" ];
216-
nativeBuildInputs = [ pkgs.nix ];
217-
} ''
218-
nix --offline --extra-experimental-features "nix-command flakes" \
219-
print-dev-env '${builtins.unsafeDiscardOutputDependency drv.drvPath}^*' >> $out
220-
'';
211+
# Use IFD (Import From Derivation) to read the shell's environment output
212+
# at evaluation time. This avoids the need for recursive-nix which is not
213+
# supported on remote builders.
214+
#
215+
# The mkShell output is a file containing "declare -x VAR=value" lines.
216+
# We read it via IFD, filter out the self-referencing $out variable,
217+
# and embed it directly in the wrapper script.
218+
let
219+
# Read the shell's output (triggers build at eval time via IFD)
220+
rawEnvContent = builtins.readFile drv;
221+
# Get the shell's store path to filter out the self-reference
222+
shellStorePath = builtins.unsafeDiscardStringContext (toString drv);
223+
# Filter out the $out self-reference to break the circular dependency
224+
envContent = builtins.replaceStrings
225+
[ "declare -x out=\"${shellStorePath}\"" ]
226+
[ "declare -x out=\"/dev/null\"" ]
227+
rawEnvContent;
221228
# this needs to be linux. It would be great if we could have this
222229
# eval platform agnostic, but flakes don't permit this. A the
223230
# platform where we build the docker images is linux (github
@@ -235,8 +242,9 @@
235242
236243
set -euo pipefail
237244
238-
# Set up the environment
239-
source ${env}
245+
# Set up the environment (embedded via IFD from mkShell output)
246+
${envContent}
247+
240248
source "$1"
241249
'';
242250
meta = {

0 commit comments

Comments
 (0)