diff --git a/.gitignore b/.gitignore index a5eac2b..64890cd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ # Tailwind output file /assets/tailwind.css + +# Nix result +/result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ab4c4c2 --- /dev/null +++ b/flake.lock @@ -0,0 +1,82 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1780930886, + "narHash": "sha256-rppURzHviaQN131F+nLiLdGfcb0uCd9gGP0E5+iw9MI=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "8c3cede7ddc26bd659d2d383b5610efbd2c7a16e", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1781061510, + "narHash": "sha256-tVuGHgt/TsWu1rUAqEL+eWRIJJHtiPE2+yQ63b+/WTU=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "d286e9691bb03045febbf8304a658eab1487d1b5", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..2c27d49 --- /dev/null +++ b/flake.nix @@ -0,0 +1,88 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + + flake-utils.url = "github:numtide/flake-utils"; + + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }@inputs: + flake-utils.lib.eachDefaultSystem (system: + let + wasm-bindgen-overlay = (final: prev: { + wasm-bindgen-cli_0_2_123 = prev.wasm-bindgen-cli_0_2_121.overrideAttrs (old: rec { + src = prev.fetchCrate { + pname = "wasm-bindgen-cli"; + version = "0.2.123"; + hash = "sha256-ymeAEYsr7OnupWYJWjSeVGvq3+s+zxSNkODbzY62rYs="; + }; + + cargoDeps = prev.rustPlatform.fetchCargoVendor { + inherit src; + inherit (src) pname version; + hash = "sha256-d7x6gtx5OqEE4MyT6yjYn/qtgjx7GroTpXJewnBV2dU="; + }; + }); + }); + + pkgs = import nixpkgs { + inherit system; + + overlays = [ + (import rust-overlay) + wasm-bindgen-overlay + ]; + }; + + rust = pkgs.rust-bin.stable.latest.default.override { + targets = [ "wasm32-unknown-unknown" ]; + }; + + build-pkgs = with pkgs; [ + dioxus-cli + wasm-bindgen-cli_0_2_123 + binaryen + lld + tailwindcss_4 + ]; + in + rec { + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ + rust + ] ++ build-pkgs; + }; + + packages.default = packages.web; + + packages.web = pkgs.rustPlatform.buildRustPackage { + name = "libretunes"; + src = ./.; + + cargoLock.lockFile = ./Cargo.lock; + + nativeBuildInputs = with pkgs; [ + makeWrapper + ] ++ build-pkgs; + + buildPhase = '' + dx build --release --frozen --web + ''; + + installPhase = '' + mkdir -p "$out/bin" + install -t "$out" target/dx/libretunes/release/web/server + + cp -r target/dx/libretunes/release/web/public "$out/public" + + makeWrapper "$out/server" "$out/bin/libretunes" \ + --set DIOXUS_PUBLIC_PATH "$out/public" + ''; + }; + } + ); +}