Skip to content

Commit 5c8b6c8

Browse files
committed
Replace IFD with build-time read for -env job generation
The previous IFD approach forced cross-platform builds during evaluation, which could cause issues when Hydra evaluates on x86_64-linux but needs to evaluate aarch64-darwin shells. This new approach reads the mkShell output at build time using cat, avoiding both: - IFD which forces builds during evaluation - recursive-nix which is not supported on remote builders The shell is now a normal build dependency, and its output (containing "declare -x VAR=value" lines) is read at build time to construct the wrapper script.
1 parent ff75b34 commit 5c8b6c8

File tree

1 file changed

+26
-46
lines changed

1 file changed

+26
-46
lines changed

flake.nix

Lines changed: 26 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -208,58 +208,38 @@
208208
} "touch $out";
209209
} // (pkgs.lib.mapAttrs' (name: drv:
210210
pkgs.lib.nameValuePair "${name}-env" (
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.
211+
# Build-time read approach: read the mkShell output at build time using cat.
212+
# This avoids both:
213+
# - IFD (Import From Derivation) which forces cross-platform builds during eval
214+
# - recursive-nix which is not supported on remote builders
214215
#
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;
228-
# this needs to be linux. It would be great if we could have this
229-
# eval platform agnostic, but flakes don't permit this. A the
230-
# platform where we build the docker images is linux (github
231-
# ubuntu runners), this needs to be evaluable on linux.
232-
in (import nixpkgs { system = "x86_64-linux"; }).writeTextFile {
233-
name = "devx";
234-
executable = true;
216+
# The shell (drv) is a normal build dependency. Its output contains
217+
# "declare -x VAR=value" lines which we read at build time.
218+
pkgs.runCommand "devx" {} ''
219+
# Read the shell's output at build time
220+
shellContent=$(cat ${drv})
221+
222+
# Filter out the $out self-reference to avoid circular dependency issues
223+
filteredContent=$(echo "$shellContent" | grep -v 'declare -x out=')
224+
225+
# Create the wrapper script
235226
# We use nix-shell to invoke bash, to work around some shells being just too ancient.
236-
# This primarily happens on macOS. But as the sourced env may expect a bash version
237-
# current with the current nix, using nix-shell to launch the bash is probably the
238-
# most reliable option.
239-
text = ''
240-
#! /usr/bin/env nix-shell
241-
#! nix-shell -i bash -p bash
227+
# This primarily happens on macOS.
228+
cat > $out <<'SCRIPT'
229+
#! /usr/bin/env nix-shell
230+
#! nix-shell -i bash -p bash
242231
243-
set -euo pipefail
232+
set -euo pipefail
233+
SCRIPT
244234
245-
# Set up the environment (embedded via IFD from mkShell output)
246-
${envContent}
235+
# Append the filtered environment
236+
echo "$filteredContent" >> $out
247237
248-
source "$1"
249-
'';
250-
meta = {
251-
description = "DevX shell";
252-
longDescription = ''
253-
The DevX shell is supposed to be used with GitHub Actions, and
254-
can be used by setting the default shell to:
238+
# Append the source command
239+
echo 'source "$1"' >> $out
255240
256-
shell: devx {0}
257-
'';
258-
homepage = "https://github.com/input-output-hk/devx";
259-
license = pkgs.lib.licenses.asl20;
260-
platforms = pkgs.lib.platforms.unix;
261-
};
262-
})) devShells)
241+
chmod +x $out
242+
'')) devShells)
263243
// (pkgs.lib.mapAttrs' (name: drv:
264244
pkgs.lib.nameValuePair "${name}-plans" drv.plans) devShells);
265245
packages.cabalProjectLocal-static = (import ./quirks.nix { pkgs = static-pkgs; static = true; }).template;

0 commit comments

Comments
 (0)