From 96411aaa21543c81ce53fd9210e63c5e3d4ac519 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 22 Aug 2022 18:31:14 +0200 Subject: bootstrap lib, add mkDevShell --- lib/mk-dev-shell.nix | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/mk-dev-shell.nix (limited to 'lib') diff --git a/lib/mk-dev-shell.nix b/lib/mk-dev-shell.nix new file mode 100644 index 0000000..e0bb441 --- /dev/null +++ b/lib/mk-dev-shell.nix @@ -0,0 +1,30 @@ +{ pkgs +, tools ? [] +, envVars ? {} +}: + +let + # TODO: escape values properly + exportEnvVar = k: v: ''export ${k}="${v}"; echo ${k}=\"${v}\"''; + exportedEnvVars = pkgs.lib.mapAttrsToList exportEnvVar envVars; + +in pkgs.mkShell { + buildInputs = tools; + + # TODO: handle case with no env variable set + # TODO: handle case with no package in tools + # TODO: allow custom shell + shellHook = '' + echo -e "\nDEVSHELL ENVIRONMENT VARIABLES:" + ${pkgs.lib.concatStringsSep "\n" exportedEnvVars} + + echo -e "\nDEVSHELL COMMANDS:" + ls "${pkgs.symlinkJoin { name = "env"; paths = tools; }}/bin" + + # Use the default user shell instead of Bash + $(${pkgs.finger_bsd}/bin/finger $USER \ + | ${pkgs.gnugrep}/bin/grep -oP 'Shell: \K.*') + + exit $? + ''; +} -- cgit v1.2.3