44
submitted 2 weeks ago* (last edited 2 weeks ago) by rikudou@lemmings.world to c/steamdeck@sopuli.xyz

Just wanted to let others know that you can install Nix and Home Manager on your SteamDeck which allows for persistent software across system updates without anything breaking. You might need sudo for this.

Simple step by step guide with commands:

  • sh <(curl -L https://nixos.org/nix/install) --no-daemon - single user installation, from official documentation
  • source .bash_profile - load the nix env into your current session
  • nix-channel --add https://nixos.org/channels/nixos-24.11 nixpkgs - replaces your nix channel with the current stable (nix default to unstable for some reason)
  • nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.11.tar.gz home-manager - adds the home manager channel
  • mv .bash_profile .bash_profile.bckp
  • mv .bashrc .bashrc.bckp - these two commands backup your bash config files
  • nix-shell '<home-manager>' -A install - installs home manager standalone, as per the official documentation
  • kate ~/.config/home-manager/home.nix - open your nix config file in the default text editor and put the following content there:
{ config, pkgs, ... }:
{
  home.username = "deck";
  home.homeDirectory = "/home/deck";

  programs.bash = {
    enable = true;
    initExtra = ''
      if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]; then . $HOME/.nix-profile/etc/profile.d/nix.sh; fi

      export NIX_SHELL_PRESERVE_PROMPT=1
      if [[ -n "$IN_NIX_SHELL" ]]; then
        export PS1="$PS1(nix-shell) "
      fi
    '';
  };

  home.stateVersion = "24.11"; # don't change this even if you upgrade your channel in the future, this should stay the same as the version you first installed nix on

  home.packages = with pkgs; [
    
  ];

  programs.home-manager.enable = true;
}
  • home-manager switch - applies the configuration from the above file
  • close the terminal and open it again, everything should work

The config file tells nix to automatically load the nix environment into your terminal session. This is a fairly minimal setup where nothing is installed. If you want to install some software, simply add it to the home.packages array like so:

  home.packages = with pkgs; [
      nmap
      cowsay
  ];

After running home-manager switch, you should be able to run two new commands: nmap and cowsay.

Other very cool possibility is to install them inside a temporary shell by running: nix-shell -p nmap cowsay. This is perfect, if you only need the package(s) this once and not something you run regularly - after you exit the temporary nix-shell, the packages won't be on your system.

Anyway, nix survives even across system upgrades, because it installs all its files into /nix or your home directory, which are preserved even when upgrading, unlike system directories.

P.S. Don't forget to run nix-collect-garbage from time to time if you install a lot of temporary packages.

top 8 comments
sorted by: hot top controversial new old
[-] rikudou@lemmings.world 17 points 2 weeks ago

And if anyone's interested in what prompted the writing of this guide, I wanted to play Palworld but didn't know the IP address of the local PC my server is on. I was also really lazy to get the IP address from the PC itself, so I decided to use nmap to scan my local network and find the PC that way. Found out nmap is not installed by default so I had to install it somehow and then I remembered that SteamOS added the /nix directory to its exceptions that survive across upgrades.

In short, instead of taking two minutes to get the IP address I spent over half an hour getting nix to work. And decided to share in case it helps others.

[-] filister@lemmy.world 3 points 2 weeks ago

One comment though, you are moving the bashrc and bash_profile instead of copying it. So consider fixing it in your instructions.

You could have also run a for loop and ping all the IPs in your subnet. Something like this will work:

for i in {1..254}; do ping -c 1 -W 1 192.168.1.$i &> /dev/null && echo 192.168.1.$i; done

Presuming that your subnet is 192.168.1.0/24. This command will loop through all the IPs in this network and only print the one that are alive.

I didn't know that Steam have added an exception for /nix which is pretty cool. Thanks for sharing

[-] rikudou@lemmings.world 1 points 2 weeks ago

The move is intentional, the configuration file I included makes Home Manager manage .bashrc and .bash_profile, the original files are moved for backup.

Ping wouldn't help that much, there's around ~30 devices on my network. And it's very much possible my PC blocks ICMP. And in addition, nmap includes the manufacturer in the output which is what I wanted to base my guess on.

[-] filister@lemmy.world 2 points 2 weeks ago* (last edited 2 weeks ago)

I am pretty sure your PC doesn't block ICMP requests and you can get the MAC address of the IP address using the arp command and then check the first three octets against the MAC vendors database.

This is all possible in Bash but the script will be slightly more complicated and will involve three different tools, ping, arp, curl.

But I am sure you know how to check your PC IP address anyway.

[-] Badland9085@lemm.ee 1 points 2 weeks ago

Sounds like a classic case of early onset yak-shaving. But given that I too get bitten by this bug from time to time, I approve.

[-] Fubarberry@sopuli.xyz 7 points 2 weeks ago

Thanks for sharing. Another valid option is Distrobox, which lets you permanently install Debian/Fedora/Arch/etc packages.

[-] rikudou@lemmings.world 2 points 2 weeks ago

Distrobox seems to use docker/podman? Not what I'm after, but I'll read more on it, never heard of it before.

[-] Fubarberry@sopuli.xyz 3 points 2 weeks ago

It's pretty common, many immutable distros come with it pre installed as the primary way to install new software.

this post was submitted on 07 Dec 2024
44 points (97.8% liked)

Steam Deck

15053 readers
164 users here now

A place to discuss and support all things Steam Deck.

Replacement for r/steamdeck_linux.

As Lemmy doesn't have flairs yet, you can use these prefixes to indicate what type of post you have made, eg:
[Flair] My post title

The following is a list of suggested flairs:
[Discussion] - General discussion.
[Help] - A request for help or support.
[News] - News about the deck.
[PSA] - Sharing important information.
[Game] - News / info about a game on the deck.
[Update] - An update to a previous post.
[Meta] - Discussion about this community.

Some more Steam Deck specific flairs:
[Boot Screen] - Custom boot screens/videos.
[Selling] - If you are selling your deck.

These are not enforced, but they are encouraged.

Rules:

Link to our Matrix Space

founded 3 years ago
MODERATORS