Skip to content

Commit

Permalink
build(flake-parts/web): include wasm modules from nix
Browse files Browse the repository at this point in the history
Previously the `public/loader` directory contained a wasm ES module that
was used for initializing service workers. Instead of including it with
the code it is now built using nix and included in the `static-files`
package.

The mechanism for loading this is also used for the `ui` and `wasm`
crates. The `wasm-modules` attrset copies the files from the derivations
given to it into the `public/wasm/${name}` directory.

The loader files have been removed from the codebase and the html has
been updated to reflect the new directories of the modules.
  • Loading branch information
justinrubek committed Sep 24, 2023
1 parent b42e21a commit 8e76199
Show file tree
Hide file tree
Showing 8 changed files with 1,698 additions and 748 deletions.
17 changes: 15 additions & 2 deletions flake-parts/web.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
{inputs, ...}: {
perSystem = {
config,
lib,
pkgs,
system,
inputs',
self',
...
}: let
# wasm-bindgen modules to include in the files
wasm-modules = {
loader = inputs'.wasm-bindgen-service-worker.packages.loader;
ui = self'.packages.ui;
wasm = self'.packages.wasm;
};

# generate bash script that copies the contents of all the wasm-modules into their respective directories
wasm-modules-includes = lib.concatMapStringsSep "\n" (name: ''
mkdir -p $out/public/wasm/${name}
cp -r ${wasm-modules.${name}}/* $out/public/wasm/${name}
'') (builtins.attrNames wasm-modules);

static-files = pkgs.runCommand "static-files" {} ''
mkdir -p $out
mkdir -p $out/public/wasm
cp -r ${../public}/* $out/public
cp -r ${self'.packages.wasm}/* $out/public/wasm
cp -r ${self'.packages.ui}/* $out/public/wasm
${wasm-modules-includes}
'';
in rec {
packages = {
Expand Down
Loading

0 comments on commit 8e76199

Please sign in to comment.