static-nix-shell: factor out more helpers & correctly abort build on config error
This commit is contained in:
parent
b6ae9f3646
commit
310f5982cb
|
@ -27,7 +27,21 @@ in rec {
|
||||||
# - [ "pkgNameA" "pkgNameB" ... ]
|
# - [ "pkgNameA" "pkgNameB" ... ]
|
||||||
# - { pkgNameA = pkgValueA; pkgNameB = pkgValueB; ... }
|
# - { pkgNameA = pkgValueA; pkgNameB = pkgValueB; ... }
|
||||||
# - ps: <evaluate to one of the above exprs>
|
# - ps: <evaluate to one of the above exprs>
|
||||||
mkShell = { pname, interpreter, interpreterName, pkgsEnv, pkgsStr, srcPath ? pname, ...}@attrs:
|
mkShell = {
|
||||||
|
pname,
|
||||||
|
interpreter,
|
||||||
|
interpreterName ? lib.last (builtins.split "/" interpreter),
|
||||||
|
pkgsEnv,
|
||||||
|
pkgExprs,
|
||||||
|
srcPath ? pname,
|
||||||
|
...
|
||||||
|
}@attrs:
|
||||||
|
let
|
||||||
|
pkgsStr = concatStringsSep "" (map
|
||||||
|
(pname: " -p ${pname}")
|
||||||
|
pkgExprs
|
||||||
|
);
|
||||||
|
in
|
||||||
stdenv.mkDerivation ({
|
stdenv.mkDerivation ({
|
||||||
version = "0.1.0"; # default version
|
version = "0.1.0"; # default version
|
||||||
patchPhase = ''
|
patchPhase = ''
|
||||||
|
@ -43,13 +57,13 @@ in rec {
|
||||||
mv ${srcPath} $out/bin/${srcPath}
|
mv ${srcPath} $out/bin/${srcPath}
|
||||||
|
|
||||||
# ensure that all nix-shell references were substituted
|
# ensure that all nix-shell references were substituted
|
||||||
! grep nix-shell $out/bin/${srcPath}
|
(! grep nix-shell $out/bin/${srcPath}) || exit 1
|
||||||
|
|
||||||
# add runtime dependencies to PATH
|
# add runtime dependencies to PATH
|
||||||
wrapProgram $out/bin/${srcPath} \
|
wrapProgram $out/bin/${srcPath} \
|
||||||
--suffix PATH : ${lib.makeBinPath pkgsEnv }
|
--suffix PATH : ${lib.makeBinPath pkgsEnv }
|
||||||
'';
|
'';
|
||||||
} // (removeAttrs attrs [ "interpreter" "interpreterName" "pkgsEnv" "pkgsStr" "srcPath" ])
|
} // (removeAttrs attrs [ "interpreter" "interpreterName" "pkgsEnv" "pkgExprs" "srcPath" ])
|
||||||
);
|
);
|
||||||
|
|
||||||
# `mkShell` specialization for `nix-shell -i bash` scripts.
|
# `mkShell` specialization for `nix-shell -i bash` scripts.
|
||||||
|
@ -57,14 +71,10 @@ in rec {
|
||||||
let
|
let
|
||||||
pkgsAsAttrs = pkgsToAttrs "" pkgs' pkgs;
|
pkgsAsAttrs = pkgsToAttrs "" pkgs' pkgs;
|
||||||
pkgsEnv = attrValues pkgsAsAttrs;
|
pkgsEnv = attrValues pkgsAsAttrs;
|
||||||
pkgsStr = concatStringsSep "" (map
|
pkgExprs = attrNames pkgsAsAttrs;
|
||||||
(pname: " -p ${pname}")
|
|
||||||
(attrNames pkgsAsAttrs)
|
|
||||||
);
|
|
||||||
in mkShell ({
|
in mkShell ({
|
||||||
inherit pkgsEnv pkgsStr;
|
inherit pkgsEnv pkgExprs;
|
||||||
interpreter = "${pkgs'.bash}/bin/bash";
|
interpreter = "${pkgs'.bash}/bin/bash";
|
||||||
interpreterName = "bash";
|
|
||||||
} // (removeAttrs attrs [ "pkgs" ])
|
} // (removeAttrs attrs [ "pkgs" ])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -81,13 +91,11 @@ in rec {
|
||||||
|
|
||||||
pkgsAsAttrs = pkgsToAttrs "" pkgs' pkgs;
|
pkgsAsAttrs = pkgsToAttrs "" pkgs' pkgs;
|
||||||
pkgsEnv = attrValues pkgsAsAttrs;
|
pkgsEnv = attrValues pkgsAsAttrs;
|
||||||
pkgsStr = concatStringsSep "" (map
|
pkgExprs = [
|
||||||
(pname: " -p ${pname}")
|
"\"python3.withPackages (ps: [ ${pyPkgsStr} ])\""
|
||||||
(attrNames pkgsAsAttrs)
|
] ++ (attrNames pkgsAsAttrs);
|
||||||
);
|
|
||||||
in mkShell ({
|
in mkShell ({
|
||||||
inherit pkgsEnv;
|
inherit pkgsEnv pkgExprs;
|
||||||
pkgsStr = " -p \"python3.withPackages (ps: [ ${pyPkgsStr} ])\"${pkgsStr}";
|
|
||||||
interpreter = pyEnv.interpreter;
|
interpreter = pyEnv.interpreter;
|
||||||
interpreterName = "python3";
|
interpreterName = "python3";
|
||||||
} // (removeAttrs attrs [ "pkgs" "pyPkgs" ])
|
} // (removeAttrs attrs [ "pkgs" "pyPkgs" ])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user