aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorpacien2022-08-22 19:14:34 +0200
committerpacien2022-08-22 19:14:34 +0200
commitf86a414ad3c4b4ec49945a7100df16acef51ff3b (patch)
tree3668213bce6e0f411aed6b57df121dc8c6eab346 /lib
parent9f8ee57824aa587ecdb28620457ba53573249f3a (diff)
downloadflaky-utils-f86a414ad3c4b4ec49945a7100df16acef51ff3b.tar.gz
lib.mkDevShell: handle custom shell and empty tools or env
Diffstat (limited to 'lib')
-rw-r--r--lib/mk-dev-shell.nix31
1 files changed, 20 insertions, 11 deletions
diff --git a/lib/mk-dev-shell.nix b/lib/mk-dev-shell.nix
index 8078f35..c6b36b7 100644
--- a/lib/mk-dev-shell.nix
+++ b/lib/mk-dev-shell.nix
@@ -1,32 +1,41 @@
1{ pkgs 1{ pkgs
2, tools ? [] 2, tools ? []
3, envVars ? {} 3, envVars ? {}
4, shell ? null
4}: 5}:
5 6
7with pkgs.lib;
8
6let 9let
7 exportEnvVar = k: v: with pkgs.lib; '' 10 exportEnvVar = k: v: ''
8 export ${escapeShellArg k}=${escapeShellArg v} 11 export ${escapeShellArg k}=${escapeShellArg v}
9 echo ${escapeShellArg k}=${escapeShellArg v} 12 echo ${escapeShellArg k}=${escapeShellArg v}
10 ''; 13 '';
11 exportedEnvVars = pkgs.lib.mapAttrsToList exportEnvVar envVars;
12
13in pkgs.mkShell {
14 buildInputs = tools;
15 14
16 # TODO: handle case with no env variable set 15 envVarsHook = envVars: ''
17 # TODO: handle case with no package in tools
18 # TODO: allow custom shell
19 shellHook = ''
20 echo -e "\nDEVSHELL ENVIRONMENT VARIABLES:" 16 echo -e "\nDEVSHELL ENVIRONMENT VARIABLES:"
21 ${pkgs.lib.concatStringsSep "\n" exportedEnvVars} 17 ${pkgs.lib.concatStringsSep "\n" (
18 pkgs.lib.mapAttrsToList exportEnvVar envVars
19 )}
20 '';
22 21
22 listToolsHook = tools: ''
23 echo -e "\nDEVSHELL COMMANDS:" 23 echo -e "\nDEVSHELL COMMANDS:"
24 ls "${pkgs.symlinkJoin { name = "env"; paths = tools; }}/bin" 24 ls "${pkgs.symlinkJoin { name = "env"; paths = tools; }}/bin"
25 '';
25 26
26 # Use the default user shell instead of Bash 27 # Use the default user shell instead of Bash
28 startUserShellHook = ''
27 $(${pkgs.finger_bsd}/bin/finger $USER \ 29 $(${pkgs.finger_bsd}/bin/finger $USER \
28 | ${pkgs.gnugrep}/bin/grep -oP 'Shell: \K.*') 30 | ${pkgs.gnugrep}/bin/grep -oP 'Shell: \K.*')
31 '';
29 32
33in pkgs.mkShell {
34 buildInputs = tools;
35 shellHook = ''
36 ${optionalString (envVars != {}) (envVarsHook envVars)}
37 ${optionalString (tools != []) (listToolsHook tools)}
38 ${if (shell != null) then shell else startUserShellHook}
30 exit $? 39 exit $?
31 ''; 40 '';
32} 41}