From 511dcc29a2e0fb39dc413f8c7cfab8d28a93afab Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 13 Nov 2022 19:55:56 +0100 Subject: mkDevShell: split env var setting and printing helpers --- lib/mk-dev-shell.nix | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/mk-dev-shell.nix b/lib/mk-dev-shell.nix index e6e916a..0e2a265 100644 --- a/lib/mk-dev-shell.nix +++ b/lib/mk-dev-shell.nix @@ -9,17 +9,26 @@ with pkgs.lib; let exportEnvVar = k: v: '' export ${escapeShellArg k}="${v}" + ''; + + exportEnvVarsHook = envVars: '' + ${pkgs.lib.concatStringsSep "\n" ( + pkgs.lib.mapAttrsToList exportEnvVar envVars + )} + ''; + + printEnvVar = k: v: '' echo ${escapeShellArg k}=${escapeShellArg v} ''; - envVarsHook = envVars: '' + printEnvVarsHook = envVars: '' echo -e "\nDEVSHELL ENVIRONMENT VARIABLES:" ${pkgs.lib.concatStringsSep "\n" ( - pkgs.lib.mapAttrsToList exportEnvVar envVars + pkgs.lib.mapAttrsToList printEnvVar envVars )} ''; - listToolsHook = tools: '' + printToolsHook = tools: '' echo -e "\nDEVSHELL COMMANDS:" ls "${pkgs.symlinkJoin { name = "env"; paths = tools; }}/bin" ''; @@ -33,8 +42,11 @@ let in pkgs.mkShell { packages = tools; shellHook = '' - ${optionalString (envVars != {}) (envVarsHook envVars)} - ${optionalString (tools != []) (listToolsHook tools)} + ${exportEnvVarsHook envVars} + + ${optionalString (envVars != {}) (printEnvVarsHook envVars)} + ${optionalString (tools != []) (printToolsHook tools)} + ${if (shell != null) then shell else startUserShellHook} exit $? ''; -- cgit v1.2.3