1 { lib, callPackage, runCommandLocal, writeScript, stdenv, coreutils }:
3 let buildFHSEnv = callPackage ./env.nix { }; in
5 args@{ name, version ? null, runScript ? "bash", nativeBuildInputs ? [], extraInstallCommands ? "", meta ? {}, passthru ? {}, ... }:
8 env = buildFHSEnv (removeAttrs args [ "version" "runScript" "extraInstallCommands" "meta" "passthru" ]);
10 chrootenv = callPackage ./chrootenv {};
12 init = run: writeScript "${name}-init" ''
14 for i in ${env}/* /host/*; do
16 [ -e "$path" ] || ${coreutils}/bin/ln -s "$i" "$path"
19 [ -d "$1" ] && [ -r "$1" ] && cd "$1"
26 versionStr = lib.optionalString (version != null) ("-" + version);
28 nameAndVersion = name + versionStr;
30 in runCommandLocal nameAndVersion {
31 inherit nativeBuildInputs meta;
33 passthru = passthru // {
34 env = runCommandLocal "${name}-shell-env" {
36 exec ${chrootenv}/bin/chrootenv ${init runScript} "$(pwd)"
40 echo >&2 "*** User chroot 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
47 cat <<EOF >$out/bin/${name}
49 exec ${chrootenv}/bin/chrootenv ${init runScript} "\$(pwd)" "\$@"
51 chmod +x $out/bin/${name}
52 ${extraInstallCommands}