update flake to use direnv
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
|||||||
/builds
|
/builds
|
||||||
/ghidra/projects/**/*.lock*
|
/ghidra/projects/**/*.lock*
|
||||||
/mars-db.conf
|
/mars-db.conf
|
||||||
|
/.direnv
|
||||||
|
|||||||
49
flake.nix
49
flake.nix
@ -95,26 +95,49 @@ rec {
|
|||||||
buildDebug = mkBuildScript "Debug";
|
buildDebug = mkBuildScript "Debug";
|
||||||
buildRelease = mkBuildScript "Release";
|
buildRelease = mkBuildScript "Release";
|
||||||
|
|
||||||
# Use this to specify commands that should be ran after entering fish shell
|
# Add project-local fish abbrs here
|
||||||
initProjectShell = pkgs.writers.writeFish "init-shell.fish" ''
|
abbrs = {
|
||||||
echo "Entering \"${description}\" environment..."
|
fail = "perl ./scripts/menu.pl";
|
||||||
|
|
||||||
# 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"
|
|
||||||
|
|
||||||
# C/C++:
|
# C/C++:
|
||||||
# abbr -a cmake-debug "${cmakeDebug}"
|
# cmake-debug = "${cmakeDebug}";
|
||||||
# abbr -a cmake-release "${cmakeRelease}"
|
# cmake-release = "${cmakeRelease}";
|
||||||
# abbr -a build-debug "${buildDebug}"
|
# build-debug = "${buildDebug}";
|
||||||
# abbr -a build-release "${buildRelease}"
|
# 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
|
in
|
||||||
builtins.concatStringsSep "\n" [
|
builtins.concatStringsSep "\n" [
|
||||||
# Launch into pure fish shell
|
# 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