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

Move the default profiles to the user’s home #5226

Merged
merged 5 commits into from
Jan 30, 2023
Merged

Conversation

thufschmitt
Copy link
Member

Rather than using /nix/var/nix/{profiles,gcroots}/per-user/, put the user
profiles and gcroots under $XDG_DATA_DIR/nix/{profiles,gcroots}.

This means that the daemon no longer needs to manage these paths itself
(they are fully handled client-side). In particular, it doesn’t have to
chown them anymore (removing one need for root).

This does change the layout of the gc-roots created by nix-env, and is
likely to break some stuff, so I’m not sure how to properly handle that.

First step towards #5208

@edolstra edolstra added this to the nix-3.0 milestone Sep 8, 2021
@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/tweag-nix-dev-update-17/15037/1

@edolstra edolstra modified the milestones: nix-2.5, nix-2.6 Dec 13, 2021
@edolstra edolstra modified the milestones: nix-2.6, nix-2.7 Jan 21, 2022
@edolstra edolstra modified the milestones: nix-2.7, nix-2.8 Mar 3, 2022
@thufschmitt thufschmitt force-pushed the client-side-profiles branch 4 times, most recently from 1d719a6 to b6f17b8 Compare April 13, 2022 08:26
@edolstra edolstra modified the milestones: nix-2.8, nix-2.9 Apr 14, 2022
@edolstra edolstra modified the milestones: nix-2.9, nix-2.10 May 27, 2022
@edolstra edolstra modified the milestones: nix-2.10, nix-2.11 Jul 11, 2022
@edolstra edolstra modified the milestones: nix-2.11, nix-2.12 Aug 25, 2022
@fricklerhandwerk fricklerhandwerk added the UX The way in which users interact with Nix. Higher level than UI. label Sep 9, 2022
@edolstra edolstra modified the milestones: nix-2.12, nix-2.13 Dec 6, 2022
@rycee
Copy link
Member

rycee commented Mar 4, 2023

I'm looking at how to adapt Home Manager to this change. Should I use some HM specific directory to keep the profile and gcroot? E.g. $XDG_DATA_DIR/home-manager/{profiles,gcroots}. And nix-collect-garbage will automatically handle the profile but leave the gcroot alone? Or should I put the HM profile and gcroot in $XDG_DATA_DIR/nix/{profiles,gcroots}?

Also, this commit doesn't seem to contain any documentation updates. Are those in a separate PR?

@rycee
Copy link
Member

rycee commented Mar 4, 2023

Hmm, I had a look at nix-collect-garbage.cc and it seems to me that it will only delete old profile generations if they are present in the Nix state dir? If so, won't it also fail to expire old user profiles after this migration? I'm not very familiar with the Nix code, though, so I may be completely mistaken here.

renovate bot added a commit to bobvanderlinden/nixpkgs-ruby that referenced this pull request Mar 4, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[cachix/install-nix-action](https://github.com/cachix/install-nix-action)
| action | major | `v19` -> `v20` |

---

### Release Notes

<details>
<summary>cachix/install-nix-action</summary>

###
[`v20`](https://github.com/cachix/install-nix-action/releases/tag/v20):
install-nix-action-v20

[Compare
Source](https://github.com/cachix/install-nix-action/compare/v19...v20)

https://discourse.nixos.org/t/nix-2-14-0-released/25900/4Fix support for
Nix 2.14 new profile location:
[NixOS/nix#5226

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "every weekend" (UTC), Automerge - At
any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/bobvanderlinden/nixpkgs-ruby).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xNTQuNiIsInVwZGF0ZWRJblZlciI6IjM0LjE1NC42In0=-->
@thiagokokada
Copy link

thiagokokada commented Mar 4, 2023

This makes the assumptions in https://github.com/nix-community/home-manager/blob/master/modules/lib-bash/activation-init.sh invalid, causing failures like https://github.com/nix-community/home-manager/actions/runs/4301868239/jobs/7499628919#step:8:260. How do we migrate smoothly?

Interesting. I just hit this issue when trying to use the Nix static inside a Steam Deck, with the store inside $HOME (introduced in https://discourse.nixos.org/t/nix-2-10-0-released/20291). While it is unfortunate that this bug was introduced, having this being worked (and eventually fixed) can be exciting.

@fricklerhandwerk
Copy link
Contributor

@rycee Apparently this still needs more work on our side. Please open an issue so we can discuss it on the team.

PetarKirov added a commit to PetarKirov/dotfiles that referenced this pull request Mar 5, 2023
PetarKirov added a commit to PetarKirov/dotfiles that referenced this pull request Mar 5, 2023
thufschmitt added a commit to tweag/nix that referenced this pull request Mar 7, 2023
thufschmitt added a commit to tweag/nix that referenced this pull request Mar 7, 2023
github-actions bot pushed a commit that referenced this pull request Mar 8, 2023
@thufschmitt thufschmitt mentioned this pull request Mar 8, 2023
7 tasks
mmlb added a commit to mmlb/each-commit-green that referenced this pull request Mar 9, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[cachix/install-nix-action](https://github.com/cachix/install-nix-action)
| action | major | `v19` -> `v20` |

---

### Release Notes

<details>
<summary>cachix/install-nix-action</summary>

###
[`v20`](https://github.com/cachix/install-nix-action/releases/tag/v20):
install-nix-action-v20

[Compare
Source](https://github.com/cachix/install-nix-action/compare/v19...v20)

https://discourse.nixos.org/t/nix-2-14-0-released/25900/4Fix support for
Nix 2.14 new profile location:
[NixOS/nix#5226

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/mmlb/each-commit-green).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xNTkuMCIsInVwZGF0ZWRJblZlciI6IjM0LjE1OS4wIn0=-->
@thufschmitt thufschmitt mentioned this pull request Mar 20, 2023
7 tasks
@Ericson2314 Ericson2314 mentioned this pull request Mar 20, 2023
7 tasks
PetarKirov added a commit to metacraft-labs/nix-blockchain-development that referenced this pull request Apr 13, 2023
PetarKirov added a commit to metacraft-labs/nix-blockchain-development that referenced this pull request Apr 13, 2023
@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/nix-team-report-2022-10-2023-03/27486/1

thufschmitt pushed a commit to tweag/nix that referenced this pull request Aug 1, 2023
Move the default profiles to the user’s home
rvem added a commit to serokell/deploy-rs that referenced this pull request Sep 6, 2023
Problem: Since NixOS/nix#5226 nix profiles for
users are stored in 'XDG_STATE_HOME' or 'HOME' directory. However,
'deploy-rs' still expects profiles to be present in
'/nix/var/nix/profiles/per-user'. As a result, an attempt to deploy a
profile with newer nix may fail with an error about non-existing files.

Solution: Instead of deducing the profile path prior to ssh'ing and
actual activation, deduce the path to the profile during as a part of
'activate-rs' invocation.

Now if the profile path is not specified explicitly as an attribute in
profile within the deploy flake, the path to the profile is determined
based on the user to which the profile belongs and on the values of
'XDG_STATE_HOME' and 'HOME' variables.
Additionally, if the old profile directory (in
'/nix/var/nix/profiles/per-user') for a given user already exists, it is
used instead for the sake of backward compatibility.
rvem added a commit to serokell/deploy-rs that referenced this pull request Sep 6, 2023
Problem: Since NixOS/nix#5226 nix profiles for
users are stored in 'XDG_STATE_HOME' or 'HOME' directory. However,
'deploy-rs' still expects profiles to be present in
'/nix/var/nix/profiles/per-user'. As a result, an attempt to deploy a
profile with newer nix may fail with an error about non-existing files.

Solution: Instead of deducing the profile path prior to ssh'ing and
actual activation, deduce the path to the profile during as a part of
'activate-rs' invocation.

Now if the profile path is not specified explicitly as an attribute in
profile within the deploy flake, the path to the profile is determined
based on the user to which the profile belongs and on the values of
'XDG_STATE_HOME' and 'HOME' variables.
Additionally, if the old profile directory (in
'/nix/var/nix/profiles/per-user') for a given user already exists, it is
used instead for the sake of backward compatibility.
rvem added a commit to serokell/deploy-rs that referenced this pull request Sep 11, 2023
Problem: Since NixOS/nix#5226 nix profiles for
users are stored in 'XDG_STATE_HOME' or 'HOME' directory. However,
'deploy-rs' still expects profiles to be present in
'/nix/var/nix/profiles/per-user'. As a result, an attempt to deploy a
profile with newer nix may fail with an error about non-existing files.

Solution: Instead of deducing the profile path prior to ssh'ing and
actual activation, deduce the path to the profile during as a part of
'activate-rs' invocation.

Now if the profile path is not specified explicitly as an attribute in
profile within the deploy flake, the path to the profile is determined
based on the user to which the profile belongs and on the values of
'XDG_STATE_HOME' and 'HOME' variables.
Additionally, if the old profile directory (in
'/nix/var/nix/profiles/per-user') for a given user already exists, it is
used instead for the sake of backward compatibility.
rvem added a commit to serokell/deploy-rs that referenced this pull request Sep 11, 2023
Problem: Since NixOS/nix#5226 nix profiles for
users are stored in 'XDG_STATE_HOME' or 'HOME' directory. However,
'deploy-rs' still expects profiles to be present in
'/nix/var/nix/profiles/per-user'. As a result, an attempt to deploy a
profile with newer nix may fail with an error about non-existing files.

Solution: Instead of deducing the profile path prior to ssh'ing and
actual activation, deduce the path to the profile during as a part of
'activate-rs' invocation.

Now if the profile path is not specified explicitly as an attribute in
profile within the deploy flake, the path to the profile is determined
based on the user to which the profile belongs and on the values of
'XDG_STATE_HOME' and 'HOME' variables.
Additionally, if the old profile directory (in
'/nix/var/nix/profiles/per-user') for a given user already exists, it is
used instead for the sake of backward compatibility.
rvem added a commit to serokell/deploy-rs that referenced this pull request Sep 12, 2023
Problem: Since NixOS/nix#5226 nix profiles for
users are stored in 'XDG_STATE_HOME' or 'HOME' directory. However,
'deploy-rs' still expects profiles to be present in
'/nix/var/nix/profiles/per-user'. As a result, an attempt to deploy a
profile with newer nix may fail with an error about non-existing files.

Solution: Instead of deducing the profile path prior to ssh'ing and
actual activation, deduce the path to the profile during as a part of
'activate-rs' invocation.

Now if the profile path is not specified explicitly as an attribute in
profile within the deploy flake, the path to the profile is determined
based on the user to which the profile belongs and on the values of
'XDG_STATE_HOME' and 'HOME' variables.
Additionally, if the old profile directory (in
'/nix/var/nix/profiles/per-user') for a given user already exists, it is
used instead for the sake of backward compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
UX The way in which users interact with Nix. Higher level than UI.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

7 participants