commit fed2789cbbbe5b53c9243489927133f5370987bf Author: Ethan Girouard Date: Tue Aug 4 19:57:46 2026 -0400 Add LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4141755 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright © 2026 Ethan Girouard + + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the “Software”), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..04cb9ff --- /dev/null +++ b/flake.nix @@ -0,0 +1,119 @@ +{ + description = "Flake for developing/building Rust web projects with Dioxus, TailwindCSS and Daisyui"; + + 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 + pkgs = import nixpkgs { + inherit system; + + overlays = [ + (import rust-overlay) + ]; + }; + + daisyui-version = "v5.7.14"; + + daisyui = pkgs.stdenvNoCC.mkDerivation { + name = "daisyui"; + + src = pkgs.fetchurl { + url = "https://github.com/saadeghi/daisyui/releases/download/${daisyui-version}/daisyui.js"; + sha256 = "sha256-R2i3PsMH3LlRpk+9mg37TF9CU5iTrqELx1S4qzi3zoM="; + }; + + unpackPhase = "true"; + + installPhase = '' + mkdir "$out" + cp "$src" "$out/daisyui.js" + ''; + }; + + daisyui-theme = pkgs.stdenvNoCC.mkDerivation { + name = "daisyui-theme"; + + src = pkgs.fetchurl { + url = "https://github.com/saadeghi/daisyui/releases/download/${daisyui-version}/daisyui-theme.js"; + sha256 = "sha256-85ayxT5UB/vsJCjLDD4Hvyv5kI4PX1COG9Tk6nF/A7Y="; + }; + + unpackPhase = "true"; + + installPhase = '' + mkdir "$out" + cp "$src" "$out/daisyui-theme.js" + ''; + }; + + rust = pkgs.rust-bin.stable.latest.default.override { + targets = [ "wasm32-unknown-unknown" ]; + }; + + build-pkgs = with pkgs; [ + rust + dioxus-cli + wasm-bindgen-cli_0_2_126 + binaryen + lld + tailwindcss_4 + ]; + + build-rs-web = src: pkgs.rustPlatform.buildRustPackage rec { + pname = (pkgs.lib.trivial.importTOML "${src}/Cargo.toml").package.name; + version = (pkgs.lib.trivial.importTOML "${src}/Cargo.toml").package.version; + inherit src; + + DAISYUI_PATH = "${daisyui}"; + DAISYUI_THEME_PATH = "${daisyui-theme}"; + GIT_REV = if builtins.hasAttr "rev" src then src.rev else src.dirtyRev; + + cargoLock.lockFile = "${src}/Cargo.lock"; + + nativeBuildInputs = with pkgs; [ + makeWrapper + ] ++ build-pkgs; + + buildPhase = '' + # dx build will run tailwindcss anyways, but doing it first here is faster and clearer if it fails + tailwindcss --input style/tailwind.css --output assets/tailwind.css + + dx build --release --frozen --web + ''; + + installPhase = '' + mkdir -p "$out/bin" + install -t "$out" target/dx/${pname}/release/web/server + + cp -r target/dx/${pname}/release/web/public "$out/public" + + makeWrapper "$out/server" "$out/bin/${pname}" \ + --set DIOXUS_PUBLIC_PATH "$out/public" + ''; + }; + in + { + devShells.default = pkgs.mkShell { + DAISYUI_PATH = "${daisyui}"; + DAISYUI_THEME_PATH = "${daisyui-theme}"; + + buildInputs = with pkgs; [ + diesel-cli + ] ++ build-pkgs; + }; + + builders.default = build-rs-web; + } + ); +} diff --git a/overlay.nix b/overlay.nix new file mode 100644 index 0000000..f4b4465 --- /dev/null +++ b/overlay.nix @@ -0,0 +1,53 @@ +final: prev: { + rustPlatform = prev.rustPlatform // { + buildDioxusWebApp = prev.lib.extendMkDerivation { + constructDrv = prev.rustPlatform.buildRustPackage; + extendDrvArgs = + finalAttrs: + args@{ + src, + nativeBuildInputs ? [ ], + ... + }: + let + pkg-info = (prev.lib.trivial.importTOML "${src}/Cargo.toml").package; + pname = pkg-info.name; + in + { + pname = pkg-info.name; + version = pkg-info.version; + + GIT_REV = if builtins.hasAttr "rev" src then src.rev else src.dirtyRev; + + cargoLock.lockFile = "${src}/Cargo.lock"; + + nativeBuildInputs = with prev; [ + makeWrapper + dioxus-cli + ] + ++ nativeBuildInputs; + + buildPhase = '' + runHook preBuild + dx build --release --frozen --web + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir -p "$out/bin" + install -t "$out" target/dx/${pname}/release/web/server + + cp -r target/dx/${pname}/release/web/public "$out/public" + + makeWrapper "$out/server" "$out/bin/${pname}" \ + --set DIOXUS_PUBLIC_PATH "$out/public" + + runHook postInstall + ''; + } + // args; + }; + }; +}