Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos-install: clear executable cache after entering chroot #355269

Merged
merged 2 commits into from
Dec 15, 2024

Conversation

xaverdh
Copy link
Contributor

@xaverdh xaverdh commented Nov 11, 2024

Clear the cache for executable locations after entering the chroot. The cached locations are no longer valid there.

This hopefully indeed resolves problems with nixos-install failing to find binaries from coreutils as witnessed in #241356 fixing it.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

Clear the cache for executable locations after entering the chroot. The cached locations are no longer valid there.

This resolves problems with nixos-install failing to find binaries from coreutils as witnessed in NixOS#241356.
@xaverdh
Copy link
Contributor Author

xaverdh commented Nov 11, 2024

PS: if you try to reproduce that executable caching behavior of bash, you need to run it in non-interactive mode (i.e. bash -c '...'). In interactive mode, it will disable the executable cache.

@poliorcetics
Copy link

@xaverdh first time I'm testing such a PR, how can I declare my nixpkgs as pointing to yours ?

I'm using flakes if that helps.

@xaverdh
Copy link
Contributor Author

xaverdh commented Dec 9, 2024

@xaverdh first time I'm testing such a PR, how can I declare my nixpkgs as pointing to yours ?

I'm using flakes if that helps.

You can build the nixos-install script from this pr with

nix build github:NixOS/nixpkgs/refs/pull/355269/head#nixos-install

and then run ./result/bin/nixos-install

@poliorcetics
Copy link

poliorcetics commented Dec 10, 2024

Confirmed working on my use case, I don't get the "X not in PATH" error with this MR and I get it on regular nixpkgs

@xaverdh xaverdh marked this pull request as ready for review December 10, 2024 18:11
@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Dec 10, 2024
@xaverdh
Copy link
Contributor Author

xaverdh commented Dec 11, 2024

cc @Mic92

@poliorcetics
Copy link

poliorcetics commented Dec 11, 2024

Using

    overlays = [
      # <https://github.com/NixOS/nixpkgs/pull/355269>
      (final: super: {
        nixos-install = super.nixos-install.overrideAttrs (old: {
          patches = old.patches or [ ] ++ [ ../patches/nixos-install-no-coreutils-caching.patch ];
        });
      })
    ];

with the most recent nixpkgs-unstable did not work.

I took the patch from https://github.com/NixOS/nixpkgs/pull/355269.patch

I may have done something wrong, but I'm unsure what if so

@wegank wegank removed the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Dec 11, 2024
@xaverdh
Copy link
Contributor Author

xaverdh commented Dec 14, 2024

Using

    overlays = [
      # <https://github.com/NixOS/nixpkgs/pull/355269>
      (final: super: {
        nixos-install = super.nixos-install.overrideAttrs (old: {
          patches = old.patches or [ ] ++ [ ../patches/nixos-install-no-coreutils-caching.patch ];
        });
      })
    ];

with the most recent nixpkgs-unstable did not work.

I took the patch from https://github.com/NixOS/nixpkgs/pull/355269.patch

I may have done something wrong, but I'm unsure what if so

can you see the patch getting applied (in the build output)?

@xaverdh
Copy link
Contributor Author

xaverdh commented Dec 14, 2024

ofborg failure appears unrelated?

@tom-kuca
Copy link
Contributor

I run into the issue, the patch didn't fix it for me.

Command:

sudo ./result/bin/nixos-install --flake '.#voyager' --verbose --debug

Output:

+ nixos-enter --root /mnt -c '      set -e
      # Clear the cache for executable locations. They were invalidated by the chroot.
      hash -r
      # Create a bind mount for each of the mount points inside the target file
      # system. This preserves the validity of their absolute paths after changing
      # the root with `nixos-enter`.
      # Without this the bootloader installation may fail due to options that
      # contain paths referenced during evaluation, like initrd.secrets.
      # when not root, re-execute the script in an unshared namespace
      mount --rbind --mkdir / "$mountPoint"
      mount --make-rslave "$mountPoint"
      /run/current-system/bin/switch-to-configuration boot
      umount -R "$mountPoint" && (rmdir "$mountPoint" 2>/dev/null || true)'
perl: warning: Setting locale failed.
... perl complains ...
/nix/var/nix/profiles/system/sw/bin/bash: line 10: mount: command not found

I see the same error without the patch, only on line 8.

I'm on arch linux. I run into it when I tried to setup a new system using disko-install, later I tried nixos-install directly.

@Mic92
Copy link
Member

Mic92 commented Dec 15, 2024

The original bug fix was for coreutils. Not finding mount might be a different bug.

@Mic92 Mic92 merged commit c142740 into NixOS:master Dec 15, 2024
21 of 23 checks passed
@xaverdh
Copy link
Contributor Author

xaverdh commented Dec 15, 2024

@ tom-kuca can you try adding

. /etc/profile

right after (or instead of) hash -r in that script?

@tom-kuca
Copy link
Contributor

@xaverdh It works, the script finishes successfuly.

@xaverdh xaverdh deleted the nixos-install-no-coreutils-caching branch December 15, 2024 17:49
@xaverdh
Copy link
Contributor Author

xaverdh commented Dec 15, 2024

here you go: #365403

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants