aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpacien2022-11-13 19:55:56 +0100
committerpacien2022-11-13 19:55:56 +0100
commit511dcc29a2e0fb39dc413f8c7cfab8d28a93afab (patch)
treeb02b4839944751581f269614855a1b6deb4fe354
parent466c0f9806b40ad280b4c2ddea370f069f9c53af (diff)
downloadflaky-utils-511dcc29a2e0fb39dc413f8c7cfab8d28a93afab.tar.gz
mkDevShell: split env var setting and printing helpers
-rw-r--r--lib/mk-dev-shell.nix22
1 files changed, 17 insertions, 5 deletions
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;
9let 9let
10 exportEnvVar = k: v: '' 10 exportEnvVar = k: v: ''
11 export ${escapeShellArg k}="${v}" 11 export ${escapeShellArg k}="${v}"
12 '';
13
14 exportEnvVarsHook = envVars: ''
15 ${pkgs.lib.concatStringsSep "\n" (
16 pkgs.lib.mapAttrsToList exportEnvVar envVars
17 )}
18 '';
19
20 printEnvVar = k: v: ''
12 echo ${escapeShellArg k}=${escapeShellArg v} 21 echo ${escapeShellArg k}=${escapeShellArg v}
13 ''; 22 '';
14 23
15 envVarsHook = envVars: '' 24 printEnvVarsHook = envVars: ''
16 echo -e "\nDEVSHELL ENVIRONMENT VARIABLES:" 25 echo -e "\nDEVSHELL ENVIRONMENT VARIABLES:"
17 ${pkgs.lib.concatStringsSep "\n" ( 26 ${pkgs.lib.concatStringsSep "\n" (
18 pkgs.lib.mapAttrsToList exportEnvVar envVars 27 pkgs.lib.mapAttrsToList printEnvVar envVars
19 )} 28 )}
20 ''; 29 '';
21 30
22 listToolsHook = tools: '' 31 printToolsHook = tools: ''
23 echo -e "\nDEVSHELL COMMANDS:" 32 echo -e "\nDEVSHELL COMMANDS:"
24 ls "${pkgs.symlinkJoin { name = "env"; paths = tools; }}/bin" 33 ls "${pkgs.symlinkJoin { name = "env"; paths = tools; }}/bin"
25 ''; 34 '';
@@ -33,8 +42,11 @@ let
33in pkgs.mkShell { 42in pkgs.mkShell {
34 packages = tools; 43 packages = tools;
35 shellHook = '' 44 shellHook = ''
36 ${optionalString (envVars != {}) (envVarsHook envVars)} 45 ${exportEnvVarsHook envVars}
37 ${optionalString (tools != []) (listToolsHook tools)} 46
47 ${optionalString (envVars != {}) (printEnvVarsHook envVars)}
48 ${optionalString (tools != []) (printToolsHook tools)}
49
38 ${if (shell != null) then shell else startUserShellHook} 50 ${if (shell != null) then shell else startUserShellHook}
39 exit $? 51 exit $?
40 ''; 52 '';