chore: tidy nix expressions

This commit is contained in:
2026-08-19 20:59:30 +02:00
parent 7e5dae50e1
commit 9edf42cf82
6 changed files with 154 additions and 87 deletions
+23
View File
@@ -0,0 +1,23 @@
{
crate2nix,
rustc,
cargo,
pkgs,
...
}: let
buildRustCrateForPkgs = _:
pkgs.buildRustCrate.override {
inherit cargo rustc;
};
# Cargo.nix for IFD
generatedCargoNix = crate2nix.tools.${pkgs.hostPlatform.system}.generatedCargoNix {
name = "rustnix";
src = ../.;
};
cargoNix = import generatedCargoNix {
inherit pkgs buildRustCrateForPkgs;
};
in
cargoNix.rootCrate
+19
View File
@@ -0,0 +1,19 @@
{
fetchCrate,
buildWasmBindgenCli,
rustPlatform,
...
}:
buildWasmBindgenCli rec {
src = fetchCrate {
pname = "wasm-bindgen-cli";
version = "0.2.127";
hash = "sha256-di+qBAdd7pENLiIB9CoZoab+W5xeDoByMREcCGTSzWo=";
};
cargoDeps = rustPlatform.fetchCargoVendor {
inherit src;
inherit (src) pname version;
hash = "sha256-FTv2GZIAQs0ePdIZXIXil7JbZ6kIT05VG6vqC1qNFxQ=";
};
}
+16
View File
@@ -0,0 +1,16 @@
{
makeRustPlatform,
cargo,
rustc,
pkgs,
...
}: let
p = pkgs;
in rec {
rustPlatform = makeRustPlatform {
inherit cargo rustc;
};
pkgs = p.extend (_: _: {
inherit rustPlatform;
});
}
+39
View File
@@ -0,0 +1,39 @@
{
stdenvNoCC,
wasm-bindgen,
wordle-solver-wasm,
root-crate,
...
}: let
snake_name = "wordle_solver";
package-meta = {
name = "wordle-solver";
type = "module";
description = "module";
version = root-crate.build.crateVersion;
files = [
"${snake_name}_bg.wasm"
"${snake_name}.js"
"${snake_name}_bg.js"
"${snake_name}.d.ts"
];
main = "${snake_name}.js";
types = "${snake_name}.d.ts";
sideEffects = [
"./${snake_name}.js"
"./snippets/*"
];
};
package-json = builtins.toJSON package-meta;
in
stdenvNoCC.mkDerivation {
name = "wordle-solver-wasm-pkg";
nativeBuildInputs = [wasm-bindgen];
unpackPhase = "true";
buildPhase = ''
wasm-bindgen --target bundler --out-dir $out ${wordle-solver-wasm}/lib/wordle_solver.wasm
cat <<EOF > $out/package.json
${package-json}
EOF
'';
}
+39
View File
@@ -0,0 +1,39 @@
{
rustPlatform,
buildPackages,
lld,
name ? "wordle-solver",
...
}:
rustPlatform.buildRustPackage {
inherit name;
src = ../.; # Or your source location
cargoLock.lockFile = ../Cargo.lock;
# Disable tests since they can't run on WASM
doCheck = false;
# Required dependencies for WASM builds
depsBuildBuild = [
buildPackages.stdenv.cc
lld # Needed for wasm-ld
];
cargoBuildFlags = [
"--lib"
"--features"
"wasm-bindgen"
];
# Configure rustc for WASM
env = {
RUSTFLAGS = ''--cfg=web_sys_unstable_apis -C linker=wasm-ld'';
};
# Copy the WASM file to the output
installPhase = ''
mkdir -p $out/lib
cp target/wasm32-unknown-unknown/release/*.wasm $out/lib/
'';
}