Add flake
This commit is contained in:
120
flake.nix
120
flake.nix
@@ -1,119 +1,9 @@
|
|||||||
{
|
{
|
||||||
description = "Flake for developing/building Rust web projects with Dioxus, TailwindCSS and Daisyui";
|
outputs =
|
||||||
|
|
||||||
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}";
|
{
|
||||||
|
overlays.default = import ./overlay.nix;
|
||||||
buildInputs = with pkgs; [
|
|
||||||
diesel-cli
|
|
||||||
] ++ build-pkgs;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
builders.default = build-rs-web;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user