Refactors for module imports and lib utilities

- Updates import paths in flake to correct locations
- Rename lib file correctly
This commit is contained in:
Chris Toph 2025-06-30 02:36:47 -04:00
parent 38beb52fe5
commit 5df8547c98
7 changed files with 48 additions and 57 deletions

View file

@ -46,8 +46,8 @@
}
)
// {
homeManagerModules.play = import ./modules/home-manager.nix;
nixosModules.play = import ./modules/nixos.nix;
homeManagerModules.play = import ./modules/home;
nixosModules.play = import ./modules/nixos;
# Default module (home-manager)
homeManagerModules.default = self.homeManagerModules.play;

37
lib/default.nix Normal file
View file

@ -0,0 +1,37 @@
{ lib, ... }:
rec {
# Helper to convert Nix attrs to gamescope command-line arguments
toCliArgs =
attrs:
let
argToString =
name: value:
if builtins.isBool value then
lib.optionalString value "--${name}"
else
"--${name} ${toString value}";
in
lib.concatStringsSep " " (lib.mapAttrsToList argToString attrs);
# Helper to convert Nix attrs to fish 'set -x' commands
toEnvCommands =
attrs:
lib.concatStringsSep "\n" (
lib.mapAttrsToList (name: value: "set -x ${name} '${toString value}'") attrs
);
getPrimaryMonitor = monitors: lib.findFirst (m: m.primary) null monitors;
getMonitorDefaults =
monitors:
let
getPrimary = getPrimaryMonitor monitors;
in
{
WIDTH = if getPrimary != null then getPrimary.width else 1920;
HEIGHT = if getPrimary != null then getPrimary.height else 1080;
REFRESH_RATE = if getPrimary != null then getPrimary.refreshRate else 60;
VRR = if getPrimary != null then getPrimary.vrr else false;
HDR = if getPrimary != null then getPrimary.hdr else false;
};
}

View file

@ -1,53 +0,0 @@
{ lib }:
{
# Helper to convert Nix attrs to gamescope command-line arguments
toCliArgs =
attrs:
let
argToString =
name: value:
if builtins.isBool value then
lib.optionalString value "--${name}"
else
"--${name} ${toString value}";
in
lib.concatStringsSep " " (lib.mapAttrsToList argToString attrs);
# Helper to convert Nix attrs to fish 'set -x' commands
toEnvCommands =
attrs:
lib.concatStringsSep "\n" (
lib.mapAttrsToList (name: value: "set -x ${name} '${toString value}'") attrs
);
getPrimaryMonitor = monitors: lib.findFirst (m: m.primary) null monitors;
getMonitorDefaults = monitors: {
WIDTH =
let
pm = lib.play.getPrimaryMonitor monitors;
in
if pm != null then pm.width else 1920;
HEIGHT =
let
pm = lib.play.getPrimaryMonitor monitors;
in
if pm != null then pm.height else 1080;
REFRESH_RATE =
let
pm = lib.play.getPrimaryMonitor monitors;
in
if pm != null then pm.refreshRate else 60;
VRR =
let
pm = lib.play.getPrimaryMonitor monitors;
in
if pm != null then pm.vrr else false;
HDR =
let
pm = lib.play.getPrimaryMonitor monitors;
in
if pm != null then pm.hdr else false;
};
}

View file

@ -4,3 +4,4 @@
./gamescoperun.nix
./wrappers.nix
];
}

View file

@ -7,10 +7,13 @@
}:
let
# Extend lib with play utilities
playLib = import ../../lib { inherit lib; };
cfg = config.play.gamescoperun;
# Use shared lib functions
inherit (lib.play) toCliArgs toEnvCommands getMonitorDefaults;
inherit (playLib) toCliArgs toEnvCommands getMonitorDefaults;
# Get monitor defaults
monitorDefaults = getMonitorDefaults config.play.monitors;

View file

@ -6,10 +6,13 @@
}:
let
# Extend lib with play utilities
playLib = import ../../lib { inherit lib; };
cfg = config.play.wrappers;
# Use shared lib function
inherit (lib.play) toCliArgs;
inherit (playLib) toCliArgs;
# Function to create a wrapper for an application
mkWrapper =