Skip to content

shellHook's trap _ides_leave EXIT breaks direnv environment capture #1

Description

@wanderer

Bug Description

When mkIdes is used in a flake devShell together with direnv's use flake, the ides shellHook sets trap _ides_leave EXIT, which overrides direnv's internal EXIT trap. Direnv relies on this trap to capture the environment state after .envrc finishes executing. With the trap overridden, direnv captures nothing — no PATH, no environment variables, nothing — making the nix dev shell completely invisible to the shell (fish, bash, zsh).

Steps to Reproduce

  1. Create a flake with a devShell using mkIdes:
devShells.default = mkIdes {
  serviceDefs.foo = {
    shellCommand = "echo hello";
    systemd.remainAfterExit = true;
  };
  shellHook = ''
    export MY_VAR=hello
  '';
  packages = [ pkgs.some-tool ];
};
  1. Add .envrc:
use flake
  1. Run direnv allow and check what direnv exports:
direnv export json | python3 -c "import sys,json; print(sorted(json.load(sys.stdin).keys()))"

Environment

  • ides: from github:manic-systems/ides (used via flake input)
  • direnv: 2.37.1
  • nix-direnv: 3.1.2
  • OS: NixOS (linux)
  • Shell: fish 3.x (also reproduces in bash)

Workaround

Save and restore direnv's EXIT trap around use flake in .envrc:

# shellcheck shell=bash
_direnv_exit_trap=$(trap -p EXIT)
use flake
eval "$_direnv_exit_trap"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions