diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a3e3a05 --- /dev/null +++ b/flake.lock @@ -0,0 +1,42 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1649676176, + "narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1651726670, + "narHash": "sha256-dSGdzB49SEvdOJvrQWfQYkAefewXraHIV08Vz6iDXWQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c777cdf5c564015d5f63b09cc93bef4178b19b01", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "rev": "c777cdf5c564015d5f63b09cc93bef4178b19b01", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ceed7a6 --- /dev/null +++ b/flake.nix @@ -0,0 +1,60 @@ +{ + description = "An implementation of the Double Ratchet cryptographic ratchet"; + + inputs.nixpkgs.url = "nixpkgs/c777cdf5c564015d5f63b09cc93bef4178b19b01"; + # c777cdf5c564015d5f63b09cc93bef4178b19b01 is current unstable. We can't use + # the current stable release because of + # https://github.com/emscripten-core/emscripten/issues/14995 + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = { self, nixpkgs, flake-utils }: + ( + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + }; + in + rec { + packages.javascript = pkgs.buildEmscriptenPackage { + name = "olm"; + + buildInputs = [ pkgs.gnumake pkgs.python3 pkgs.yarn ]; + + src = ./.; + + configurePhase = ""; + + buildPhase = '' + export EM_CACHE=$TMPDIR + make javascript/exported_functions.json + make js + ''; + + output = [ "out" ]; + + installPhase = '' + mkdir -p $out/javascript + cd javascript + echo sha256: > checksums.txt + sha256sum olm.js olm_legacy.js olm.wasm >> checksums.txt + echo sha512: >> checksums.txt + sha512sum olm.js olm_legacy.js olm.wasm >> checksums.txt + cp package.json olm.js olm.wasm olm_legacy.js index.d.ts README.md checksums.txt $out/javascript + cd .. + ''; + + checkPhase = '' + cd javascript + export HOME=$TMPDIR + yarn install + yarn test + cd .. + ''; + }; + + defaultPackage = packages.javascript; + } + ) + ); +}