Skip to content

Instantly share code, notes, and snippets.

@OnikenX
Last active June 9, 2023 00:16
Show Gist options
  • Save OnikenX/00885157e29222b148778d078c93b0af to your computer and use it in GitHub Desktop.
Save OnikenX/00885157e29222b148778d078c93b0af to your computer and use it in GitHub Desktop.
Steam Deck package manager rootless

Steam Deck

Arquitecture

The steam deck, in terms of partition layout, is much closer to a modern phone than to a conventional PC.

The partition are divided in a AB layout, where you have a identical copy of critical files between partitions A and B of multiple partitions. This means that is much more secure and stable to update but it also means that your changes are easly reverted and of course those partitions are readonly and really low in extra space as it does not need much more.

So how can it, being imutable and always reseting, have personalized packages installed permanently?

Well for that we have 2 answers containers with complete systems where we can use its tools or using a rootless package system, I will go with the latter and the former could be for other stuff.

Nix Package Manager

Nix is a package manager for an OS called NixOS where packages are installed with independecy of eachothers, having also the ability of having different versions of the same packages.

So saying all that whats the importance of this package manager for the deck when the deck uses the pacman package manager and is arch? Well the reason is because it is also rootless! And for being the packages really well isolates it lets us install Nix in any Unix OS neat right so how can we install it in the deck?

Preparation

Well nix is kinda all that sweet honey but it does have a problem, it does not have bit problem, it does not you put the /nix folder wherenever you want, you can use nix-portable which is a wrapper for using a container and does not let us use the more interesting stuff of nix like nix-env and having the env in our normal shell transparently and if you try to link the folder to another it spits out errors, so what we can do?

Well for that we can mount it to our sdcard or home directory :D.

First of create a nix folder or where you want it to be, for exemple I put mine in my sdcard being its path /run/media/mmcblk0p1/nix/, lets call the path for your folder and mine as $NIX.

Now lets start with the installation.

Installation

  1. Unlock the filesystem with: sudo steamos-readonly disable
  2. creat the /nix folder sudo mkdir /nix && sudo chown deck /nix
  3. Bind the /nix folder with the folder you created sudo mount --bind $NIX /nix
  4. Installing nix as single user: sh <(curl -L https://nixos.org/nix/install) --no-daemon
  5. Added it in your bashrc if it is not already there: echo "source /home/deck/.nix-profile/etc/profile.d/nix.sh" >> ~/.bashrc

Usage

And we are done. To install packages you just need to use nix-env -i <package-name>. To search you can do it in here.

Pos Install

After rebooting the /nix file will be unbinded, to fix this you can download the bind_nix.service and put it in /etc/systemd/system and download the bind_nix.sh and put it in /home/deck/.local/bin/bind_nix.sh, after that enable it.

In resume:

sudo curl https://gist.githubusercontent.com/OnikenX/00885157e29222b148778d078c93b0af/raw/02dae1fd749bd4090ddaba52e99123ffceae9da3/bind-nix.service -o /etc/systemd/system/bind-nix.service
sudo systemctl enable --now bind_nix.service

Always remember that the deck can delete bind_nix.service when updating so you could need to restore it.

[Unit]
Description=Binds nix directory to root
After=run-media-mmcblk0p1.mount
Requires=run-media-mmcblk0p1.mount
[Service]
Restart=on-failure
RestartSec=15
ExecStart=/usr/bin/env bash /home/deck/.local/bin/bind_nix.sh
[Install]
WantedBy=multi-user.target
#!/bin/bash
#where to redirect /nix
NIX=/run/media/mmcblk0p1/nix/
# if steamos is not writable change the state
if [ ! $(steamos-readonly status | grep disable) ] ; then
steamos-readonly disable
fi
#if folder does not exist create it
if [ ! -d /nix ]; then
mkdir /nix
chown deck /nix
fi
#binds directories
mount --bind $NIX /nix
if [ $? -ne 0 ]; then
echo dont have permissions
exit 1;
else
echo runned sucessfully
exit 0;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment