Skip to content

Commit

Permalink
fix: add wip homemade module
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony Rabbito <[email protected]>
  • Loading branch information
anthr76 committed Apr 6, 2024
1 parent ef27a43 commit 5c9c97f
Show file tree
Hide file tree
Showing 9 changed files with 340 additions and 18 deletions.
1 change: 0 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
specialArgs = { inherit inputs outputs; };
modules = [
chaotic.nixosModules.default
jovian-nixos.nixosModules.jovian
./nixos/hosts/octo.nwk3.rabbito.tech
];
};
Expand Down
1 change: 1 addition & 0 deletions modules/nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
# List your module files here
# my-module = import ./my-module.nix;
gaming-kernel = import ./gaming-kernel.nix;
steamos = import ./steamos;
}
169 changes: 169 additions & 0 deletions modules/nixos/steamos/autostart.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
{ config, lib, pkgs, inputs, ... }:

let
inherit (lib)
mkDefault
mkIf
mkMerge
mkOption
types
;
cfg = config.snowflake.steam;
in
{
options = {
snowflake = {
steam = {
autoStart = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Whether to automatically launch the Steam Deck UI on boot.
Traditional Display Managers cannot be enabled in conjunction with this option.
'';
};

user = mkOption {
type = types.str;
description = lib.mdDoc ''
The user to run Steam with.
'';
};

desktopSession = mkOption {
type = with types ; nullOr str // {
check = userProvidedDesktopSession:
lib.assertMsg (userProvidedDesktopSession != null -> (str.check userProvidedDesktopSession && lib.elem userProvidedDesktopSession config.services.xserver.displayManager.sessionData.sessionNames)) ''
Desktop session '${userProvidedDesktopSession}' not found.
Valid values for 'snowflake.steam.desktopSession' are:
${lib.concatStringsSep "\n " config.services.xserver.displayManager.sessionData.sessionNames}
If you don't want a desktop session to switch to, set 'snowflake.steam.desktopSession' to 'gamescope-wayland'.
'';
};
default = null;
example = "plasma";
description = lib.mdDoc ''
The session to launch for Desktop Mode.
By default, attempting to switch to the desktop will launch Gaming Mode again.
'';
};
};
};
};

config = mkIf cfg.enable (mkMerge [
(mkIf cfg.autoStart {
assertions = [
{
assertion = !config.systemd.services.display-manager.enable;
message = ''
Traditional Display Managers cannot be enabled when snowflake.steam.autoStart is used
Hint: check `services.xserver.displaymanager.*.enable` options in your configuration.
'';
}
];

warnings = lib.optional (cfg.desktopSession == null) ''
snowflake.steam.desktopSession is unset.
This means that using the Switch to Desktop function in Gaming Mode will
relaunch Gaming Mode.
Set snowflake.steam.desktopSession to the name of a desktop session, or "gamescope-wayland"
to keep this behavior.
'';

services.xserver = {
enable = true;
displayManager.lightdm.enable = false;
displayManager.startx.enable = true;
};

systemd.user.services.gamescope-session = {
overrideStrategy = "asDropin";

environment = mkMerge (
[
{
JOVIAN_DESKTOP_SESSION = cfg.desktopSession;
PATH = lib.mkForce null;
}
]
# Add any globally defined well-known XKB_DEFAULT environment variables to the session
# This is the closest wayland sessions have to generic keyboard configurations.
++ (map (var:
(mkIf (config.environment.variables ? "${var}") {
"${var}" = mkDefault config.environment.variables."${var}";
})
) [
"XKB_DEFAULT_LAYOUT"
"XKB_DEFAULT_OPTIONS"
"XKB_DEFAULT_MODEL"
"XKB_DEFAULT_RULES"
"XKB_DEFAULT_VARIANT"
]
)
);

# upstream unit redirects to a file, but this seems unnecessary now?
# see https://github.com/Jovian-Experiments/PKGBUILDs-mirror/blob/76aa4a564094dc656aa1b1daa0f116a7b93b0d7b/gamescope-session.service#L10
serviceConfig = {
StandardOutput = "journal";
StandardError = "journal";
};
};

services.greetd = {
enable = true;
settings = {
default_session = {
user = "jovian-greeter";
command = "${inputs.jovian-nixos.legacyPackages.${pkgs.system}.jovian-greeter}/bin/jovian-greeter ${cfg.user}";
};
};
};

users.users.jovian-greeter = {
isSystemUser = true;
group = "jovian-greeter";
};
users.groups.jovian-greeter = {};

security.pam.services = {
greetd.text = ''
auth requisite pam_nologin.so
auth sufficient pam_succeed_if.so user = ${cfg.user} quiet_success
auth required pam_unix.so
account sufficient pam_unix.so
password required pam_deny.so
session optional pam_keyinit.so revoke
session include login
'';
};

environment = {
systemPackages = [ inputs.jovian-nixos.legacyPackages.${pkgs.system}.jovian-greeter.helper ];
pathsToLink = [ "lib/jovian-greeter" ];
};
security.polkit.extraConfig = ''
polkit.addRule(function(action, subject) {
if (
action.id == "org.freedesktop.policykit.exec" &&
action.lookup("program") == "/run/current-system/sw/lib/jovian-greeter/consume-session" &&
subject.user == "jovian-greeter"
) {
return polkit.Result.YES;
}
});
'';

xdg.portal.configPackages = mkDefault [ inputs.jovian-nixos.legacyPackages.${pkgs.system}.gamescope-session ];
})
]);
}
32 changes: 32 additions & 0 deletions modules/nixos/steamos/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{ lib, ... }:

let
inherit (lib)
mkOption
types
;
in
{
imports = [
./steam.nix
./autostart.nix
./environment.nix
];
options = {
snowflake = {
steam = {
enable = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Whether to enable the Steam Deck UI.
When enabled, you can either use the `autoStart` option (preferred),
launch the Steam Deck UI from your Display Manager or
by running `start-gamescope-session`.
'';
};
};
};
};
}
41 changes: 41 additions & 0 deletions modules/nixos/steamos/environment.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{ config, lib, pkgs, ... }:

let
inherit (lib)
concatStringsSep
escapeShellArg
mapAttrsToList
mkIf
mkMerge
mkOption
types
;

cfg = config.snowflake.steam;
in
{
options = {
snowflake.steam = {
environment = mkOption {
type = with types; attrsOf str;
default = {};
description = ''
Additional environment variables or overrides to environment variables
that will be applied to the gamescope session.
'';
};
};
};
config = mkIf cfg.enable (mkMerge [
{
environment.etc."xdg/gamescope-session/environment" = {
text = concatStringsSep "\n" (
mapAttrsToList (
key: value:
"export ${escapeShellArg key}=${escapeShellArg value}"
) cfg.environment
);
};
}
]);
}
91 changes: 91 additions & 0 deletions modules/nixos/steamos/steam.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{ config, inputs, lib, pkgs, ... }:

let
inherit (lib)
mkDefault
mkIf
mkMerge
;

cfg = config.snowflake.steam;
in
{
config = mkIf cfg.enable (mkMerge [
{
warnings = []
++ lib.optional (!config.networking.networkmanager.enable)
"The Steam Deck UI integrates with NetworkManager (networking.networkmanager.enable) which is not enabled. NetworkManager is required to complete the first-time setup process.";
}
{
security.wrappers.gamescope = {
owner = "root";
group = "root";
source = "${pkgs.gamescope_git}/bin/gamescope";
capabilities = "cap_sys_nice+pie";
};

security.wrappers.galileo-mura-extractor = {
owner = "root";
group = "root";
source = "${inputs.jovian-nixos.legacyPackages.${pkgs.system}.galileo-mura}/bin/galileo-mura-extractor";
setuid = true;
};
}
{
# Enable MTU probing, as vendor does
# See: https://github.com/ValveSoftware/SteamOS/issues/1006
# See also: https://www.reddit.com/r/SteamDeck/comments/ymqvbz/ubisoft_connect_connection_lost_stuck/j36kk4w/?context=3
boot.kernel.sysctl."net.ipv4.tcp_mtu_probing" = true;

hardware.opengl = {
driSupport32Bit = true;
extraPackages = [ pkgs.gamescope-wsi_git ];
extraPackages32 = [ pkgs.pkgsi686Linux.gamescope-wsi_git ];
};

hardware.pulseaudio.support32Bit = true;
hardware.steam-hardware.enable = mkDefault true;

environment.systemPackages = [ inputs.jovian-nixos.legacyPackages.${pkgs.system}.gamescope-session inputs.jovian-nixos.legacyPackages.${pkgs.system}.steamos-polkit-helpers ];

systemd.packages = [ inputs.jovian-nixos.legacyPackages.${pkgs.system}.gamescope-session ];

services.xserver.displayManager.sessionPackages = [ inputs.jovian-nixos.legacyPackages.${pkgs.system}.gamescope-session ];

# Conflicts with powerbuttond
services.logind.extraConfig = ''
HandlePowerKey=ignore
'';

services.udev.packages = [
inputs.jovian-nixos.legacyPackages.${pkgs.system}.powerbuttond
];

# This rule allows the user to configure Wi-Fi in Deck UI.
#
# Steam modifies the system network configs via
# `org.freedesktop.NetworkManager.settings.modify.system`,
# which normally requires being in the `networkmanager` group.
security.polkit.extraConfig = ''
// snowflake-NixOS/steam: Allow users to configure Wi-Fi in Deck UI
polkit.addRule(function(action, subject) {
if (
action.id.indexOf("org.freedesktop.NetworkManager") == 0 &&
subject.isInGroup("users") &&
subject.local &&
subject.active
) {
return polkit.Result.YES;
}
});
'';

snowflake.steam.environment = {
# We don't support adopting a drive, yet.
STEAM_ALLOW_DRIVE_ADOPT = mkDefault "0";
# Ejecting doesn't work, either.
STEAM_ALLOW_DRIVE_UNMOUNT = mkDefault "0";
};
}
]);
}
3 changes: 0 additions & 3 deletions nixos/hosts/f80.nwk3.rabbito.tech/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@
environment.variables.DXVK_FILTER_DEVICE_NAME =
"AMD Radeon RX 7900 XTX (RADV NAVI31)";
# Debugging Gamescope
environment.enableDebugInfo = true;
environment.systemPackages = [ pkgs.gdb ];
chaotic.nyx.overlay.onTopOf = "user-pkgs";
# chaotic.nyx.overlay.enable = false;
# environment.variables.DRI_PRIME = "1";

}
3 changes: 2 additions & 1 deletion nixos/hosts/octo.nwk3.rabbito.tech/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
networking.useDHCP = lib.mkDefault true;
networking.hostName = "octo";
system.stateVersion = "23.11";
# boot.kernelPackages = pkgs.linuxPackages_testing;
environment.systemPackages = [ pkgs.gdb ];
chaotic.nyx.overlay.onTopOf = "user-pkgs";
}
Loading

0 comments on commit 5c9c97f

Please sign in to comment.