Jovian NixOS

From NixOS Wiki
Jump to: navigation, search

Jovian Nixos is an expertly curated configuration that enables NixOS on Valve Steam Deck. It can also be used to build a dedicated gaming computer. When applied, your computer will be like a gaming console using Steam's Big Picture mode.

Presumptions

Please extrapolate for other NixOS versions, configurations, flakes, hardware, et cetera.

  • NixOS unstable (Only the unstable channel is supported)
  • Classic channels configuration
  • Fresh install on a dedicated x86_64 PC with an AMD CPU and GPU

HOWTO

1) Login, switch to superuser, change directory to /etc/nixos.

sudo su
cd /etc/nixos

2) Create /etc/nixos/jovian.nix with the following configuration.

nano /etc/nixos/jovian.nix
#
# jovian.nix -- Gaming
#
{pkgs, ...}: let
  # Local user account for auto login
  # Separate and distinct from Steam login
  # Can be any name you like
  gameuser = "gamer";
  jovian-nixos = builtins.fetchGit {
    url = "https://github.com/Jovian-Experiments/Jovian-NixOS";
    ref = "development";
  };
in {
  system.activationScripts = {
    print-jovian = {
      text = builtins.trace "building the jovian configuration..." "";
    };
  };

  #
  # Imports
  #
  imports = [ "${jovian-nixos}/modules" ];

  #
  # Boot
  #
  boot.kernelParams = ["amd_pstate=active"];

  #
  # Hardware
  #
  hardware.amdgpu = {
    amdvlk = {
      enable = true;
      support32Bit.enable = true;
    };

    initrd.enable = true;
  };

  hardware.xone.enable = true;

  #
  # Jovian
  #
  jovian.hardware.has.amd.gpu = true;

  jovian.steam.enable = true;

  #
  # Packages
  #
  environment.systemPackages = with pkgs; [
    steam-rom-manager # App for adding 3rd party games/ROMs as Steam launch items
  ];

  #
  # SDDM
  #
  services.displayManager.sddm.settings = {
    Autologin = {
      Session = "gamescope-wayland.desktop";
      User = "${gameuser}";
    };
  };

  #
  # Steam
  #
  # Set game launcher: gamemoderun %command%
  #   Set this for each game in Steam, if the game could benefit from a minor
  #   performance tweak: YOUR_GAME > Properties > General > Launch > Options
  #   It's a modest tweak that may not be needed. Jovian is optimized for
  #   high performance by default.
  programs.gamemode = {
    enable = true;
    settings = {
      general = {
        renice = 10;
      };
      gpu = {
        apply_gpu_optimisations = "accept-responsibility"; # For systems with AMD GPUs
        gpu_device = 0;
        amd_performance_level = "high";
      };
    };
  };

  programs.steam = {
    enable = true;
    localNetworkGameTransfers.openFirewall = true;
  };

  #
  # Users
  #
  users = {
    groups.${gameuser} = {
      name = "${gameuser}";
      gid = 10000;
    };

    # Generate hashed password: mkpasswd -m sha-512
    # hashedPassword sets the initial password. Use `passwd` to change it.
    users.${gameuser} = {
      description = "${gameuser}";
      extraGroups = ["gamemode" "networkmanager"];
      group = "${gameuser}";
      hashedPassword = "$abc123..."; # <<<--- Generate your own initial hashed password
      home = "/home/${gameuser}";
      isNormalUser = true;
      uid = 10000;
    };
  };
}

3) Backup your original configuration.nix.

cp configuration.nix configuration.nix.orig

4) Added the following import to configuration.nix.

nano /etc/nixos/configuration.nix
  imports =
    [
      ./hardware-configuration.nix
      ./jovian.nix
    ]

5) Switch to the unstable channel, apply the configuration. and reboot.

nix-channel --add https://nixos.org/channels/nixos-unstable nixos
nix-channel --update
nixos-rebuild boot --upgrade
sync ; sync ; sync
reboot

Be patient. After rebooting my computer seemed to hang at a black screen. I think that Steam was initializing. I waited ~20 minutes and rebooted again. After that the computer successfully logged in and launched Steam in Big Picture mode.

I then paired my gaming controller, logged into to Steam, and had a lot of fun. You will too!

Optional

Add the following quality of life improvements to configuration.nix if you like.

nano /etc/nixos/configuration.nix
  #
  # Boot
  #
  boot = {
    consoleLogLevel = 0;

    initrd.verbose = false;

    kernelPackages = pkgs.linuxPackages_latest;

    # Quiet, graphical boot
    kernelParams = [
      "quiet"
      "loglevel=3"
      "rd.systemd.show_status=false"
      "rd.udev.log_level=3"
      "udev.log_priority=3"
    ];

    loader = {
      efi.canTouchEfiVariables = true;

      systemd-boot = {
        configurationLimit = 10;
        enable = true;
      };

      timeout = 5;
    };

    plymouth.enable = true; # Splash screen
  };

  #
  # Nix
  #
  nix = {
    gc = {
      automatic = true;
      dates = "weekly";
      options = "--delete-older-than 60d";
    };
  };

  #
  # System
  #
  system = {
    activationScripts = {
      # Print a summary of nixos-rebuild changes
      diff = {
        supportsDryActivation = true;
        text = ''
          ${pkgs.nvd}/bin/nvd --nix-bin-dir=${pkgs.nix}/bin diff \
            /run/current-system "$systemConfig"
        '';
      };
    autoUpgrade = {
      enable = true;
      allowReboot = true;
      dates = "Mon 06:00";
      persistent = true;
      randomizedDelaySec = "20min";
    };
  };

References

Jovian-NixOS: [1] Steam Big Picture: [2]