home/modules/prism-launcher: init
This commit is contained in:
@ -1,8 +1,6 @@
|
|||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
let
|
let
|
||||||
cfg = config.programs.prism-launcher;
|
cfg = config.programs.prism-launcher;
|
||||||
|
|
||||||
screenshotPathGlob = "${config.xdg.dataHome}/PrismLauncher/instances/*/.minecraft/screenshots";
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.programs.prism-launcher = {
|
options.programs.prism-launcher = {
|
||||||
@ -10,19 +8,29 @@ in
|
|||||||
|
|
||||||
package = lib.mkPackageOption pkgs "prismlauncher" { };
|
package = lib.mkPackageOption pkgs "prismlauncher" { };
|
||||||
|
|
||||||
|
stateDir = lib.mkOption {
|
||||||
|
description = "The directory where PrismLauncher stores it's state";
|
||||||
|
type = lib.types.path;
|
||||||
|
default = "${config.xdg.dataHome}/PrismLauncher";
|
||||||
|
defaultText = lib.literalExpression ''"''${config.xdg.dataHome}/PrismLauncher"'';
|
||||||
|
};
|
||||||
|
|
||||||
screenshotMover = {
|
screenshotMover = {
|
||||||
enable = lib.mkEnableOption "a systemd unit that automatically moves screenshots from all minecraft instances into a common dir";
|
enable = lib.mkEnableOption "a systemd unit that automatically moves screenshots from all minecraft instances into a common dir";
|
||||||
|
|
||||||
screenshotDir = lib.mkOption {
|
screenshotDir = lib.mkOption {
|
||||||
description = "Where to move the minecraft screenshots.";
|
description = "Where to move the minecraft screenshots.";
|
||||||
type = lib.types.path;
|
type = lib.types.path;
|
||||||
# TODO: priority list:
|
default = if config.xdg.userDirs.pictures != null
|
||||||
# - userDirs pictures
|
then "${config.xdg.userDirs.pictures}/prismlauncher-screenshots"
|
||||||
# - homeDir Pictures
|
else "${config.home.homeDirectory}/Pictures";
|
||||||
default = "${config.xdg.userDirs.pictures}/prismlauncher-screenshots";
|
defaultText = lib.literalExpression ''
|
||||||
# TODO: Literal expression for default
|
if config.xdg.userDirs.pictures != null
|
||||||
|
then "''${config.xdg.userDirs.pictures}/prismlauncher-screenshots"
|
||||||
|
else "''${config.home.homeDirectory}/Pictures"
|
||||||
|
'';
|
||||||
example = lib.literalExpression ''
|
example = lib.literalExpression ''
|
||||||
"''${config.home.homeDirectory}/minecraftScreenshots"
|
"''${config.home.homeDirectory}/minecraft-screenshots"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -35,7 +43,7 @@ in
|
|||||||
Install.WantedBy = [ "paths.target" ];
|
Install.WantedBy = [ "paths.target" ];
|
||||||
Unit.Description = "Watchdog that moves screenshots from all prismlauncher minecraft instances into a common dir";
|
Unit.Description = "Watchdog that moves screenshots from all prismlauncher minecraft instances into a common dir";
|
||||||
Path = {
|
Path = {
|
||||||
PathChanged = [ screenshotPathGlob ];
|
PathExistsGlob = [ "${cfg.stateDir}/instances/*/.minecraft/screenshots/*.png" ];
|
||||||
Unit = "prismlauncher-move-minecraft-screenshots.service";
|
Unit = "prismlauncher-move-minecraft-screenshots.service";
|
||||||
TriggerLimitIntervalSec = "1s";
|
TriggerLimitIntervalSec = "1s";
|
||||||
TriggerLimitBurst = "1";
|
TriggerLimitBurst = "1";
|
||||||
@ -46,10 +54,32 @@ in
|
|||||||
Unit.Description = "Watchdog that moves screenshots from all prismlauncher minecraft instances into a common dir";
|
Unit.Description = "Watchdog that moves screenshots from all prismlauncher minecraft instances into a common dir";
|
||||||
Service = {
|
Service = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
# TODO: expand glob inside a shell
|
ExecStart = lib.getExe (pkgs.writeShellApplication {
|
||||||
ExecStart = "${pkgs.coreutils}/bin/mv ${screenshotPathGlob} '${cfg.screenshotMover.screenshotDir}'";
|
name = "prismlauncher-move-minecraft-screenshots.sh";
|
||||||
|
runtimeInputs = with pkgs; [ coreutils findutils ];
|
||||||
|
text = let
|
||||||
|
instancesDir = "${cfg.stateDir}/instances";
|
||||||
|
in ''
|
||||||
|
shopt -s nullglob
|
||||||
|
|
||||||
|
for idir in "${instancesDir}"/*/; do
|
||||||
|
INSTANCE_NAME="''${idir#${instancesDir}/}"
|
||||||
|
INSTANCE_NAME="''${INSTANCE_NAME%'/'}"
|
||||||
|
SCREENSHOT_TARGET_DIR="${cfg.screenshotMover.screenshotDir}/$INSTANCE_NAME"
|
||||||
|
mkdir -p "''${SCREENSHOT_TARGET_DIR}"
|
||||||
|
if [ -d "${instancesDir}/$INSTANCE_NAME"/.minecraft/screenshots ]; then
|
||||||
|
for screenshot in "${instancesDir}/$INSTANCE_NAME"/.minecraft/screenshots/*.png; do
|
||||||
|
echo "Moving '$screenshot' -> '$SCREENSHOT_TARGET_DIR'"
|
||||||
|
cp --preserve=all "$screenshot" "$SCREENSHOT_TARGET_DIR"
|
||||||
|
rm "$screenshot"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
});
|
||||||
|
|
||||||
PrivateUsers = true;
|
PrivateUsers = true;
|
||||||
|
PrivateNetwork = true;
|
||||||
ProtectSystem = true;
|
ProtectSystem = true;
|
||||||
NoNewPrivileges = true;
|
NoNewPrivileges = true;
|
||||||
ProtectKernelTunables = true;
|
ProtectKernelTunables = true;
|
||||||
@ -58,5 +88,9 @@ in
|
|||||||
RestrictNamespaces = true;
|
RestrictNamespaces = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
systemd.user.tmpfiles.rules = lib.mkIf cfg.screenshotMover.enable [
|
||||||
|
"'d' '${cfg.screenshotMover.screenshotDir}' - ${config.home.username} - - -"
|
||||||
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user