diff options
-rw-r--r-- | lib/mk-dev-shell.nix | 31 | ||||
-rw-r--r-- | readme.md | 2 |
2 files changed, 22 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 | ||
7 | with pkgs.lib; | ||
8 | |||
6 | let | 9 | let |
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 | |||
13 | in 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 | ||
33 | in 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 | } |
@@ -48,6 +48,8 @@ Functions documentation provided as comments below. | |||
48 | PGDATABASE = "app"; | 48 | PGDATABASE = "app"; |
49 | DATABASE_URL = "postgresql:///${PGDATABASE}?host=${PGHOST}"; | 49 | DATABASE_URL = "postgresql:///${PGDATABASE}?host=${PGHOST}"; |
50 | }; | 50 | }; |
51 | |||
52 | shell = null; | ||
51 | }; | 53 | }; |
52 | 54 | ||
53 | }); | 55 | }); |