prismlauncher: add module

This PR adds a module with basic options for PrismLauncher,
a FOSS Minecraft launcher / mod manager.
This commit is contained in:
zorrobert 2024-06-17 12:00:31 +02:00
parent 9b53a10f4c
commit 84b136076d
6 changed files with 201 additions and 0 deletions

View file

@ -193,6 +193,7 @@ let
./programs/poetry.nix
./programs/powerline-go.nix
./programs/pqiv.nix
./programs/prismlauncher.nix
./programs/pubs.nix
./programs/pyenv.nix
./programs/pylint.nix

View file

@ -0,0 +1,145 @@
{ config, lib, pkgs, ... }:
let
cfg = config.programs.prismlauncher;
# set config path depending on the OS
configPath = if pkgs.stdenv.isDarwin then
"${config.xdg.dataHome}/Application Support/PrismLauncher"
else
"${config.xdg.dataHome}/PrismLauncher";
in {
meta.maintainers = [ lib.hm.maintainers.zorrobert ];
options.programs.prismlauncher = {
enable = lib.mkEnableOption "prismlauncher";
package = lib.mkOption {
type = lib.types.package;
default = pkgs.prismlauncher;
defaultText = lib.literalExpression "pkgs.prismlauncher";
description = "The PrismLauncher package to use.";
};
extraConfig = lib.mkOption {
type = lib.types.attrs;
default = { };
example = {
General = {
ApplicationTheme = "system";
AutoCloseConsole = false;
BackgroundCat = "kitteh";
};
};
description = "Additional settings for prismlauncher.cfg";
};
### Launcher
launcher = {
instances = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "instances";
description = "The folder used by PrismLauncher to store instances.";
};
mods = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "mods";
description = "The folder where PrismLauncher searches for local mods.";
};
icons = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "icons";
description = "The folder where PrismLauncher stores custom icons";
};
downloads = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "/home/username/Downloads";
description = "The folder PrismLauncher uses for downloads.";
};
};
### Java
java = {
maximumMemoryAllocation = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
example = 4096;
description =
"The maximum amount of memory Minecraft is allowed to use.";
};
path = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example =
"/nix/store/ly19kvgvcl2if4i3hv60x1sg7g69vzyv-openjdk-21+35/bin/java";
description = "The Java Runtime path for PrismLauncher.";
};
};
### Language
language = {
language = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "en_GB";
description = "The language used by PrismLauncher";
};
useSystemLocales = lib.mkOption {
type = lib.types.nullOr lib.types.bool;
default = null;
description = "Set the language to the system default";
};
};
};
config = lib.mkIf cfg.enable {
home.packages = [ cfg.package ];
home.activation = {
createPrismLauncherConfig = lib.hm.dag.entryAfter [ "linkGeneration" ]
(lib.concatStringsSep "\n" (
# map defined options to setting names in prismlauncher.cfg and filter out undefined options
(lib.attrsets.mapAttrsToList (name: value: ''
${pkgs.libsForQt5.kconfig}/bin/kwriteconfig5 --file ${configPath}/prismlauncher.cfg --group 'General' --key '${name}' '${
builtins.toString value
}'
'') (lib.attrsets.filterAttrsRecursive (n: v: v != null) {
### Launcher
InstanceDir = cfg.launcher.instances;
CentralModsDir = cfg.launcher.mods;
IconsDir = cfg.launcher.icons;
DownloadsDir = cfg.launcher.downloads;
### Minecraft
### Java
MaxMemAlloc = cfg.java.maximumMemoryAllocation;
JavaPath = cfg.java.path;
### Language
Language = cfg.language.language;
UseSystemLocale = cfg.language.useSystemLocales;
### Custom Commands
### Environment Variables
### Proxy
### External Tools
### Accounts
### APIs
}))
# add settings from extraConfig
++ (builtins.map (group:
lib.concatStringsSep "\n" ((lib.attrsets.mapAttrsToList
(name: value: ''
${pkgs.libsForQt5.kconfig}/bin/kwriteconfig5 --file ${configPath}/prismlauncher.cfg --group '${group}' --key '${name}' '${value}'
'') cfg.extraConfig.${group})))
(builtins.attrNames cfg.extraConfig))));
};
};
}

View file

@ -125,6 +125,7 @@ in import nmtSrc {
./modules/programs/pls
./modules/programs/poetry
./modules/programs/powerline-go
./modules/programs/prismlauncher
./modules/programs/pubs
./modules/programs/pyenv
./modules/programs/qcal

View file

@ -0,0 +1,10 @@
[General]
InstanceDir=/home/user/PrismLauncher/instances
CentralModsDir=/home/user/PrismLauncher/mods
IconsDir=/home/user/PrismLauncher/icons
DownloadsDir=/home/user/PrismLauncher/downloads
MaxMemAlloc=5678
JavaPath=/example-path
Language=en_GB
UseSystemLocale=true
BackgroundCat=kitteh

View file

@ -0,0 +1,43 @@
{ config, lib, pkgs, ... }:
{
programs.prismlauncher = {
enable = true;
extraConfig = {
General = {
BackgroundCat = "kitteh";
};
};
launcher = {
instances = "/home/user/PrismLauncher/instances";
mods = "/home/user/PrismLauncher/mods";
icons = "/home/user/PrismLauncher/icons";
downloads = "/home/user/PrismLauncher/downloads";
};
java = {
maximumMemoryAllocation = 5678;
path = "/example-path";
};
# language = {
# language = "en_GB";
# useSystemLocales = true;
# };
};
test.stubs.prismlauncher = { };
nmt.script = ''
assertFileContains activate \
'${config.xdg.dataHome}/PrismLauncher/prismlauncher.cfg'
generated="$(grep -o '${config.xdg.dataHome}/PrismLauncher/prismlauncher.cfg' $TESTED/activate)"
diff -u "$generated" ${./basic-configuration.cfg}
echo "THIS TEST IS A TEMPORARY PLACEHOLDER! PLEASE WRITE THIS TEST!"
exit 1
'';
# diff -u home-files/.local/share/PrismLauncher/prismlauncher.cfg ${./basic-configuration.cfg}
# assertFileContent home-files/.local/share/PrismLauncher/prismlauncher.cfg ${./basic-configuration.cfg}
# generated="$(grep -o '/nix/store/.*-prismlauncher.cfg' $TESTED/activate)"
# diff -u "$generated" ${./basic-configuration.cfg}
}

View file

@ -0,0 +1 @@
{ prismlauncher-basic-configuration = ./basic-configuration.nix; }