mirror of
https://gitlab.com/rensa-nix/devshell.git
synced 2025-12-12 06:10:07 +01:00
chore: initial commit
This commit is contained in:
commit
fbacfc149b
21 changed files with 748 additions and 0 deletions
70
lib/utils/mkNakedShell.nix
Normal file
70
lib/utils/mkNakedShell.nix
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
{
|
||||
bashInteractive,
|
||||
coreutils,
|
||||
stdenv,
|
||||
writeTextFile,
|
||||
}: let
|
||||
bashPath = "${bashInteractive}/bin/bash";
|
||||
nakedStdenv = writeTextFile {
|
||||
name = "naked-stdenv";
|
||||
destination = "/setup";
|
||||
text = ''
|
||||
# Fix for `nix develop`
|
||||
: ''${outputs:=out}
|
||||
|
||||
runHook() {
|
||||
eval "$shellHook"
|
||||
unset runHook
|
||||
}
|
||||
'';
|
||||
};
|
||||
in
|
||||
{
|
||||
name,
|
||||
# A path to a buildEnv that will be loaded by the shell.
|
||||
# We assume that the buildEnv contains an ./env.bash script.
|
||||
profile,
|
||||
meta ? {},
|
||||
passthru ? {},
|
||||
}:
|
||||
(derivation {
|
||||
inherit name;
|
||||
|
||||
system = stdenv.hostPlatform.system;
|
||||
|
||||
# `nix develop` actually checks and uses builder. And it must be bash.
|
||||
builder = bashPath;
|
||||
|
||||
# Bring in the dependencies on `nix-build`
|
||||
args = [
|
||||
"-ec"
|
||||
"${coreutils}/bin/ln -s ${profile} $out; exit 0"
|
||||
];
|
||||
|
||||
# $stdenv/setup is loaded by nix-shell during startup.
|
||||
# https://github.com/nixos/nix/blob/377345e26f1ac4bbc87bb21debcc52a1d03230aa/src/nix-build/nix-build.cc#L429-L432
|
||||
stdenv = nakedStdenv;
|
||||
|
||||
# The shellHook is loaded directly by `nix develop`. But nix-shell
|
||||
# requires that other trampoline.
|
||||
shellHook = ''
|
||||
# Remove all the unnecessary noise that is set by the build env
|
||||
unset NIX_BUILD_TOP NIX_BUILD_CORES NIX_STORE
|
||||
unset TEMP TEMPDIR TMP TMPDIR
|
||||
unset builder out shellHook stdenv system name
|
||||
# Flakes stuff
|
||||
unset dontAddDisableDepTrack outputs
|
||||
|
||||
# For `nix develop`. We get /noshell on Linux and /sbin/nologin on macOS.
|
||||
if [[ "$SHELL" == "/noshell" || "$SHELL" == "/sbin/nologin" ]]; then
|
||||
export SHELL=${bashPath}
|
||||
fi
|
||||
|
||||
# Load the environment
|
||||
source "${profile}/env.bash"
|
||||
'';
|
||||
})
|
||||
// {
|
||||
inherit meta passthru;
|
||||
}
|
||||
// passthru
|
||||
Loading…
Add table
Add a link
Reference in a new issue