update flake to use direnv
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
||||
/builds
|
||||
/ghidra/projects/**/*.lock*
|
||||
/mars-db.conf
|
||||
/.direnv
|
||||
|
||||
49
flake.nix
49
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}"
|
||||
''
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user