Remove home manager from the steam deck.

This commit is contained in:
Tom Alexander 2026-02-02 18:59:35 -05:00
parent 3577edab9d
commit 185b2dcba2
Signed by: talexander
GPG Key ID: 36C99E8B3C39D85F
73 changed files with 589 additions and 79 deletions

View File

@ -0,0 +1,61 @@
{
config,
pkgs,
nixgl,
...
}:
{
imports = [
./roles/2ship2harkinian
# ./roles/ares
# ./roles/dolphin
# ./roles/dont_use_substituters
# ./roles/duckstation
# ./roles/global_options
./roles/graphics
# ./roles/pcsx2
# ./roles/rpcs3
# ./roles/ryujinx
# ./roles/shipwright
# ./roles/sm64ex
# ./roles/spaghettikart
# ./roles/steam_rom_manager
# ./roles/yuzu
# ./util/copy_files
# ./util/persist_symlink
./util/unfree_polyfill
];
# enable flakes
# nix = {
# package = pkgs.nix;
# settings.experimental-features = [
# "nix-command"
# "flakes"
# ];
# };
# Automatic garbage collection
# nix.gc = {
# # Runs nix-collect-garbage --delete-older-than 30d
# automatic = true;
# randomizedDelaySec = "14m";
# options = "--delete-older-than 30d";
# };
# nix.settings.auto-optimise-store = true;
# home.packages = with pkgs; [
# pkgs.nixgl.nixGLIntel
# (pkgs.nixgl.nixGLCommon pkgs.nixgl.nixGLIntel)
# pkgs.nixgl.nixVulkanIntel
# ];
# This would keep build-time dependencies so I can rebuild while offline.
# nix.settings = {
# keep-outputs = true;
# keep-derivations = true;
# };
config = {
castrum.packages = with pkgs; [ nano ];
};
}

View File

@ -1,79 +0,0 @@
* Initial Setup
** Mount /home/deck/nix to /nix
The default /nix is too small and it could be modified by OS releases. We want to use something in our home folder since that will be untouched in upgrades.
# TODO: /home/nix gets owned by root but it should be owned by deck:deck for single-user nix installs
# TODO: nixos-installer adds this to /home/deck/.bash_profile , will this be wiped out in updates?
# if [ -e /home/deck/.nix-profile/etc/profile.d/nix.sh ]; then . /home/deck/.nix-profile/etc/profile.d/nix.sh; fi # added by Nix installer
Create =/etc/systemd/system/nix-directory.service=
#+begin_src text
[Unit]
Description=Create a `/nix` directory to be used for bind mounting
#PropagatesStopTo=nix-daemon.service
PropagatesStopTo=nix.mount
DefaultDependencies=no
[Service]
Type=oneshot
ExecStart=steamos-readonly disable
ExecStart=mkdir -vp /nix
ExecStart=chmod -v 0755 /nix
ExecStart=chown -v root /nix
ExecStart=chgrp -v root /nix
ExecStart=steamos-readonly enable
ExecStop=steamos-readonly disable
ExecStop=rmdir /nix
ExecStop=steamos-readonly enable
RemainAfterExit=true
#+end_src
Create =/etc/systemd/system/nix.mount=
#+begin_src text
[Unit]
Description=Mount `/home/nix` on `/nix`
#PropagatesStopTo=nix-daemon.service
PropagatesStopTo=nix-directory.service
After=nix-directory.service
Requires=nix-directory.service
ConditionPathIsDirectory=/nix
DefaultDependencies=no
#RequiredBy=nix-daemon.service
#RequiredBy=nix-daemon.socket
[Mount]
What=/home/nix
Where=/nix
Type=none
DirectoryMode=0755
Options=bind
#+end_src
Create =/etc/systemd/system/ensure-symlinked-units-resolve.service=
#+begin_src text
[Unit]
Description=Ensure Nix related units which are symlinked resolve
After=nix.mount
Requires=nix-directory.service
Requires=nix.mount
DefaultDependencies=no
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/systemctl daemon-reload
#ExecStart=/usr/bin/systemctl restart --no-block nix-daemon.socket
[Install]
WantedBy=sysinit.target
#+end_src
Enable the mount by running
#+begin_src bash
sudo systemctl enable --now ensure-symlinked-units-resolve.service
#+end_src
** Install nix
#+begin_src bash
sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --no-daemon
#+end_src

82
nix/steam_deck/flake.lock generated Normal file
View File

@ -0,0 +1,82 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixgl": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1762090880,
"narHash": "sha256-fbRQzIGPkjZa83MowjbD2ALaJf9y6KMDdJBQMKFeY/8=",
"owner": "nix-community",
"repo": "nixGL",
"rev": "b6105297e6f0cd041670c3e8628394d4ee247ed5",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixGL",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1770197578,
"narHash": "sha256-AYqlWrX09+HvGs8zM6ebZ1pwUqjkfpnv8mewYwAo+iM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "00c21e4c93d963c50d4c0c89bfa84ed6e0694df2",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixgl": "nixgl",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

51
nix/steam_deck/flake.nix Normal file
View File

@ -0,0 +1,51 @@
{
description = "My system configuration";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
nixgl = {
url = "github:nix-community/nixGL";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
nixpkgs,
nixgl,
...
}:
let
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
castrum = import ./util/castrum;
in
{
packages = forAllSystems (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ nixgl.overlay ];
};
in
{
profile = castrum.lib.castrumSystem {
inherit pkgs nixpkgs;
# Specifies things to pin in the flake registry and in NIX_PATH.
pinned = {
nixpkgs = toString nixpkgs;
};
modules = [
# { nixpkgs.overlays = [ nixgl.overlay ]; }
# impermanence.homeManagerModules.impermanence
./hosts/deck
./configuration.nix
];
specialArgs = {
inherit nixgl;
};
};
}
);
};
}

View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
#
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
: "${JOBS:="1"}"
TARGET=deck@172.16.16.250
rsync -av --progress --delete --exclude=.git "$DIR/../../" "${TARGET}:~/.config/mynix"
rsync -av --progress --delete --exclude=.git "/persist/manual/manual_add_to_store" "${TARGET}:~/.persist/manual/"
# nix run --extra-experimental-features nix-command --extra-experimental-features flakes .#profile.switch
# ssh "${TARGET}" 'source /home/deck/.nix-profile/etc/profile.d/nix.sh && for f in ~/.persist/manual/manual_add_to_store/*; do nix-store --add-fixed sha256 "$f"; done'
ssh "${TARGET}" "source /home/deck/.nix-profile/etc/profile.d/nix.sh && nix run --extra-experimental-features nix-command --extra-experimental-features flakes /home/deck/.config/mynix#profile.switch --show-trace"
# ssh "${TARGET}" 'cat .config/mynix/flake.lock' > "$DIR/../../flake.lock"

View File

@ -0,0 +1,30 @@
{
config,
lib,
pkgs,
...
}:
{
imports = [ ];
config = {
# me.ares.enable = true;
# me.dolphin.enable = true;
# me.dont_use_substituters.enable = true;
# me.duckstation.enable = true;
me.graphical = true;
# me.optimizations.enable = true;
# me.pcsx2.enable = true;
# me.rpcs3.enable = true;
# me.ryujinx.enable = true;
me.ship2harkinian.enable = true;
# me.shipwright.enable = true;
# me.sm64ex.enable = true;
# me.spaghettikart.enable = true;
# me.steam_rom_manager.enable = true; # Steam rom manager UI does not render. I think it wants to be in an AppImage.
# me.yuzu.enable = true;
castrum.packages = with pkgs; [ ];
};
}

View File

@ -0,0 +1,70 @@
{
config,
lib,
pkgs,
...
}:
let
steam_2s2h = pkgs.writeScriptBin "steam_2s2h" ''
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pkgs.libglvnd}/lib"
exec ${pkgs._2ship2harkinian}/bin/2s2h "''${@}"
'';
in
{
imports = [ ];
options.me = {
ship2harkinian.enable = lib.mkOption {
type = lib.types.bool;
default = false;
example = true;
description = "Whether we want to install 2ship2harkinian.";
};
};
config = lib.mkIf config.me.ship2harkinian.enable (
lib.mkMerge [
{
allowedUnfree = [ "2ship2harkinian" ];
}
(lib.mkIf config.me.graphical {
castrum.packages = with pkgs; [
_2ship2harkinian
steam_2s2h
];
home.file.".local/share/2ship/2ship2harkinian.json" = {
source = ./files/2ship2harkinian.json;
};
me.persist.directories = [ ".local/share/2ship/saves" ];
home.persistence."/home/deck/.state" = {
files = [
".local/share/2ship/mm.o2r"
];
};
nixpkgs.overlays = [
(final: prev: {
_2ship2harkinian = pkgs.buildEnv {
name = prev._2ship2harkinian.name;
paths = [
(config.lib.nixGL.wrap prev._2ship2harkinian)
];
extraOutputsToInstall = [
"man"
"doc"
"info"
];
# We have to use 555 instead of the normal 444 here because the .desktop file ends up inside $HOME on steam deck and desktop files must be either not in $HOME or must be executable, otherwise KDE Plasma refuses to execute them.
postBuild = ''
chmod 0555 $out/share/applications/2s2h.desktop
'';
};
})
];
})
]
);
}

View File

@ -0,0 +1,20 @@
{
"CVars": {
"gInterpolationFPS": 60,
"gEnhancements": {
"Graphics": {
"AuthenticLogo": 1
}
},
"gSettings": {
"InternalResolution": 2.0,
"MSAAValue": 2,
"OpenMenuBar": 0
}
},
"Window": {
"Fullscreen": {
"Enabled": true
}
}
}

View File

@ -0,0 +1,43 @@
{
config,
lib,
pkgs,
nixgl,
...
}:
{
imports = [ ];
options.me.graphics_card_type = lib.mkOption {
type = lib.types.nullOr (
lib.types.enum [
"amd"
"intel"
"nvidia"
]
);
default = null;
example = "amd";
description = "What graphics card type is in the computer.";
};
options.me.graphical = lib.mkOption {
type = lib.types.bool;
default = false;
example = true;
description = "Whether we want to install graphical programs.";
};
config = (
lib.mkMerge [
(lib.mkIf config.me.graphical {
nixGL.packages = nixgl.packages;
# home.packages = with pkgs; [
# mesa-demos # for glxgears
# vulkan-tools # for vkcube
# ];
})
]
);
}

View File

@ -0,0 +1,76 @@
# Creates a profile. Arguments are forwarded to pkgs.buildEnv.
#
# The following attributes are available:
# - .switch: switches to the profile
# - .rollback: rolls back to the previous version of the profile
args@{
pkgs,
nixpkgs,
name ? "castrum-profile",
# Items to pin in the flake registry and NIX_PATH, such that they're seen by
# `nix run nixpkgs#hello` and `nix-shell -p hello --run hello`.
pinned ? { },
# Extra arguments given when switching profiles (n.b. not shell escaped).
extraSwitchArgs ? [ ],
modules ? [ ],
specialArgs ? { },
...
}:
let
args' = builtins.removeAttrs args [
"pkgs"
"nixpkgs"
"pinned"
"extraSwitchArgs"
"modules"
"specialArgs"
];
pins = import ./pin.nix { inherit pkgs pinned; };
config = pkgs.lib.evalModules {
modules = [
./modules
{ nixpkgs.system = pkgs.stdenv.hostPlatform.system; }
]
++ modules;
specialArgs = specialArgs // {
inherit nixpkgs;
};
};
env = pkgs.buildEnv (
args'
// {
inherit name;
paths = [ pkgs.nix ] ++ config.config.castrum.packages;
}
);
in
env
// {
switch = pkgs.writeShellScriptBin "switch" ''
nix-env --set ${env} ${toString extraSwitchArgs} "$@"
'';
rollback = pkgs.writeShellScriptBin "rollback" ''
nix-env --rollback ${toString extraSwitchArgs} "$@"
'';
# pass through pins, so you can e.g. nix build .#profile.pins.channels
inherit pins;
# This script pins any of the items in "pinned" in both the flake registry
# and the nix channels, such that `nix run nixpkgs#hello` and
# `nix-shell -p hello --run hello` will hit the same nixpkgs as is used in
# the declarative profile.
#
# It is not really possible to cleanly roll this back in terms of the flake
# registry, so we suggest just reverting with git in that case.
pin = pkgs.writeShellScriptBin "pin" ''
if [[ $UID == 0 ]]; then
${pins.pinFlakes { isRoot = true; }}
else
${pins.pinFlakes { isRoot = false; }}
fi
nix-env --profile /nix/var/nix/profiles/per-user/$USER/channels --set ${pins.channels}
'';
}

View File

@ -0,0 +1,3 @@
{
lib = import ./lib.nix;
}

View File

@ -0,0 +1,3 @@
{
castrumSystem = import ./castrumSystem.nix;
}

View File

@ -0,0 +1,13 @@
{
config,
lib,
pkgs,
...
}:
{
imports = [
./nixpkgs.nix
./packages.nix
];
}

View File

@ -0,0 +1,39 @@
{
config,
options,
lib,
pkgs,
nixpkgs,
...
}:
let
finalPkgs = import nixpkgs {
system = config.nixpkgs.system;
config = { };
overlays = config.nixpkgs.overlays;
};
in
{
imports = [
];
options.nixpkgs = {
system = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
overlays = lib.mkOption {
default = [ ];
type = lib.types.listOf lib.types.anything;
description = "Overlays for nixpkgs.";
};
};
config = {
_module.args = {
pkgs = finalPkgs;
};
};
}

View File

@ -0,0 +1,25 @@
{
config,
lib,
pkgs,
...
}:
{
imports = [
];
options.castrum = {
packages = lib.mkOption {
type = lib.types.listOf lib.types.path;
default = [ ];
example = with pkgs; [
nano
bash
];
description = ''
List of packages to install.
'';
};
};
}

View File

@ -0,0 +1,33 @@
{
pkgs,
pinned ? { },
}:
let
inherit (pkgs) lib;
pathOk = item: builtins.match ".*-source$" (toString item) != null;
pathChecked =
name: item:
pkgs.lib.assertMsg (pathOk item) ''
Flake registry pin item path must end with -source, due to https://github.com/NixOS/nix/issues/7075.
Name: ${name}
Path: ${toString item}
Consider pinning nixpkgs with `builtins.fetchTarball` with `name` set to "source".
'';
pins = builtins.mapAttrs (
name: value:
assert pathChecked name value;
value
) pinned;
in
{
inherit pins;
channels = pkgs.linkFarm "user-environment" pins;
pinFlakes =
{ isRoot }:
lib.concatMapStringsSep "\n" (
name:
"nix registry pin ${lib.optionalString isRoot "--registry /etc/nix/registry.json"} --override-flake ${name} ${pins.${name}} ${name}"
) (builtins.attrNames pins);
}

View File

@ -0,0 +1,20 @@
{
config,
lib,
foo,
...
}:
let
inherit (builtins) elem;
inherit (lib) getName mkOption;
inherit (lib.types) listOf str;
in
{
# Pending https://github.com/NixOS/nixpkgs/issues/55674
options.allowedUnfree = mkOption {
type = listOf str;
default = [ ];
};
# config.nixpkgs.config.allowUnfreePredicate = p: elem (getName p) config.allowedUnfree;
}