emmanuelrosa / erosanix

My main NixOS/Nix Flakes repository
MIT License
78 stars 4 forks source link

Add Micro-Cap package #12

Closed nikp123 closed 4 months ago

nikp123 commented 5 months ago

Since you're the only one (on GitHub IIRC) who has packaged windows apps under nix, I think its appropriate to put it here.

Micro-Cap is a electronics simulation suite that is useful for any electronics student, engineer or hobbyist. It was made by a now defunct company "Spectrum Software" (you can read about it more on wikipedia).

But long story short: It's a really neat tool.

The package itself is NOT free software (FOSS) by any definition but its freely available to download, at least it was until the website shut down in early 2023.

The install is not automated so you'll still have to go over InstallShield dialogs, but honestly i feel that's way safer than trying to nixify it and potentially breaking something. And I've tried the common InstallShield flags and arguments and they unfortunately don't do the job. But as long as the user doesn't change any of the directories in the installation path everything should work as intended.

emmanuelrosa commented 4 months ago

I just noticed this PR. Sorry about that.

I'll take a look at this.

emmanuelrosa commented 4 months ago

OK, this looks good but some changes are needed. The version is actually 12.2.0.5, and there are some additional files which should be mapped. Here's a patch:

diff --git a/pkgs/microcap.nix b/pkgs/microcap.nix
index be8a5e1..fd155d8 100644
--- a/pkgs/microcap.nix
+++ b/pkgs/microcap.nix
@@ -11,7 +11,7 @@
 , copyDesktopIcons
 , ... }: let
   pname = "microcap";
-  version = "12.2.0.2"; # The final version, I suppose
+  version = "12.2.0.5"; # The final version, I suppose

   # Press 'F' for Spectrum Software
   src = fetchzip {
@@ -34,8 +34,17 @@ in mkWindowsApp rec {
   name = pname;

   fileMap = {
-    # This file is changed on runtime, so we'll have to link it
-    "$HOME/.config/Micro-Cap/mcap.dat" = "drive_c/MC12/MCAP.dat";
+    # These files are changed on runtime, so we'll have to link them.
+    "$HOME/.config/Micro-Cap/mcap.dat" = "drive_c/MC12/mcap.dat";
+    "$HOME/.config/Micro-Cap/tool.dat" = "drive_c/MC12/tool.dat";
+    "$HOME/.config/Micro-Cap/MDL.dat" = "drive_c/MC12/MDL.dat";
+    "$HOME/.config/Micro-Cap/default.san" = "drive_c/MC12/default.san";
+    "$HOME/.config/Micro-Cap/WFB.BIN" = "drive_c/MC12/WFB.BIN";
+    "$HOME/.config/Micro-Cap/standard.shp" = "drive_c/MC12/standard.shp";
+    "$HOME/.config/Micro-Cap/Standard.cmp" = "drive_c/MC12/Standard.cmp";
+    "$HOME/.config/Micro-Cap/standard.tbk" = "drive_c/MC12/standard.tbk";
+    "$HOME/.config/Micro-Cap/standard.pkg" = "drive_c/MC12/standard.pkg";
+    "$HOME/.config/Micro-Cap/DATA" = "drive_c/MC12/DATA";
   };

   winAppInstall = ''

I made several attempts to save a .cir file, and it would not save. I didn't get any errors, I just couldn't save anything within nor outside of the DATA directory. But that could be because I don't know how to use the software.

nikp123 commented 4 months ago

OK, this looks good but some changes are needed. The version is actually 12.2.0.5, and there are some additional files which should be mapped. Here's a patch:

diff --git a/pkgs/microcap.nix b/pkgs/microcap.nix
index be8a5e1..fd155d8 100644
--- a/pkgs/microcap.nix
+++ b/pkgs/microcap.nix
@@ -11,7 +11,7 @@
 , copyDesktopIcons
 , ... }: let
   pname = "microcap";
-  version = "12.2.0.2"; # The final version, I suppose
+  version = "12.2.0.5"; # The final version, I suppose

   # Press 'F' for Spectrum Software
   src = fetchzip {
@@ -34,8 +34,17 @@ in mkWindowsApp rec {
   name = pname;

   fileMap = {
-    # This file is changed on runtime, so we'll have to link it
-    "$HOME/.config/Micro-Cap/mcap.dat" = "drive_c/MC12/MCAP.dat";
+    # These files are changed on runtime, so we'll have to link them.
+    "$HOME/.config/Micro-Cap/mcap.dat" = "drive_c/MC12/mcap.dat";
+    "$HOME/.config/Micro-Cap/tool.dat" = "drive_c/MC12/tool.dat";
+    "$HOME/.config/Micro-Cap/MDL.dat" = "drive_c/MC12/MDL.dat";
+    "$HOME/.config/Micro-Cap/default.san" = "drive_c/MC12/default.san";
+    "$HOME/.config/Micro-Cap/WFB.BIN" = "drive_c/MC12/WFB.BIN";
+    "$HOME/.config/Micro-Cap/standard.shp" = "drive_c/MC12/standard.shp";
+    "$HOME/.config/Micro-Cap/Standard.cmp" = "drive_c/MC12/Standard.cmp";
+    "$HOME/.config/Micro-Cap/standard.tbk" = "drive_c/MC12/standard.tbk";
+    "$HOME/.config/Micro-Cap/standard.pkg" = "drive_c/MC12/standard.pkg";
+    "$HOME/.config/Micro-Cap/DATA" = "drive_c/MC12/DATA";
   };

   winAppInstall = ''

I made several attempts to save a .cir file, and it would not save. I didn't get any errors, I just couldn't save anything within nor outside of the DATA directory. But that could be because I don't know how to use the software.

Thats because you have to launch it AFTER the installation script has finished. Found that bug myself, kinda wished I could prevent the installer from launching the executable. Sorry for not posting that here, I forgot.

emmanuelrosa commented 4 months ago

Yes, that's a related issue. When I allowed the installer to launch the application, the app presented a warning saying that I should exit the application and run it again to finalize the installation. I did that, which allowed the installer to finish.

It's easier to simply disable launching the application to avoid that quirk, but that's not the default setting in the installer.

However, I attempted to save a file after the app had already been installed. I even had the data directory mapped and the files were there. But for some reason my file didn't save.-------- Original Message --------On 3/31/24 6:46 AM, nikp123 wrote:

OK, this looks good but some changes are needed. The version is actually 12.2.0.5, and there are some additional files which should be mapped. Here's a patch: diff --git a/pkgs/microcap.nix b/pkgs/microcap.nix index be8a5e1..fd155d8 100644 --- a/pkgs/microcap.nix +++ b/pkgs/microcap.nix @@ -11,7 +11,7 @@ , copyDesktopIcons , ... }: let pname = "microcap";

I made several attempts to save a .cir file, and it would not save. I didn't get any errors, I just couldn't save anything within nor outside of the DATA directory. But that could be because I don't know how to use the software.

Thats because you have to launch it AFTER the installation script has finished. Found that bug myself, kinda wished I could prevent the installer from launching the executable.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.> [ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": "https://github.com/emmanuelrosa/erosanix/pull/12#issuecomment-2028637606", "url": "https://github.com/emmanuelrosa/erosanix/pull/12#issuecomment-2028637606", "name": "View Pull Request" }, "description": "View this Pull Request on GitHub", "publisher": { @.***": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

nikp123 commented 4 months ago

Also might giving me some guidance, if you know, on how to tame InstallShield installers?

Reason being: I want to have an another go at it.

emmanuelrosa commented 4 months ago

I haven't done much with InstallShield installers. I've been lucky thus far.

Something that might help you with the troubleshooting is to run the installer under "wineshell":

$ nix run github:emmanuelrosa/erosanix#wineshell-wineWow64
$ # Now you're in a BASH shell with wine available and a temporary WINEPREFIX.
$ wine setup.exe /r

After installation, see if there's a setup.iss at $WINEPREFIX/drive_c/windows/ If there is, grab a copy of it before you exit.

$ exit

You can then use the setup.iss file to automate the installation, but it has to be in the same directory as setup.exe:

  issFile = ./setup.iss;

  winAppInstall = ''
    cp "${issFile}" "$WINEPREFIX/drive_c/"
    cp "${src}/setup.exe" "$WINEPREFIX/drive_c/"
    $WINE "$WINEPREFIX/drive_c/setup.exe" /s /sms
    wineserver -w
  '';
nikp123 commented 4 months ago

$ wine setup.exe /r

Thank you, this is EXACTLY what I needed. It does record a setup.iss exactly where you said it will. Will update this package shortly

nikp123 commented 4 months ago

For some reason I am running into a bug where a directory is missing. Has something changed in the meantime?

nikp123@Wall /e/nixos> microcap
mktemp: Unknown option 'suffix=.mkwindowsApp' (see "mktemp --help")
/nix/store/qry797lqxf8bq33154jrq6l3chs1l6al-libwindowsapp.bash: line 39: : No such file or directory
/nix/store/qry797lqxf8bq33154jrq6l3chs1l6al-libwindowsapp.bash: line 40: : No such file or directory
cat: : No such file or directory
mktemp: Unknown option 'suffix=.mkwindowsApp' (see "mktemp --help")
/nix/store/qry797lqxf8bq33154jrq6l3chs1l6al-libwindowsapp.bash: line 39: : No such file or directory
/nix/store/qry797lqxf8bq33154jrq6l3chs1l6al-libwindowsapp.bash: line 40: : No such file or directory
cat: : No such file or directory
Relevant code is this function ``` wa_init_layer () { local input_hash=$1 local reference=$2 local layer_dir=$(_wa_get_layer $input_hash) local incomplete_layer_dir="$layer_dir.incomplete" if [ ! -d "$layer_dir" ] then if [ ! -d "$incomplete_layer_dir" ] then mkdir -p "$incomplete_layer_dir/wineprefix" pushd "$incomplete_layer_dir" > /dev/null echo "$WA_API" > api echo "$reference" > refs chmod ugo-w api popd > /dev/null fi else local tmp_refs=$(mktemp --suffix=.mkwindowsApp) cat "$layer_dir/refs" > "$tmp_refs" echo "$reference" >> "$tmp_refs" cat "$tmp_refs" | sort | uniq > "$layer_dir/refs" rm -f "$tmp_refs" fi printf "%s" $layer_dir } ```
emmanuelrosa commented 4 months ago

That's weird. No I haven't changed anything. mktemp is a part of coreutils. I don't see how you would end up with a different implementation, such as busybox or tinycore.

nikp123 commented 4 months ago

That's weird. No I haven't changed anything. mktemp is a part of coreutils. I don't see how you would end up with a different implementation, such as busybox or tinycore.

You're right, toybox seems to break it. image

This should be a seperate issue. Installing it in the global environment breaks that script.

Update: it DOES break it, when i remove it from the global environment, it works just fine

nikp123 commented 4 months ago

Also how may i test changes locally so that i don't have to go through a whole git push, nix flake update and then nixOS-rebuild cycle?

EDIT: NVM, figured it out (for those following along: nix run thing#microcap)

emmanuelrosa commented 4 months ago

Yes, nix run is a way to do that. To test adding it to your NixOS configuration you can use --override-input:

nixos-rebuild test --override-input erosanix PATH_TO_LOCAL_EROSANIX_REPO

That would allow you to skip the git push and flake update.

nikp123 commented 4 months ago

Yep, I can't get away from that save bug. Not sure whats going on.

emmanuelrosa commented 4 months ago

I got saving to work. I was able to save a circuit file, exit the software, run the software again and open the saved circuit file.

The fix is to configure the WINEPREFIX to act like winxp. The patch below:

commit c99ad780f518326e2b3124dda35f32abc9138470
Author: Emmanuel Rosa
Date:   Mon Apr 1 16:40:39 2024 -0400

    microcap: file save fix

diff --git a/pkgs/microcap/default.nix b/pkgs/microcap/default.nix
index 112a0a8..1473fd1 100644
--- a/pkgs/microcap/default.nix
+++ b/pkgs/microcap/default.nix
@@ -35,7 +35,9 @@ in mkWindowsApp rec {

   fileMap = {
     # This file is changed on runtime, so we'll have to link it
-    "$HOME/.config/Micro-Cap/mcap.dat" = "drive_c/MC12/MCAP.dat";
+    "$HOME/.config/Micro-Cap/mcap.dat" = "drive_c/MC12/mcap.dat";
+    "$HOME/.config/Micro-Cap/DATA" = "drive_c/MC12/DATA"; # User files.
+    "$HOME/.cache/Micro-Cap/LIBRARY" = "drive_c/MC12/LIBRARY"; # Cached files.
   };

   issFile = ./setup.iss;
@@ -44,7 +46,7 @@ in mkWindowsApp rec {
     mkdir                 "$WINEPREFIX/drive_c/microcap"
     cp "${issFile}"       "$WINEPREFIX/drive_c/microcap/setup.iss"
     cp -rf "${src}/."     "$WINEPREFIX/drive_c/microcap"
-    ls                    "$WINEPREFIX/drive_c/microcap"
+    winetricks winxp
     $WINE                 "$WINEPREFIX/drive_c/microcap/setup.exe" /s /sms
     wineserver -w         # Wait for the above wine process to finish
     chmod -R 777          "$WINEPREFIX/drive_c/microcap"
nikp123 commented 4 months ago

The patch below:

How do I merge this, do I give you push access or do I merge those differences myself?

emmanuelrosa commented 4 months ago

You can just apply the patch yourself. Or reproduce the changes yourself.-------- Original Message --------On 4/1/24 5:05 PM, nikp123 wrote:

The patch below:

How do I merge this, do I give you push access or do I merge those differences myself?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.> [ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": "https://github.com/emmanuelrosa/erosanix/pull/12#issuecomment-2030552791", "url": "https://github.com/emmanuelrosa/erosanix/pull/12#issuecomment-2030552791", "name": "View Pull Request" }, "description": "View this Pull Request on GitHub", "publisher": { @.***": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

nikp123 commented 4 months ago

I couldn't reproduce the results, unfortunately. It still fails to save.

emmanuelrosa commented 4 months ago

Hmm...

Use nix shell instead of nix run so that you can set a special environment variable:

$ nix shell ...
$ WA_RUN_APP=0 microcap
$ # Now you're in a nested BASH shell in the same environment that microcap runs in.
$ winecfg

You'll now see the Wine configuration window. Select the "Applications" tab and check if the Windows version is "Windows XP" or "Windows XP 64"

You'll have to run exit twice to get out of both shells.

The launcher script looks for the environment variable WA_RUN_APP, and if it's set to 0 it will perform all of the usual steps except that it will not run the application. Instead it drops you into a shell. I put that in for troubleshooting.

nikp123 commented 4 months ago

Great, seems to work now. I didn't even have to change it in winecfg. Maybe it was a cache issue? Who knows?

emmanuelrosa commented 4 months ago

Awesome!

If you don't mind, I'd like to squash the commits.

nikp123 commented 4 months ago

No problem, do as you please.

emmanuelrosa commented 4 months ago

Ths squashed commit is now on my master branch, see 0ea1247

nikp123 commented 4 months ago

Thanks a lot for your help