diff --git a/modules/modules.nix b/modules/modules.nix index 4e1f0e20..35834854 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -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 diff --git a/modules/programs/prismlauncher.nix b/modules/programs/prismlauncher.nix new file mode 100755 index 00000000..80c2ecf9 --- /dev/null +++ b/modules/programs/prismlauncher.nix @@ -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)))); + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 4d8d49d4..7b3d1fc4 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -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 diff --git a/tests/modules/programs/prismlauncher/basic-configuration.cfg b/tests/modules/programs/prismlauncher/basic-configuration.cfg new file mode 100644 index 00000000..c71d6380 --- /dev/null +++ b/tests/modules/programs/prismlauncher/basic-configuration.cfg @@ -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 diff --git a/tests/modules/programs/prismlauncher/basic-configuration.nix b/tests/modules/programs/prismlauncher/basic-configuration.nix new file mode 100644 index 00000000..ff48f476 --- /dev/null +++ b/tests/modules/programs/prismlauncher/basic-configuration.nix @@ -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} +} + diff --git a/tests/modules/programs/prismlauncher/default.nix b/tests/modules/programs/prismlauncher/default.nix new file mode 100644 index 00000000..178adf21 --- /dev/null +++ b/tests/modules/programs/prismlauncher/default.nix @@ -0,0 +1 @@ +{ prismlauncher-basic-configuration = ./basic-configuration.nix; }