mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 04:19:19 -08:00
fix(steam): better data management and setup
This commit is contained in:
parent
81bd1a1a15
commit
475273692d
5 changed files with 822 additions and 284 deletions
|
|
@ -5,12 +5,25 @@
|
|||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (inputs.self.lib.lib) userIs;
|
||||
inherit (inputs.self.lib.lib) mkWinPath userIs;
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib.modules) mkIf mkMerge mkDefault mkOptionDefault;
|
||||
inherit (lib.attrsets) filterAttrs mapAttrsToList listToAttrs nameValuePair;
|
||||
inherit (lib.lists) singleton;
|
||||
inherit (lib.strings) removePrefix;
|
||||
cfg = config.services.steam.accountSwitch;
|
||||
machineModule = { config, name, ... }: {
|
||||
options = with lib.types; {
|
||||
name = mkOption {
|
||||
type = str;
|
||||
default = name;
|
||||
};
|
||||
owner = mkOption {
|
||||
type = str;
|
||||
default = "admin";
|
||||
};
|
||||
};
|
||||
};
|
||||
in {
|
||||
options.services.steam.accountSwitch = with lib.types; {
|
||||
enable = mkEnableOption "steam-account-switch";
|
||||
|
|
@ -52,6 +65,10 @@ in {
|
|||
users = mkOption {
|
||||
type = listOf str;
|
||||
};
|
||||
machines = mkOption {
|
||||
type = attrsOf (submodule machineModule);
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
|
||||
config = let
|
||||
|
|
@ -76,35 +93,34 @@ in {
|
|||
inherit owner;
|
||||
inherit (shared) group mode;
|
||||
};
|
||||
setupFiles =
|
||||
singleton {
|
||||
${cfg.rootDir} = toplevel;
|
||||
${cfg.binDir} = toplevel;
|
||||
${cfg.binDir + "/users"} = shared;
|
||||
${cfg.dataDir} = toplevel;
|
||||
${cfg.sharedDataDir} = shared;
|
||||
${cfg.workingDir} = toplevel;
|
||||
${cfg.sharedWorkingDir} = shared;
|
||||
}
|
||||
++ map (owner: {
|
||||
${cfg.dataDir + "/${owner}"} = personal owner;
|
||||
${cfg.workingDir + "/${owner}"} = personal owner;
|
||||
})
|
||||
cfg.users;
|
||||
userBinFiles = listToAttrs (map (user:
|
||||
nameValuePair "${cfg.binDir}/users/${user}.bat" {
|
||||
inherit (toplevel) owner group;
|
||||
mode = "0755";
|
||||
type = "copy";
|
||||
src = pkgs.writeTextFile {
|
||||
name = "steam-${user}.bat";
|
||||
executable = true;
|
||||
text = ''
|
||||
setx GENSO_STEAM_USER ${user}
|
||||
'';
|
||||
};
|
||||
})
|
||||
cfg.users);
|
||||
setupFiles = singleton {
|
||||
${cfg.rootDir} = toplevel;
|
||||
${cfg.binDir} = toplevel;
|
||||
${cfg.binDir + "/users"} = shared;
|
||||
${cfg.dataDir} = toplevel;
|
||||
${cfg.sharedDataDir} = shared;
|
||||
${cfg.workingDir} = toplevel;
|
||||
${cfg.sharedWorkingDir} = shared;
|
||||
} ++ map (owner: {
|
||||
${cfg.dataDir + "/${owner}"} = personal owner;
|
||||
${cfg.workingDir + "/${owner}"} = personal owner;
|
||||
}) cfg.users
|
||||
++ mapAttrsToList (_: machine: {
|
||||
${cfg.dataDir + "/${machine.name}"} = personal machine.owner;
|
||||
${cfg.workingDir + "/${machine.name}"} = personal machine.owner;
|
||||
}) cfg.machines;
|
||||
userBinFiles = listToAttrs (map (user: nameValuePair "${cfg.binDir}/users/${user}.bat" {
|
||||
inherit (toplevel) owner group;
|
||||
mode = "0755";
|
||||
type = "copy";
|
||||
src = pkgs.writeTextFile {
|
||||
name = "steam-${user}.bat";
|
||||
executable = true;
|
||||
text = ''
|
||||
setx GENSO_STEAM_USER ${user}
|
||||
'';
|
||||
};
|
||||
}) cfg.users);
|
||||
in {
|
||||
enable = mkIf (cfg.enable || cfg.setup) true;
|
||||
files = mkMerge [
|
||||
|
|
@ -112,5 +128,18 @@ in {
|
|||
(mkIf cfg.enable userBinFiles)
|
||||
];
|
||||
};
|
||||
lib.steam = {
|
||||
mkSharePathWith = {
|
||||
path,
|
||||
winRoot ? "%GENSO_SMB_SHARED_MOUNT%",
|
||||
}: mkWinPath (
|
||||
winRoot
|
||||
+ "/${cfg.sharePath}"
|
||||
+ "/${removePrefix (cfg.rootDir + "/") path}"
|
||||
);
|
||||
mkSharePath = path: config.lib.steam.mkSharePathWith {
|
||||
inherit path;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue