42 lines
953 B
Nix
42 lines
953 B
Nix
{
|
|
conda,
|
|
yq,
|
|
writeShellApplication,
|
|
}:
|
|
writeShellApplication {
|
|
name = "conda-direnv";
|
|
|
|
runtimeInputs = [
|
|
conda
|
|
yq
|
|
];
|
|
|
|
text = ''
|
|
if [ ! -f environment.yml ]; then
|
|
echo "environment.yml does not exist! Exiting..."
|
|
exit 1
|
|
fi
|
|
|
|
ENV_NAME=$(${yq}/bin/yq ".name" environment.yml -r)
|
|
if [ "$ENV_NAME" == "" ] || [ "$ENV_NAME" == "null" ]; then
|
|
echo "Property \"name\" not in environment.yml or empty! Exiting..."
|
|
exit 1
|
|
fi
|
|
|
|
echo Welcome to your conda environment "$ENV_NAME"! Activating...
|
|
|
|
condanew() {
|
|
conda env create -f environment.yml -n $ENV_NAME
|
|
conda activate $ENV_NAME
|
|
}
|
|
|
|
exec ${conda}/bin/conda-shell
|
|
conda activate $ENV_NAME || condanew
|
|
|
|
echo "Environment active! To update it, run:"
|
|
echo -e "\tconda env update -f environment.yml -n $ENV_NAME"
|
|
|
|
"$SHELL" # needs to be last line so that conda-shell actually enters a shell
|
|
'';
|
|
}
|