MatrixAI / TypeScript-Demo-Electron

TypeScript Electron Demo Project using Nix
https://matrix.ai
Apache License 2.0
8 stars 3 forks source link

Automatically determine downloads for electron zip bundle #17

Open tfc opened 1 year ago

tfc commented 1 year ago

Specification

Hi, i just learned from your repository how to put the electron squirrel windows installer bundling process into the nix sandbox. Thank you very much for sharing!

From reading the code, i assume that you generated the list of zip downloads from the checksums.js file from the electron folder manually. In order to facilitate updates, i automated this process. I don't know if there are specific reasons other than lack of time for you to not automate this, but nonetheless i decided to leave the snippet here in case someone (you or other readers of the code in this repo) may find it useful:

          electronZipBundle = nodeDeps:
            let
              items = builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.readFile "${nodeDeps}/lib/node_modules/electron/checksums.json"));
              itemNames = builtins.attrNames items;
              electronMatch = builtins.match "electron-(v[0-9.]*)-([a-z0-9]+)-([a-z0-9]+)\.zip";
              electronItemNames = builtins.filter (x: electronMatch x != null) itemNames;
              f = k:
                let
                  matches = electronMatch k;
                  version = builtins.elemAt matches 0;
                  sha256 = items.${k};
                  path = pkgs.fetchurl {
                    url = "https://github.com/electron/electron/releases/download/${version}/${k}";
                    inherit sha256;
                  };
                in
                {
                  inherit (path) name;
                  inherit path;
                };
            in
            pkgs.linkFarm "electron-zip-dir" (builtins.map f electronItemNames);
CMCDragonkai commented 1 year ago

Thanks! What are you building with electron and nix?

tfc commented 1 year ago

@CMCDragonkai I'm building applications that are implemented with react and purescript on linux, and then also crosscompile them to windows.

CMCDragonkai commented 1 year ago

You're cross compiling electron to windows? How does that work?

tfc commented 1 year ago

It's very easy with nix. I've even got installer generation and auto-update work with this, like a breeze. My github profile shows how to contact me via chat or mail, if you're interested i can explain it to you as i currently don't have that open source where i use it.