Skip to content

nixos/etc: switching configuration with etc.overlay breaks cwd #477628

@Majiir

Description

@Majiir

Nixpkgs version

  • Stable (25.11)

Describe the bug

When the current working directory is in /etc and you switch to a new configuration that remounts /etc (with etc.overlay), some applications break because getcwd returns an error.

Steps to reproduce

  1. cd somewhere in /etc
  2. nixos-rebuild test to a config that changes /etc so it remounts
  3. python -c 'import os; print(os.getcwd())'

For a real application that breaks, try jj.

Expected behaviour

Switching configuration should not break an open directory that is present in both the old and new /etc.

Screenshots

No response

Relevant log output

[nix-shell:/etc/nixos]$ pwd
/etc/nixos

[nix-shell:/etc/nixos]$ echo $PWD
/etc/nixos

[nix-shell:/etc/nixos]$ python -c 'import os; print(os.getcwd())'
/etc/nixos

[nix-shell:/etc/nixos]$ nixos-rebuild test --sudo
building the system configuration...
activating the configuration...
remounting /etc...
Moving mount
Mounting beneath top mount
Attaching mount /run/nixos-etc.kQvjgZCHpo -> /etc
Moving single attached mount
reloading user units for majiirpaktu...
restarting sysinit-reactivation.target
the following new units were started: run-keys.mount, run-nixos\x2detc\x2dmetadata.r6kDbokHLZ.mount, sysinit-reactivation.target, systemd-tmpfiles-resetup.service
Done. The new configuration is /nix/store/xy39zvnc2kzif9q2955fvhzbcx79jny2-nixos-system-server-25.11.20251223.76701a1

[nix-shell:/etc/nixos]$ pwd
/etc/nixos

[nix-shell:/etc/nixos]$ echo $PWD
/etc/nixos

[nix-shell:/etc/nixos]$ python -c 'import os; print(os.getcwd())'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import os; print(os.getcwd())
                     ~~~~~~~~~^^
FileNotFoundError: [Errno 2] No such file or directory

[nix-shell:/etc/nixos]$ cd /etc/nixos

[nix-shell:/etc/nixos]$ python -c 'import os; print(os.getcwd())'
/etc/nixos

[nix-shell:/etc/nixos]$ jj
Error: Could not determine current directory
Hint: Did you update to a commit where the directory doesn't exist or can't be accessed?

Additional context

Since we put the config in /etc/nixos by default, it's probably not uncommon that a user would hit this situation.

System metadata

  • system: "x86_64-linux"
  • host os: Linux 6.12.63, NixOS, 25.11 (Xantusia), 25.11.20251223.76701a1
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.31.2

Notify maintainers

@nikstur


Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)

I assert that this issue is relevant for Nixpkgs

Is this issue important to you?

Add a 👍 reaction to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bugSomething is broken6.topic: nixosIssues or PRs affecting NixOS modules, or package usability issues specific to NixOS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions