Remove home manager from the steam deck.

This commit is contained in:
Tom Alexander 2026-02-02 18:59:35 -05:00
parent ae10e31365
commit 16811fb240
Signed by: talexander
GPG Key ID: 36C99E8B3C39D85F
70 changed files with 482 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
}

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

@ -0,0 +1,52 @@
{
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;
# 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;
inherit nixpkgs;
};
};
}
);
};
}

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,72 @@
# 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@{
# nixpkgs to use
pkgs,
# Name of the profile, which appears in the Nix store path of the result
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"
"pinned"
"extraSwitchArgs"
"modules"
"specialArgs"
];
pins = import ./pin.nix { inherit pkgs pinned; };
config = pkgs.lib.evalModules {
modules = [ ./modules ] ++ modules;
specialArgs = specialArgs // {
_pkgs = pkgs;
};
};
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,68 @@
{
config,
options,
lib,
_pkgs,
nixpkgs,
...
}:
let
# finalPkgs = _pkgs;
finalPkgs = import nixpkgs {
system = _pkgs.system;
config = { };
overlays = [ ];
# inherit system;
# overlays = [ nixgl.overlay ];
};
in
{
imports = [
];
# options.nixpkgs = {
# config = lib.mkOption {
# default = { };
# example = lib.literalExpression ''
# { allowBroken = true; allowUnfree = true; }
# '';
# type = configType;
# description = ''
# Global configuration for Nixpkgs.
# The complete list of [Nixpkgs configuration options](https://nixos.org/manual/nixpkgs/unstable/#sec-config-options-reference) is in the [Nixpkgs manual section on global configuration](https://nixos.org/manual/nixpkgs/unstable/#chap-packageconfig).
# Ignored when {option}`nixpkgs.pkgs` is set.
# '';
# };
# overlays = lib.mkOption {
# default = [ ];
# example = lib.literalExpression ''
# [
# (self: super: {
# openssh = super.openssh.override {
# hpnSupport = true;
# kerberos = self.libkrb5;
# };
# })
# ]
# '';
# type = lib.types.listOf overlayType;
# description = ''
# List of overlays to apply to Nixpkgs.
# This option allows modifying the Nixpkgs package set accessed through the `pkgs` module argument.
# For details, see the [Overlays chapter in the Nixpkgs manual](https://nixos.org/manual/nixpkgs/stable/#chap-overlays).
# If the {option}`nixpkgs.pkgs` option is set, overlays specified using `nixpkgs.overlays` will be applied after the overlays that were already included in `nixpkgs.pkgs`.
# '';
# };
# };
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;
}