Files
nix/modules/software/cad/magica.nix
T
2026-10-25 10:08:15 -05:00

61 lines
2.5 KiB
Nix

# MagicaVoxel / MagicaCSG via umu + Proton-GE.
# Binaries live in ./_magica (git-excluded), so this needs --impure eval.
{
den.aspects.software.cad.homeManager = { config, lib, pkgs, ... }:
let
apps = {
voxel = { name = "MagicaVoxel"; exe = "MagicaVoxel.exe"; bin = "magicavoxel"; mime = "model/x-vox"; ext = "vox"; };
csg = { name = "MagicaCSG"; exe = "MagicaCSG.exe"; bin = "magicacsg"; mime = "model/x-mcsg"; ext = "mcsg"; };
};
srcOf = app: "${config.home.homeDirectory}/nix/modules/software/cad/_magica/${app}";
present = lib.filterAttrs (app: _: builtins.pathExists (srcOf app)) apps;
storeOf = app: builtins.path { path = srcOf app; name = "magica-${app}"; };
launcher = app: a: let store = storeOf app; in pkgs.writeShellApplication {
name = a.bin;
runtimeInputs = [ pkgs.umu-launcher pkgs.coreutils pkgs.rsync ];
text = ''
base="''${XDG_DATA_HOME:-$HOME/.local/share}/magica/${app}"
export GAMEID=umu-0
export PROTONPATH=${pkgs.proton-ge-bin.steamcompattool}
export WINEPREFIX="$base/prefix"
mkdir -p "$base/app" "$WINEPREFIX"
if [ "$(cat "$base/stamp" 2>/dev/null)" != "${store}" ]; then
excl=()
[ -d "$base/app/config" ] && excl=(--exclude=/config)
rsync -r --chmod=u+w "''${excl[@]}" "${store}/" "$base/app/"
chmod -R u+w "$base/app"
echo "${store}" > "$base/stamp"
fi
mkdir -p "$base/app/cache" "$base/app/export"
args=()
for f in "$@"; do args+=("$(realpath -- "$f")"); done
cd "$base/app"
exec umu-run ${a.exe} "''${args[@]}"
'';
};
in
{
home.packages = lib.mapAttrsToList launcher present;
xdg.dataFile."mime/packages/magica.xml".text = ''
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
${lib.concatMapStrings (a: ''
<mime-type type="${a.mime}">
<comment>${a.name} model</comment>
<glob pattern="*.${a.ext}"/>
</mime-type>
'') (lib.attrValues apps)}</mime-info>
'';
xdg.desktopEntries = lib.mapAttrs' (app: a: lib.nameValuePair a.bin ({
inherit (a) name;
exec = "${a.bin} %f";
categories = [ "Graphics" ];
mimeType = [ a.mime ];
} // lib.optionalAttrs (builtins.pathExists "${srcOf app}/config/font/icon.png") {
icon = "${storeOf app}/config/font/icon.png";
})) present;
};
}