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

multi-user-installer: restore copy-to-store idempotence? #6679

Open
abathur opened this issue Jun 16, 2022 · 5 comments · May be fixed by #7603
Open

multi-user-installer: restore copy-to-store idempotence? #6679

abathur opened this issue Jun 16, 2022 · 5 comments · May be fixed by #7603

Comments

@abathur
Copy link
Member

abathur commented Jun 16, 2022

Before #5150, this section of the multi-user installer used rsync and was (IIRC) ~idempotent:

install_from_extracted_nix() {
task "Installing Nix"
(
cd "$EXTRACTED_NIX_PATH"
_sudo "to copy the basic Nix files to the new store at $NIX_ROOT/store" \
cp -RPp ./store/* "$NIX_ROOT/store/"
_sudo "to make the new store non-writable at $NIX_ROOT/store" \
chmod -R ugo-w "$NIX_ROOT/store/"

Dropping the rsync dependency to support debian makes sense, but it would be nice to figure out whether we can portably make this step idempotent again--and do it, if it's simple enough.

Shooting from the hip:

  • this might be as simple as using cp's -f flag, if it's portable?
  • it's probably not as simple as just ignoring the exit code from cp, since there could be other issues
  • it's probably not as simple as just diffing the directories, since an existing store will contain more than the store seed

(If we can't do this without, say, wiping the store or restoring the rsync dependency, we should probably figure out how to fail faster until we can find another approach.)

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/small-installer-idempotence-fix/19791/1

@brejoc
Copy link

brejoc commented Sep 28, 2022

Due to this change I ran into a problem relate to this on macOS today. Because of an update the changes in /etc/zshrc got wiped. In matrix someone suggested to just reinstall. I know that running the installer again worked in the past. This time it failed with an cp: cannot overwrite directory error.

~~> Installing Nix

---- sudo execution ------------------------------------------------------------
I am executing:

    $ sudo cp -RPp ./store/0ky7rhm0ckf4vw7vg2v5cyarrbsblvmj-aws-crt-cpp-0.17.28 ./store/1dcbaii28xnv98zw2w5f0skn2mar1ck8-aws-c-auth-0.6.13 ./store/2033pdgsv4wgl0zx6nng9i8q5f4h18lk-libidn2-2.3.2 ./store/2im4pw4pl5zsr6mjhwrjfcinrl9qljhy-nss-cacert-3.80 ./store/3b8r3yspv7f7p92jfxg548cfxi7q19d7-bash-5.1-p16 ./store/3k2ygb7mk9ylm2r5g0iad7akg1qwas4g-libssh2-1.10.0 ./store/3qcn93slgnm0wz74fq3nsd2942k3vsfm-aws-c-cal-0.5.17 ./store/58ppyba9pbc8yxqiw11gv9aw2adh1lgg-libxml2-2.9.14 ./store/6d17z21w7h8vmpsnmr8dm73sb3mvkpp0-nlohmann_json-3.10.5 ./store/789cl5k5ca0m9sxkiqyl4ackv5f0cmfz-aws-sdk-cpp-1.9.238 ./store/79z2m5vwbqwzrmfsbbv6rvk04z2nzf0x-curl-7.83.1 ./store/7hn69mlypdg285ar3ia71prgcrsx521g-libiconv-50 ./store/7m37v9mnii266p2l21xl97s4666f7d2s-libarchive-3.6.1-lib ./store/7vfyla60szbi8h35q93mrsij6whb3q9q-aws-c-compression-0.2.14 ./store/8yr5vy7jasrizvnvm9d12iynbbvf8r3p-nghttp2-1.47.0-lib ./store/962rka435k9c9p5ng1z2y3gspi4gs7hr-libcxxabi-11.1.0 ./store/9h5pks3l96gkp7653x4jxsfz1ca41fdc-aws-c-io-0.11.0 ./store/9jzvhm113w1xndcc5p4lvbqpqvk01c17-aws-c-mqtt-0.7.10 ./store/9x2z66kf8g8p9y1bxkraspghsy8jb5nj-zstd-1.5.2 ./store/a08j7vsgfcvzx0ahl986v38mjrx3gkm0-brotli-1.0.9-lib ./store/blnw8pnh6srwwr31g23mh6b70g6viaam-libcxx-11.1.0 ./store/cfc8xcp3q1ccx9wrfkbagia95w6rsvsh-apple-framework-Security-11.0.0 ./store/cpl9nndqjgn238p3kdwws845gscavfh4-sqlite-3.38.5 ./store/czwp4nmcn5skjiylhbyhg5k21wv76w9j-libsodium-1.0.18 ./store/d1hxdg09lxql958cmnrjq68alnd73i39-aws-c-s3-0.1.39 ./store/dg4r67wwna6sb2drh7gj38byq91ix2z9-aws-c-common-0.7.0 ./store/dmk5m3nlqp1awaqrp1f06qhhkh3l102n-nix-2.11.1 ./store/gwxhwcf0m9yrhz5wql1181bjfp654m1b-zlib-1.2.12 ./store/h9z5lncphgm9if86wxrfqg7w7fv7khbh-libkrb5-1.19.3 ./store/jgwmpgiin89dp0jjpjlwily6fgj1xs1a-aws-c-sdkutils-0.1.2 ./store/kd48xgjihd6sz5gvf2bvj7kw7m7ybhmf-xz-5.2.5 ./store/n2bygl2nqg7r35mg4ny45cwkarxgx2xb-curl-7.83.1 ./store/nf20p297fz6sfs97m7rl7al9ywchi83n-openssl-1.1.1q ./store/p7755cvgiwvv6lvin1r25jy711p8fn2n-libunistring-1.0 ./store/r6y0rvzx8z9z459ghmj1zrnpi4r7xa5v-aws-checksums-0.1.12 ./store/s5ikc3jlv67j9bm8463rjz3x09lcwm8v-aws-c-http-0.6.15 ./store/v2p3injpwnyf31vfllpz2k172mr58fn9-apple-lib-libDER ./store/vzbnm6afkdcbgb57npl06gk7rsap4sfy-apple-framework-CoreFoundation-11.0.0 ./store/w18g47jdi000hq064cb83j42kmbc4k3s-editline-1.17.1 ./store/w5n081lpdyhc5aa69cq59j9s1h626jgj-apple-framework-IOKit-11.0.0 ./store/xi7bwrkki4fwr6zam7gmcklnqq3f3d5h-aws-c-event-stream-0.2.7 ./store/y9j96x0zkxwwbqknr66r7bwczlxa4kk6-bzip2-1.0.6.0.2 ./store/y9rzzima6wdy0ph29ff09hr8vadfkx16-libobjc-11.0.0 ./store/z1l79b1phxy2yzcwsvn0ar121gcnh0x6-boehm-gc-8.0.6 /nix/store/

to copy the basic Nix files to the new store at /nix/store

cp: cannot overwrite directory /nix/store/cfc8xcp3q1ccx9wrfkbagia95w6rsvsh-apple-framework-Security-11.0.0/Library/Frameworks/Security.framework/Versions/Current with non-directory ./store/cfc8xcp3q1ccx9wrfkbagia95w6rsvsh-apple-framework-Security-11.0.0/Library/Frameworks/Security.framework/Versions/Current
cp: cannot overwrite directory /nix/store/cfc8xcp3q1ccx9wrfkbagia95w6rsvsh-apple-framework-Security-11.0.0/Library/Frameworks/Security.framework/Headers with non-directory ./store/cfc8xcp3q1ccx9wrfkbagia95w6rsvsh-apple-framework-Security-11.0.0/Library/Frameworks/Security.framework/Headers
cp: cannot overwrite directory /nix/store/cfc8xcp3q1ccx9wrfkbagia95w6rsvsh-apple-framework-Security-11.0.0/Library/Frameworks/Security.framework/Modules with non-directory ./store/cfc8xcp3q1ccx9wrfkbagia95w6rsvsh-apple-framework-Security-11.0.0/Library/Frameworks/Security.framework/Modules
cp: cannot overwrite directory /nix/store/h9z5lncphgm9if86wxrfqg7w7fv7khbh-libkrb5-1.19.3/sbin with non-directory ./store/h9z5lncphgm9if86wxrfqg7w7fv7khbh-libkrb5-1.19.3/sbin
cp: cannot overwrite directory /nix/store/vzbnm6afkdcbgb57npl06gk7rsap4sfy-apple-framework-CoreFoundation-11.0.0/Library/Frameworks/CoreFoundation.framework/Versions/Current with non-directory ./store/vzbnm6afkdcbgb57npl06gk7rsap4sfy-apple-framework-CoreFoundation-11.0.0/Library/Frameworks/CoreFoundation.framework/Versions/Current
cp: cannot overwrite directory /nix/store/vzbnm6afkdcbgb57npl06gk7rsap4sfy-apple-framework-CoreFoundation-11.0.0/Library/Frameworks/CoreFoundation.framework/Headers with non-directory ./store/vzbnm6afkdcbgb57npl06gk7rsap4sfy-apple-framework-CoreFoundation-11.0.0/Library/Frameworks/CoreFoundation.framework/Headers
cp: cannot overwrite directory /nix/store/vzbnm6afkdcbgb57npl06gk7rsap4sfy-apple-framework-CoreFoundation-11.0.0/Library/Frameworks/CoreFoundation.framework/Modules with non-directory ./store/vzbnm6afkdcbgb57npl06gk7rsap4sfy-apple-framework-CoreFoundation-11.0.0/Library/Frameworks/CoreFoundation.framework/Modules
cp: cannot overwrite directory /nix/store/w5n081lpdyhc5aa69cq59j9s1h626jgj-apple-framework-IOKit-11.0.0/Library/Frameworks/IOKit.framework/Versions/Current with non-directory ./store/w5n081lpdyhc5aa69cq59j9s1h626jgj-apple-framework-IOKit-11.0.0/Library/Frameworks/IOKit.framework/Versions/Current
cp: cannot overwrite directory /nix/store/w5n081lpdyhc5aa69cq59j9s1h626jgj-apple-framework-IOKit-11.0.0/Library/Frameworks/IOKit.framework/Headers with non-directory ./store/w5n081lpdyhc5aa69cq59j9s1h626jgj-apple-framework-IOKit-11.0.0/Library/Frameworks/IOKit.framework/Headers
cp: cannot overwrite directory /nix/store/w5n081lpdyhc5aa69cq59j9s1h626jgj-apple-framework-IOKit-11.0.0/Library/Frameworks/IOKit.framework/Modules with non-directory ./store/w5n081lpdyhc5aa69cq59j9s1h626jgj-apple-framework-IOKit-11.0.0/Library/Frameworks/IOKit.framework/Modules

---- oh no! --------------------------------------------------------------------
Jeeze, something went wrong. If you can take all the output and open
an issue, we'd love to fix the problem so nobody else has this issue.

:(

PS: For my original problem it's of course it's much easier to add the three lines to /etc/zshrc again.

@abathur
Copy link
Member Author

abathur commented Sep 28, 2022

Yes, restoring the hook is the right approach for now.

This cp case is a regression, but IIRC it isn't the only idempotence problem in the installer (you'd still run into issues with nix already being in /etc/bashrc and the presence of the plist for the nix-daemon LaunchDaemon, I think).

Until it can be made idempotent, it's best to follow the uninstall instructions before reinstalling it: https://nixos.org/manual/nix/stable/installation/installing-binary.html#macos

@brejoc
Copy link

brejoc commented Sep 29, 2022

@abathur You are right, there are more idempotency problems. But those can quit easily be circumnavigated. This one not.

Thanks for the link to the uninstall instructions. That's quite handy!

iFreilicht added a commit to iFreilicht/nix that referenced this issue Jan 15, 2023
@iFreilicht iFreilicht linked a pull request Jan 15, 2023 that will close this issue
@iFreilicht
Copy link
Contributor

#7603 should fix this.

iFreilicht added a commit to iFreilicht/nix that referenced this issue Jan 31, 2023
Fixes NixOS#6679 and all issues that contain
`cp: cannot overwrite directory ... with non-directory` errors.
These were caused by 475fc10 and
bb0c4b9. Or rather, installations after
475fc10 erroneously followed and deep-copied symlinks, which was fixed
in bb0c4b9. This meant installations installed with the installer
released between these commits had some paths in their nix store with
directories where symlinks should have been, causing the fixed installer
to try to overwrite them with symlinks.

The -n will not overwrite existing files, which is fine inside of the
nix-store as identical store paths will have identical content.
iFreilicht added a commit to iFreilicht/nix that referenced this issue Jan 31, 2023
Fixes NixOS#6679 and all issues that contain
`cp: cannot overwrite directory ... with non-directory` errors.
These were caused by 475fc10 and
bb0c4b9. Or rather, installations after
475fc10 erroneously followed and deep-copied symlinks, which was fixed
in bb0c4b9. This meant installations installed with the installer
released between these commits had some paths in their nix store with
directories where symlinks should have been, causing the fixed installer
to try to overwrite them with symlinks.

The -n will not overwrite existing files, which is fine inside of the
nix-store as identical store paths will have identical content.

For additional details and examples, see
NixOS#7603 (comment)
iFreilicht added a commit to iFreilicht/nix that referenced this issue Jun 20, 2023
Fixes NixOS#6679 and all issues that contain
`cp: cannot overwrite directory ... with non-directory` errors.
These were caused by 475fc10 and
bb0c4b9. Or rather, installations after
475fc10 erroneously followed and deep-copied symlinks, which was fixed
in bb0c4b9. This meant installations installed with the installer
released between these commits had some paths in their nix store with
directories where symlinks should have been, causing the fixed installer
to try to overwrite them with symlinks.

The -n will not overwrite existing files, which is fine inside of the
nix-store as identical store paths will have identical content.

For additional details and examples, see
NixOS#7603 (comment)
iFreilicht added a commit to iFreilicht/nix that referenced this issue Jun 27, 2023
Fixes NixOS#6679 and all issues that contain
`cp: cannot overwrite directory ... with non-directory` errors.
These were caused by 475fc10 and
bb0c4b9. Or rather, installations after
475fc10 erroneously followed and deep-copied symlinks, which was fixed
in bb0c4b9. This meant installations installed with the installer
released between these commits had some paths in their nix store with
directories where symlinks should have been, causing the fixed installer
to try to overwrite them with symlinks.

The -n will not overwrite existing files, which is fine inside of the
nix-store as identical store paths will have identical content.

For additional details and examples, see
NixOS#7603 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants