{"id":27958434,"url":"https://github.com/determinatesystems/nix-wasm-example","last_synced_at":"2025-05-07T18:23:55.654Z","repository":{"id":173310291,"uuid":"603277329","full_name":"DeterminateSystems/nix-wasm-example","owner":"DeterminateSystems","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-06T18:15:40.000Z","size":79,"stargazers_count":21,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-06T19:26:29.975Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DeterminateSystems.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-18T02:35:39.000Z","updated_at":"2024-09-26T18:30:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"ec1c8dce-0373-4a0b-ac20-a184aa6ac7c9","html_url":"https://github.com/DeterminateSystems/nix-wasm-example","commit_stats":null,"previous_names":["determinatesystems/nix-wasm-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeterminateSystems%2Fnix-wasm-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeterminateSystems%2Fnix-wasm-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeterminateSystems%2Fnix-wasm-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeterminateSystems%2Fnix-wasm-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DeterminateSystems","download_url":"https://codeload.github.com/DeterminateSystems/nix-wasm-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252932385,"owners_count":21827289,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-07T18:23:54.954Z","updated_at":"2025-05-07T18:23:55.623Z","avatar_url":"https://github.com/DeterminateSystems.png","language":"Nix","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nix + WebAssembly example project\n\n\u003e [!INFO]\n\u003e This repo was created as a complement to the [Nix as a WebAssembly build tool][blog-post] blog post on the [Determinate Systems blog][blog] and fulfilled its purpose.\n\u003e It won't be updated further but you're free to use it [as you see fit](./LICENSE)!\n\nThis repo houses an example project that uses [Nix] to build and hack on [WebAssembly][wasm] (Wasm) in [Rust].\n\n## Setup\n\nFirst, make sure that [Nix] is installed with [flakes] enabled. We recommend using our [Determinate Nix Installer][dni]:\n\n```shell\ncurl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix \\\n  | sh -s -- install\n```\n\nWith Nix installed, you can activate the [development environment][dev]:\n\n```shell\nnix develop\n```\n\n\u003e [!NOTE]\n\u003e This should happen automatically if you have [direnv] installed and run `direnv allow`.\n\n## Packages\n\nBelow are some packages you can build in this project.\n\n### Build Wasm binary\n\nTo build a Wasm binary from the [Rust sources](./src/main.rs):\n\n```shell\nnix build \".#hello-wasm\"\n```\n\nThis generates a [stripped] Wasm binary at `result/lib/hello-wasm.wasm` (where `result` is a symlink to a [Nix store][store] path).\n\n### Build a full Wasm package\n\nTo build a Wasm binary from the Rust sources plus some other goodies:\n\n```shell\nnix build \".#hello-wasm-pkg\"\n\n# Inspect the package\ntree result\n```\n\nInside the package you should see:\n\n* `lib/hello-wasm.wasm` (the same [stripped] binary from [above](#build-wasm-binary))\n* `share/hello-wasm-dump.txt` (an [object dump][objdump])\n* `share/hello-wasm.dist` (a [stats] file)\n* `share/hello-wasm.wat` (a human-readable [WAT] file)\n\n### Run the binary\n\nYou can also run the compiled binary using two different Wasm runtimes.\n\nTo run it using [WasmEdge]:\n\n```shell\nnix run \".#hello-wasmedge-exec\"\n```\n\nTo run it using [Wasmtime]:\n\n```shell\nnix run \".#hello-wasmtime-exec\"\n```\n\n## Advantages of Nix for Wasm development\n\n* Many languages can build Wasm but creating multi-language development environments (without Nix, of course) is hard.\n* Successful Wasm development environments often a wide range of tools, compilers, runtimes, etc.\n* Nix can not only provide arbitrarily complex development environments but it can do so across Unix-based platforms.\n\n[blog]: https://determinate.systems/posts\n[blog-post]: https://determinate.systems/posts/nix-wasm\n[dev]: https://zero-to-nix.com/concepts/dev-env\n[direnv]: https://direnv.net\n[dni]: https://github.com/DeterminateSystems/nix-installer\n[flakes]: https://zero-to-nix.com/concepts/flakes\n[nix]: https://zero-to-nix.com\n[objdump]: https://webassembly.github.io/wabt/doc/wasm-objdump.1.html\n[rust]: https://rust-lang.org\n[stats]: https://webassembly.github.io/wabt/doc/wasm-stats.1.html\n[store]: https://zero-to-nix.com/concepts/nix-store\n[stripped]: https://webassembly.github.io/wabt/doc/wasm-strip.1.html\n[wasm]: https://webassembly.org\n[wasmedge]: https://wasmedge.org\n[wasmtime]: https://docs.wasmtime.dev\n[wat]: https://developer.mozilla.org/docs/WebAssembly/Understanding_the_text_format\n\n[^1]: `result` isn't a local directory but rather a symlink to the build result directory in the\n  [Nix store][store]. It should have a path of the form `/nix/store/${HASH}-wasm-all`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeterminatesystems%2Fnix-wasm-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeterminatesystems%2Fnix-wasm-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeterminatesystems%2Fnix-wasm-example/lists"}