{ stdenv, makeWrapper, makeDesktopItem, copyDesktopItems, wineWowPackages, vcredist2019, # Full win64 Wine prefix produced by installing CODESYS 3.5.15.20 interactively # (with dotnet462, msxml4/6 via winetricks). See pkgs/codesys3/README for steps. src, }: let wine = wineWowPackages.stable; in stdenv.mkDerivation { pname = "codesys3"; version = "3.5.15.20"; inherit src; sourceRoot = "."; nativeBuildInputs = [ makeWrapper copyDesktopItems ]; desktopItems = [ (makeDesktopItem { name = "codesys3"; desktopName = "CODESYS 3.5"; genericName = "PLC Programming"; exec = "codesys3"; categories = [ "Development" ]; startupWMClass = "CODESYS.exe"; }) ]; installPhase = '' runHook preInstall # The src is a full wine prefix (win64). Copy it to the store as a read-only # template; the wrapper inflates it to ~/.local/share/codesys3 on first run. install -d $out/share/codesys3-prefix cp -r . $out/share/codesys3-prefix/ # Also expose the vcredist2019 DLLs so the wrapper can drop them in on demand. install -d $out/share/codesys3-windll cp ${vcredist2019}/windll/*.dll $out/share/codesys3-windll/ makeWrapper ${wine}/bin/wine $out/bin/codesys3 \ --run ' PREFIX="$HOME/.local/share/codesys3-prefix" if [ ! -f "$PREFIX/.codesys3-ready" ]; then echo "Setting up CODESYS 3 prefix (first run, may take a moment)..." rm -rf "$PREFIX" cp -r '"$out/share/codesys3-prefix"' "$PREFIX" chmod -R u+w "$PREFIX" touch "$PREFIX/.codesys3-ready" fi export WINEPREFIX="$PREFIX" export WINEARCH=win64 export WINEDEBUG=-all ' \ --add-flags '"C:\\Program Files\\CODESYS 3.5.15.20\\CODESYS\\Common\\CODESYS.exe"' runHook postInstall ''; meta.mainProgram = "codesys3"; }