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.

  • Rikudou_Sage@lemmings.worldOP
    link
    fedilink
    English
    arrow-up
    18
    arrow-down
    1
    ·
    5 days 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.

    • Badland9085@lemm.ee
      link
      fedilink
      arrow-up
      1
      ·
      3 days 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.

    • filister@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      5 days 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_Sage@lemmings.worldOP
        link
        fedilink
        arrow-up
        1
        ·
        5 days 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
          link
          fedilink
          arrow-up
          2
          ·
          edit-2
          5 days 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.

  • Fubarberry@sopuli.xyzM
    link
    fedilink
    English
    arrow-up
    7
    ·
    5 days ago

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

      • Fubarberry@sopuli.xyzM
        link
        fedilink
        English
        arrow-up
        3
        ·
        5 days ago

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