diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 02ec4b0..1324ee6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /builds /ghidra/projects/**/*.lock* /mars-db.conf +/.direnv diff --git a/flake.nix b/flake.nix index a36412a..c579a53 100644 --- a/flake.nix +++ b/flake.nix @@ -95,26 +95,49 @@ rec { buildDebug = mkBuildScript "Debug"; buildRelease = mkBuildScript "Release"; - # Use this to specify commands that should be ran after entering fish shell - initProjectShell = pkgs.writers.writeFish "init-shell.fish" '' - echo "Entering \"${description}\" environment..." - - # Determine the project root, used e.g. in cmake scripts - set -g -x FLAKE_PROJECT_ROOT (git rev-parse --show-toplevel) - - abbr -a fail "perl ./scripts/menu.pl" + # Add project-local fish abbrs here + abbrs = { + fail = "perl ./scripts/menu.pl"; # C/C++: - # abbr -a cmake-debug "${cmakeDebug}" - # abbr -a cmake-release "${cmakeRelease}" - # abbr -a build-debug "${buildDebug}" - # abbr -a build-release "${buildRelease}" + # cmake-debug = "${cmakeDebug}"; + # cmake-release = "${cmakeRelease}"; + # build-debug = "${buildDebug}"; + # build-release = "${buildRelease}"; + }; + + eraseAbbr = name: value: ''abbr --erase ${name} 2>/dev/null''; + createAbbr = name: value: ''abbr -a ${name} "${value}"''; + + # This will be sourced by the global fish config if INIT_PROJECT_SHELL gets unset + unloadProjectShell = pkgs.writers.writeFish "unload-shell.fish" '' + echo "Unloading \"${description}\" environment..." + + ${builtins.concatStringsSep "\n" (lib.mapAttrsToList eraseAbbr abbrs)} + ''; + + # This will be sourced by the global fish config if INIT_PROJECT_SHELL gets set + initProjectShell = pkgs.writers.writeFish "init-shell.fish" '' + # Unload just in case, to not have redefinition errors + source ${unloadProjectShell} + + echo "Sourcing \"${description}\" environment..." + + ${builtins.concatStringsSep "\n" (lib.mapAttrsToList createAbbr abbrs)} ''; in builtins.concatStringsSep "\n" [ # Launch into pure fish shell '' - exec "$(type -p fish)" -C "source ${initProjectShell} && abbr -a menu '${pkgs.bat}/bin/bat "${initProjectShell}"'" + # Can't do the "exec" with nix-direnv + # - The "exec fish" would call direnv again => Infinite loop + # - The shellHook is Bash/POSIX, so fish syntax doesn't work + # exec "$(type -p fish)" -C "source ${initProjectShell} && abbr -a menu '${pkgs.bat}/bin/bat "${initProjectShell}"'" + + # Determine the project root, used e.g. in cmake scripts + export FLAKE_PROJECT_ROOT="$(git rev-parse --show-toplevel)" + export INIT_PROJECT_SHELL="${initProjectShell}" + export UNLOAD_PROJECT_SHELL="${unloadProjectShell}" '' ];