nixpkgs/pkgs/build-support/mkshell/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
1.6 KiB
Nix
Raw Normal View History

{ lib, stdenv, buildEnv }:
2017-12-21 00:42:07 +01:00
# A special kind of derivation that is only meant to be consumed by the
# nix-shell.
{ name ? "nix-shell"
, # a list of packages to add to the shell environment
packages ? [ ]
, # propagate all the inputs from the given derivations
inputsFrom ? [ ]
, buildInputs ? [ ]
, nativeBuildInputs ? [ ]
, propagatedBuildInputs ? [ ]
, propagatedNativeBuildInputs ? [ ]
, ...
2017-12-21 00:42:07 +01:00
}@attrs:
let
mergeInputs = name:
(attrs.${name} or [ ]) ++
(lib.subtractLists inputsFrom (lib.flatten (lib.catAttrs name inputsFrom)));
2017-12-21 00:42:07 +01:00
rest = builtins.removeAttrs attrs [
"name"
"packages"
2017-12-21 00:42:07 +01:00
"inputsFrom"
"buildInputs"
"nativeBuildInputs"
"propagatedBuildInputs"
"propagatedNativeBuildInputs"
"shellHook"
2017-12-21 00:42:07 +01:00
];
in
stdenv.mkDerivation ({
inherit name;
2017-12-21 00:42:07 +01:00
buildInputs = mergeInputs "buildInputs";
nativeBuildInputs = packages ++ (mergeInputs "nativeBuildInputs");
2017-12-21 00:42:07 +01:00
propagatedBuildInputs = mergeInputs "propagatedBuildInputs";
propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs";
shellHook = lib.concatStringsSep "\n" (lib.catAttrs "shellHook"
(lib.reverseList inputsFrom ++ [ attrs ]));
phases = [ "buildPhase" ];
buildPhase = ''
mkshell: refactor Bash snippet I’ve been using https://github.com/Fuuzetsu/shellcheck-nix-attributes on most of my derivations, and attaching it to one derived from `mkShell` resulted in ``` shellcheck_buildPhase In /nix/store/8774inwznc87dwhac90winc9b5k6gmkb-nix-shell_shellcheck_buildPhase line 1: echo "------------------------------------------------------------" >>$out ^-- SC2129 (style): Consider using { cmd1; cmd2; } >> file instead of individual redirects. ^--^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: echo "------------------------------------------------------------" >>"$out" In /nix/store/8774inwznc87dwhac90winc9b5k6gmkb-nix-shell_shellcheck_buildPhase line 2: echo " WARNING: the existence of this path is not guaranteed." >>$out ^--^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: echo " WARNING: the existence of this path is not guaranteed." >>"$out" In /nix/store/8774inwznc87dwhac90winc9b5k6gmkb-nix-shell_shellcheck_buildPhase line 3: echo " It is an internal implementation detail for pkgs.mkShell." >>$out ^--^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: echo " It is an internal implementation detail for pkgs.mkShell." >>"$out" In /nix/store/8774inwznc87dwhac90winc9b5k6gmkb-nix-shell_shellcheck_buildPhase line 4: echo "------------------------------------------------------------" >>$out ^--^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: echo "------------------------------------------------------------" >>"$out" In /nix/store/8774inwznc87dwhac90winc9b5k6gmkb-nix-shell_shellcheck_buildPhase line 5: echo >> $out ^--^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: echo >> "$out" In /nix/store/8774inwznc87dwhac90winc9b5k6gmkb-nix-shell_shellcheck_buildPhase line 7: export >> $out ^--^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: export >> "$out" For more information: https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ... https://www.shellcheck.net/wiki/SC2129 -- Consider using { cmd1; cmd2; } >>... ``` ——— https://garnix.io/build/qgxbameB This addresses the shellcheck complaints.
2022-12-05 09:16:12 +01:00
{ echo "------------------------------------------------------------";
echo " WARNING: the existence of this path is not guaranteed.";
echo " It is an internal implementation detail for pkgs.mkShell.";
echo "------------------------------------------------------------";
echo;
# Record all build inputs as runtime dependencies
export;
} >> "$out"
2017-12-21 00:42:07 +01:00
'';
preferLocalBuild = true;
2017-12-21 00:42:07 +01:00
} // rest)