feat(minecraft): make username configurable

This commit is contained in:
514fpv 2024-05-31 14:00:52 +08:00
parent d9dba8b68a
commit bfb06ba476
Signed by: koishi
SSH key fingerprint: SHA256:axz0uIzzY+5W19i7QOUuiw5LSqhKfCBKPf3L4xFRxLw
2 changed files with 10 additions and 5 deletions
home/minecraft

View file

@ -4,7 +4,7 @@
, ... }: with lib; let , ... }: with lib; let
inherit (config.passthrough) gui; inherit (config.passthrough) gui;
cfg = config.passthrough.minecraft; cfg = config.passthrough.minecraft;
enable = cfg.enable && config.home.username == "minecraft"; enable = cfg.enable && config.home.username == cfg.user;
in mkIf enable { in mkIf enable {
home.packages = with pkgs; [ home.packages = with pkgs; [
jdk8 jdk8

View file

@ -7,6 +7,11 @@
in { in {
options.home.minecraft = { options.home.minecraft = {
enable = mkEnableOption "minecraft game launcher and jvm"; enable = mkEnableOption "minecraft game launcher and jvm";
user = mkOption {
type = with types; str;
default = "minecraft";
description = "username which minecraft game client runs under";
};
}; };
config = { config = {
@ -15,14 +20,14 @@ in {
{ passthrough.minecraft = cfg; } { passthrough.minecraft = cfg; }
]; ];
users.profiles.minecraft = mkIf cfg.enable { users.profiles.minecraft = mkIf (cfg.enable && cfg.user == "minecraft") {
uid = 5801; uid = 5801;
description = "Minecraft"; description = "Minecraft";
picture = ../picture/aux.png; picture = ../picture/aux.png;
}; };
environment.persistence."/nix/persist".users.minecraft.directories = mkIf (cfg.enable && gui) [ environment.persistence."/nix/persist".users.${cfg.user} = mkIf (cfg.enable && gui) {
".local/share/PrismLauncher" directories = [ ".local/share/PrismLauncher" ];
]; };
}; };
} }