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

Support for SteamOS Nix Offload in SteamOS 20230522.1000 #495

Conversation

Hoverbear
Copy link
Contributor

Description

Fixes #474

Before I undraft I need to figure out a good story for users who might have nix installed when they update to this version...

Checklist
  • Formatted with cargo fmt
  • Built with nix build
  • Ran flake checks with nix flake check
  • Added or updated relevant tests (leave unchecked if not applicable)
  • Added or updated relevant documentation (leave unchecked if not applicable)
  • Linked to related issues (leave unchecked if not applicable)
Validating with install.determinate.systems

If a maintainer has added the upload to s3 label to this PR, it will become available for installation via install.determinate.systems:

curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix/pr/$PR_NUMBER | sh -s -- install

@Hoverbear Hoverbear self-assigned this May 30, 2023
@Hoverbear Hoverbear changed the title Hoverbear/ds 912 steamos beta or maybe just main branch installer conflict Support for SteamOS Nix Offload in SteamOS 20230522.1000 May 30, 2023
@Hoverbear
Copy link
Contributor Author

Hoverbear commented May 30, 2023

So I took a 20220425.2 build and installed Nix using v0.9.1, then I updated to 20230522.1000 following the instructions in this PR.

After rebooting into the new build, I confirmed that Nix still works.

(deck@steamdeck ~)$ nix run nixpkgs#hello
Hello, world!
(deck@steamdeck ~)$ systemctl status nix-daemon.service
● nix-daemon.service - Nix Daemon
     Loaded: loaded (/etc/systemd/system/nix-daemon.service; linked; preset: disabled)
     Active: active (running) since Tue 2023-05-30 10:11:08 PDT; 4min 16s ago
TriggeredBy: ● nix-daemon.socket
       Docs: man:nix-daemon
             https://nixos.org/manual
   Main PID: 4487 (nix-daemon)
      Tasks: 2 (limit: 9395)
     Memory: 6.9M
        CPU: 55ms
     CGroup: /system.slice/nix-daemon.service
             └─4487 nix-daemon --daemon

May 30 10:11:08 steamdeck systemd[1]: Started Nix Daemon.
May 30 10:11:08 steamdeck nix-daemon[4487]: accepted connection from pid 4484, user deck
May 30 10:15:17 steamdeck nix-daemon[4487]: accepted connection from pid 4564, user deck
(deck@steamdeck ~)$ systemctl status nix-directory.service
● nix-directory.service - Create a `/nix` directory to be used for bind mounting
     Loaded: loaded (/etc/systemd/system/nix-directory.service; static)
     Active: active (exited) since Tue 2023-05-30 10:09:32 PDT; 5min ago
   Main PID: 886 (code=exited, status=0/SUCCESS)
        CPU: 41ms

May 30 10:09:32 steamdeck systemd[1]: Starting Create a `/nix` directory to be used for bind mounting...
May 30 10:09:32 steamdeck chmod[879]: mode of '/nix' retained as 0755 (rwxr-xr-x)
May 30 10:09:32 steamdeck chown[883]: ownership of '/nix' retained as root
May 30 10:09:32 steamdeck chgrp[884]: group of '/nix' retained as root
May 30 10:09:32 steamdeck systemd[1]: Finished Create a `/nix` directory to be used for bind mounting.
(deck@steamdeck ~)$ systemctl status nix.mount
● nix.mount - Mount `/home/nix` on `/nix`
     Loaded: loaded (/proc/self/mountinfo; disabled; preset: disabled)
     Active: active (mounted) since Tue 2023-05-30 10:09:32 PDT; 6min ago
      Until: Tue 2023-05-30 10:09:32 PDT; 6min ago
      Where: /nix
       What: /dev/vda8
      Tasks: 0 (limit: 9395)
     Memory: 4.0K
        CPU: 1ms
     CGroup: /system.slice/nix.mount

May 30 10:09:32 steamdeck systemd[1]: Mounting Mount `/home/nix` on `/nix`...
May 30 10:09:32 steamdeck systemd[1]: Mounted Mount `/home/nix` on `/nix`.
(deck@steamdeck ~)$ cat /etc/os-release 
NAME="SteamOS"
PRETTY_NAME="SteamOS"
VERSION_CODENAME=holo
ID=steamos
ID_LIKE=arch
ANSI_COLOR="1;35"
HOME_URL="https://www.steampowered.com/"
DOCUMENTATION_URL="https://support.steampowered.com/"
SUPPORT_URL="https://support.steampowered.com/"
BUG_REPORT_URL="https://support.steampowered.com/"
LOGO=steamos
VARIANT_ID=steamdeck
BUILD_ID=20230522.1000
VERSION_ID=3.5

It uninstalled cleanly:

(deck@steamdeck ~)$ /nix/nix-installer uninstall
`nix-installer` needs to run as `root`, attempting to escalate now via `sudo`...
[sudo] password for deck: 
Nix uninstall plan (v0.9.1)

Planner: steam-deck (with default settings)

Planned actions:
* Disable (and stop) the systemd unit ensure-symlinked-units-resolve.service
* Unconfigure Nix daemon related settings with systemd
* Unconfigure the shell profiles
* Remove the Nix configuration in `/etc/nix/nix.conf`
* Unset the default Nix profile
* Remove the directory tree in `/nix`
* Delete group `nixbld` (GID 30000)
* Disable (and stop) the systemd unit nix.mount
* Delete file `/etc/systemd/system/ensure-symlinked-units-resolve.service`
* Delete file `/etc/systemd/system/nix.mount`
* Delete file `/etc/systemd/system/nix-directory.service`
* Remove the directory `/home/nix`


Proceed? ([Y]es/[n]o/[e]xplain): y
 INFO Revert: Remove directory `/nix/temp-install-dir`
 INFO Revert: Enable (and start) the systemd unit ensure-symlinked-units-resolve.service
 INFO Revert: Configure Nix daemon related settings with systemd
 INFO Revert: Configure Nix
 INFO Revert: Provision Nix
 INFO Revert: Enable (and start) the systemd unit nix.mount
 INFO Revert: Create or overwrite file `/etc/systemd/system/ensure-symlinked-units-resolve.service`
 INFO Revert: Create or overwrite file `/etc/systemd/system/nix.mount`
 INFO Revert: Create or overwrite file `/etc/systemd/system/nix-directory.service`
 INFO Revert: Create directory `/home/nix`
Nix was uninstalled successfully!

However it seems we aren't reloading systemd on uninstall. Checking nix.mount after shows:

(130)(deck@steamdeck ~)$ systemctl status nix.mount
Warning: The unit file, source configuration file or drop-ins of nix.mount changed on disk. Run 'systemctl daemon-reload' to reload units.
○ nix.mount - Mount `/home/nix` on `/nix`
     Loaded: loaded (/proc/self/mountinfo; disabled; preset: disabled)
     Active: inactive (dead) since Tue 2023-05-30 10:17:02 PDT; 55s ago
   Duration: 7min 29.668s
      Where: /nix
       What: /home/nix
        CPU: 3ms

May 30 10:09:32 steamdeck systemd[1]: Mounting Mount `/home/nix` on `/nix`...
May 30 10:09:32 steamdeck systemd[1]: Mounted Mount `/home/nix` on `/nix`.
May 30 10:17:02 steamdeck systemd[1]: Unmounting Mount `/home/nix` on `/nix`...
May 30 10:17:02 steamdeck systemd[1]: nix.mount: Deactivated successfully.
May 30 10:17:02 steamdeck systemd[1]: Unmounted Mount `/home/nix` on `/nix`.

I thought we did this:

if let Err(err) = execute_command(
Command::new("systemctl")
.process_group(0)
.arg("daemon-reload")
.stdin(std::process::Stdio::null()),
)
.await
{
errors.push(err);
}

... It seems the timing is wrong though. We need it to happen at the very end of the install. Dang.

Anyways, reloading:

(deck@steamdeck ~)$ systemctl daemon-reload
==== AUTHENTICATING FOR org.freedesktop.systemd1.reload-daemon ====
Authentication is required to reload the systemd state.
Authenticating as: Steam Deck User (deck)
Password: 
==== AUTHENTICATION COMPLETE ====
(deck@steamdeck ~)$ systemctl status nix.mount
○ nix.mount - SteamOS Offload - /nix
     Loaded: loaded (/usr/lib/systemd/system/nix.mount; disabled; preset: disabled)
     Active: inactive (dead) since Tue 2023-05-30 10:17:02 PDT; 2min 9s ago
   Duration: 7min 29.668s
      Where: /nix
       What: /home/.steamos/offload/nix
        CPU: 3ms

May 30 10:09:32 steamdeck systemd[1]: Mounting Mount `/home/nix` on `/nix`...
May 30 10:09:32 steamdeck systemd[1]: Mounted Mount `/home/nix` on `/nix`.
May 30 10:17:02 steamdeck systemd[1]: Unmounting Mount `/home/nix` on `/nix`...
May 30 10:17:02 steamdeck systemd[1]: nix.mount: Deactivated successfully.
May 30 10:17:02 steamdeck systemd[1]: Unmounted Mount `/home/nix` on `/nix`.

When I try to reinstall I can see the planner isn't quite picking up that we can use that offload. That's because /home/.steamos/offload/nix doesn't exist yet.

(deck@steamdeck ~)$ systemctl daemon-reload
==== AUTHENTICATING FOR org.freedesktop.systemd1.reload-daemon ====
Authentication is required to reload the systemd state.
Authenticating as: Steam Deck User (deck)
Password: 
==== AUTHENTICATION COMPLETE ====
(deck@steamdeck ~)$ systemctl status nix.mount
○ nix.mount - SteamOS Offload - /nix
     Loaded: loaded (/usr/lib/systemd/system/nix.mount; disabled; preset: disabled)
     Active: inactive (dead) since Tue 2023-05-30 10:17:02 PDT; 2min 9s ago
   Duration: 7min 29.668s
      Where: /nix
       What: /home/.steamos/offload/nix
        CPU: 3ms

May 30 10:09:32 steamdeck systemd[1]: Mounting Mount `/home/nix` on `/nix`...
May 30 10:09:32 steamdeck systemd[1]: Mounted Mount `/home/nix` on `/nix`.
May 30 10:17:02 steamdeck systemd[1]: Unmounting Mount `/home/nix` on `/nix`...
May 30 10:17:02 steamdeck systemd[1]: nix.mount: Deactivated successfully.
May 30 10:17:02 steamdeck systemd[1]: Unmounted Mount `/home/nix` on `/nix`.
(deck@steamdeck ~)$ ls /home/.steamos/offload/
opt/  root/ srv/  usr/  var/  

Rebooting, we can see that the nix.mount unit fails because we deleted the /nix folder:

(deck@steamdeck ~)$ systemctl status nix.mount
○ nix.mount - SteamOS Offload - /nix
     Loaded: loaded (/usr/lib/systemd/system/nix.mount; disabled; preset: disabled)
     Active: inactive (dead)
  Condition: start condition failed at Tue 2023-05-30 10:26:34 PDT; 1min 30s ago
             └─ ConditionPathExists=/nix was not met
      Where: /nix
       What: /home/.steamos/offload/nix

May 30 10:26:34 steamdeck systemd[1]: SteamOS Offload - /nix was skipped because of a failed condition check (ConditionPathExists=/nix).

We can remedy this:

(deck@steamdeck ~)$ sudo steamos-readonly disable
(deck@steamdeck ~)$ sudo mkdir -p /nix
(deck@steamdeck ~)$ sudo steamos-readonly enable

Then reboot, and install, getting the right plan:

(deck@steamdeck ~)$ ./nix-installer install steam-deck
`nix-installer` needs to run as `root`, attempting to escalate now via `sudo`...
[sudo] password for deck: 
Nix install plan (v0.9.1-unreleased)
Planner: steam-deck (with default settings)

Planned actions:
* Create or overwrite file `/etc/systemd/system/ensure-symlinked-units-resolve.service`
* Fetch `https://releases.nixos.org/nix/nix-2.15.0/nix-2.15.0-x86_64-linux.tar.xz` to `/nix/temp-install-dir`
* Create group `nixbld` (GID 30000)
* Create a directory tree in `/nix`
* Move the downloaded Nix into `/nix`
* Setup the default Nix profile
* Place the Nix configuration in `/etc/nix/nix.conf`
* Configure the shell profiles
* Configure Nix daemon related settings with systemd
* Enable (and start) the systemd unit ensure-symlinked-units-resolve.service
* Remove directory `/nix/temp-install-dir`


Proceed? ([Y]es/[n]o/[e]xplain): 

@Hoverbear
Copy link
Contributor Author

So that if you install nix, then upgrade SteamOS, then uninstall nix, you end up roughly here:

(1)(deck@steamdeck ~)$ systemctl status nix.mount
Warning: The unit file, source configuration file or drop-ins of nix.mount changed on disk. Run 'systemctl daemon-reload' to reload units.
○ nix.mount - Mount `/home/nix` on `/nix`
     Loaded: loaded (/proc/self/mountinfo; disabled; preset: disabled)
     Active: inactive (dead) since Wed 2023-05-31 12:04:25 PDT; 35min ago
   Duration: 1min 53.950s
      Where: /nix
       What: /home/nix
        CPU: 3ms

May 31 12:04:25 steamdeck systemd[1]: Unmounting Mount `/home/nix` on `/nix`...
May 31 12:04:25 steamdeck systemd[1]: nix.mount: Deactivated successfully.
May 31 12:04:25 steamdeck systemd[1]: Unmounted Mount `/home/nix` on `/nix`.

Because we aren't running systemctl daemon-reload at the end of uninstall.

After #495 we'll actually notify you are in this state:

(deck@steamdeck ~)$ ./nix-installer install steam-deck
`nix-installer` needs to run as `root`, attempting to escalate now via `sudo`...
[sudo] password for deck: 
Error: 
   0: Planner error
   1: Custom planner error
   2: Detected the SteamOS `nix.mount` unit exists, but `systemctl status nix.mount` returned a warning that `systemctl daemon-reload` should be run. Run `systemctl daemon-reload` and try again.

Location:
   src/cli/subcommand/install.rs:117

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

After you do that (or say, you uninstall then reboot) you'll see roughly this:

(deck@steamdeck ~)$ systemctl status nix.mount
○ nix.mount - SteamOS Offload - /nix
     Loaded: loaded (/usr/lib/systemd/system/nix.mount; enabled; preset: disabled)
     Active: inactive (dead) since Wed 2023-05-31 12:04:25 PDT; 56min ago
   Duration: 1min 53.950s
  Condition: start condition failed at Wed 2023-05-31 12:49:07 PDT; 11min ago
             └─ ConditionPathExists=/nix was not met
      Where: /nix
       What: /home/.steamos/offload/nix
        CPU: 3ms

May 31 12:04:25 steamdeck systemd[1]: Unmounting Mount `/home/nix` on `/nix`...
May 31 12:04:25 steamdeck systemd[1]: nix.mount: Deactivated successfully.
May 31 12:04:25 steamdeck systemd[1]: Unmounted Mount `/home/nix` on `/nix`.
May 31 12:49:07 steamdeck systemd[1]: SteamOS Offload - /nix was skipped because of a failed condition check (ConditionPathExists=/nix).
(3)(deck@steamdeck ~)$ ./nix-installer install steam-deck
`nix-installer` needs to run as `root`, attempting to escalate now via `sudo`...
[sudo] password for deck: 
Nix install plan (v0.9.1-unreleased)
Planner: steam-deck (with default settings)

Planned actions:
* Run `systemctl daemon-reload`
* Ensure SteamOS's `/nix` directory exists
* Enable (and start) the systemd unit nix.mount
* Create or overwrite file `/etc/systemd/system/ensure-symlinked-units-resolve.service`
* Fetch `https://releases.nixos.org/nix/nix-2.15.0/nix-2.15.0-x86_64-linux.tar.xz` to `/nix/temp-install-dir`
* Create group `nixbld` (GID 30000)
* Create a directory tree in `/nix`
* Move the downloaded Nix into `/nix`
* Setup the default Nix profile
* Place the Nix configuration in `/etc/nix/nix.conf`
* Configure the shell profiles
* Configure Nix daemon related settings with systemd
* Enable (and start) the systemd unit ensure-symlinked-units-resolve.service
* Remove directory `/nix/temp-install-dir`
* Run `systemctl daemon-reload`


Proceed? ([Y]es/[n]o/[e]xplain): y
 INFO Step: Run `systemctl daemon-reload`
 INFO Step: Ensure SteamOS's `/nix` directory exists
 INFO Step: Enable (and start) the systemd unit nix.mount
 INFO Step: Create or overwrite file `/etc/systemd/system/ensure-symlinked-units-resolve.service`
 INFO Step: Provision Nix
 INFO Step: Configure Nix
 INFO Step: Configure Nix daemon related settings with systemd
 INFO Step: Enable (and start) the systemd unit ensure-symlinked-units-resolve.service
 INFO Step: Remove directory `/nix/temp-install-dir`
 INFO Step: Run `systemctl daemon-reload`
Nix was installed successfully!
To get started using Nix, open a new shell or run `. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh`

(deck@steamdeck ~)$ . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
(deck@steamdeck ~)$ nix run nixpkgs#hello
Hello, world!
(deck@steamdeck ~)$ systemctl status nix.mount
● nix.mount - SteamOS Offload - /nix
     Loaded: loaded (/proc/self/mountinfo; enabled; preset: disabled)
     Active: active (mounted) since Wed 2023-05-31 13:01:33 PDT; 45s ago
      Until: Wed 2023-05-31 13:01:33 PDT; 45s ago
      Where: /nix
       What: /dev/vda8
      Tasks: 0 (limit: 9395)
     Memory: 8.0K
        CPU: 1ms
     CGroup: /system.slice/nix.mount

May 31 13:01:33 steamdeck systemd[1]: Mounting SteamOS Offload - /nix...
May 31 13:01:33 steamdeck systemd[1]: Mounted SteamOS Offload - /nix.
(deck@steamdeck ~)$ /nix/nix-installer uninstall
`nix-installer` needs to run as `root`, attempting to escalate now via `sudo`...
Nix uninstall plan (v0.9.1-unreleased)

Planner: steam-deck (with default settings)

Planned actions:
* Run `systemctl daemon-reload`
* Disable (and stop) the systemd unit ensure-symlinked-units-resolve.service
* Unconfigure Nix daemon related settings with systemd
* Unconfigure the shell profiles
* Remove the Nix configuration in `/etc/nix/nix.conf`
* Unset the default Nix profile
* Remove the directory tree in `/nix`
* Delete group `nixbld` (GID 30000)
* Delete file `/etc/systemd/system/ensure-symlinked-units-resolve.service`
* Disable (and stop) the systemd unit nix.mount
* Run `systemctl daemon-reload`


Proceed? ([Y]es/[n]o/[e]xplain): y
 INFO Revert: Run `systemctl daemon-reload`
 INFO Revert: Remove directory `/nix/temp-install-dir`
 INFO Revert: Enable (and start) the systemd unit ensure-symlinked-units-resolve.service
 INFO Revert: Configure Nix daemon related settings with systemd
 INFO Revert: Configure Nix
 INFO Revert: Provision Nix
 INFO Revert: Create or overwrite file `/etc/systemd/system/ensure-symlinked-units-resolve.service`
 INFO Revert: Enable (and start) the systemd unit nix.mount
 INFO Revert: Ensure SteamOS's `/nix` directory exists
 INFO Revert: Run `systemctl daemon-reload`
Nix was uninstalled successfully!

@Hoverbear Hoverbear marked this pull request as ready for review May 31, 2023 20:19
@Hoverbear Hoverbear requested a review from cole-h May 31, 2023 20:19
@Hoverbear
Copy link
Contributor Author

@cole-h I'd appreciate a second check of both the non-upgrade and upgrade path. :)

@Hoverbear Hoverbear added the upload to s3 The labeled PR is allowed to upload its artifacts to S3 for easy testing label May 31, 2023
Copy link
Member

@cole-h cole-h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems OK? I don't have a Steam Deck, so I had to resort to testing in a VM, and it seems to have worked just fine? I installed on 20220425.2, updated to 20230522.1000, rebooted, and everything still worked. Uninstalled and reinstalled on 20230522.1000 and everything still worked.

@Hoverbear
Copy link
Contributor Author

I'm gonna give it a go on hardware and hit merge if it works. :)

@Hoverbear
Copy link
Contributor Author

Confirmed working on real hardware!

@Hoverbear Hoverbear merged commit 5a07b23 into main Jun 1, 2023
@Hoverbear Hoverbear deleted the hoverbear/ds-912-steamos-beta-or-maybe-just-main-branch-installer-conflict branch June 1, 2023 16:48
@Hoverbear
Copy link
Contributor Author

Shoot, I just noticed uninstalling on 20230522.1000 is not working. I need to do another PR...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Steam Deck upload to s3 The labeled PR is allowed to upload its artifacts to S3 for easy testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SteamOS beta (or maybe just "main") branch installer conflict
2 participants