1

I am running Arch Linux on the Steam Deck. Steam Deck has a read only root file system which forces you to use Flatpak, or else to make the file system writable at the expense of wiping out, say, pacman-based installations every time they update the Deck's software.

I'm not a fan of Flatpak, I prefer Nix not least because it has packages that I need that are not available with Flatpak.

Nix allows you to run the entire package manager without root access from a chroot jail using nix-user-chroot utility.

Once installed, the command for getting into the chrooted nix environment is nix-user-chroot ~/.nix bash -l which works fine in a new shell:

enter image description here

However if I stick that exact same line at the end of my .bashrc I get a panic:

enter image description here

This appears to be exactly the same error that occurs if I run the command twice:

enter image description here

Keep in mind that the Steam Deck's shell already appears to be running in a chroot jail, as per this technique for finding out if I'm already chrooted (run without the nix-user-chroot ~/.nix bash -l in my bashrc):

enter image description here

So my question is, how do I automatically run nix-user-chroot ~/.nix bash -l so that it is invoked for every terminal?

3
  • @moderators you might want to create a new 'steam-deck' tab because I anticipate this brilliant little machine's funky Arch installation will get quite a few questions on your forum. I cannot as don't have 300 yet. Commented May 1, 2022 at 22:17
  • Please don't post screenshots of text. Copy the text here and use code formatting instead. unix.stackexchange.com/editing-help#code
    – muru
    Commented Jun 8, 2022 at 4:48
  • 1
    Also, if you do SOME_FLAG_VARIABLE=1 nix-user-chroot ~/.nix bash -l, is the SOME_FLAG_VARIABLE environment variable available in the chroot shell? (It should be, but this nix-user-chroot command might clean the environment.) If it is, you can just check for that variable before executing the command in your bashrc: if [[ -z SOME_FLAG_VARIABLE ]]; then exec SOME_FLAG_VARIABLE=1 nix-user-chroot ~/.nix bash -l; fi
    – muru
    Commented Jun 8, 2022 at 4:53

2 Answers 2

1

As muru mentioned in the comment, the problem is that the first execution of nix-user-chroot ~/.nix bash -l works fine, but spawns a new shell which again tries to execute nix-user-chroot etc. The solution is to put the nix-user-chroot inside an if-clause, checking if the nix environment is already loaded, e.g. running

if [ -z "${NIX_PROFILES}" ]; then
    ./nix-user-chroot ~/.nix bash -l
fi

after loading your nix profile (there's a line added by the installer either in the .bashrc or .profile file).

1

I do something a bit different and change Konsole's command in Settings->Edit Current Profile... to:

/bin/bash -c "~/.local/bin/nix-user-chroot ~/.nix bash"

I have to create a new profile as the Vapor one is read only.

It does almost the same thing. It's only in Konsole so if I do ++ my bash still works in case I need to fix something :)

Then for apps I create an executable bash script in ~/.local/bin/<YOURAPPNAME> and make it executable chmod +x ~/.local/bin/<YOURAPPNAME> with this content:

#! /usr/bin/env bash

~/.local/bin/nix-user-chroot ~/.nix ~/.nix-profile/bin/<YOURAPPNAME>

And for desktop use I create ~/.local/share/applications/<YOURAPPNAME>.desktop:

[Desktop Entry]
Version=1.0
Name=<YOURAPPNAME>
Comment=<YOURAPPDESCRIPTION>
Exec=~/.local/bin/<YOURAPPNAME>
Terminal=false
Type=Application
Icon=meld
Categories=GNOME;Development;
StartupNotify=false
NoDisplay=false

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .