diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 116bdc3899..a28c70fc4c 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -2942,13 +2942,22 @@ dependencies = [ "subtle", ] +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys 0.3.7", +] + [[package]] name = "dirs" version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" dependencies = [ - "dirs-sys", + "dirs-sys 0.4.1", ] [[package]] @@ -2961,6 +2970,17 @@ dependencies = [ "dirs-sys-next", ] +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "dirs-sys" version = "0.4.1" @@ -4041,7 +4061,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b780635574b3d92f036890d8373433d6f9fc7abb320ee42a5c25897fc8ed732" dependencies = [ - "dirs", + "dirs 5.0.1", "indicatif", "log", "native-tls", @@ -7081,6 +7101,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", + "shellexpand", "syn 2.0.87", "walkdir", ] @@ -7815,6 +7836,15 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shellexpand" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" +dependencies = [ + "dirs 4.0.0", +] + [[package]] name = "shlex" version = "1.3.0" diff --git a/backend/Cargo.toml b/backend/Cargo.toml index c444778502..26251822fb 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -154,7 +154,7 @@ tracing-appender = "^0" prometheus = { version = "^0", default-features = false } cookie = { version = "0.17.0" } phf = { version = "0.11", features = ["macros"] } -rust-embed = "^6" +rust-embed = { version = "^6", features = ["interpolate-folder-path"] } mime_guess = "^2" hex = "^0" sql-builder = "^3" diff --git a/backend/windmill-api/src/static_assets.rs b/backend/windmill-api/src/static_assets.rs index 783732b1c0..0423727e68 100644 --- a/backend/windmill-api/src/static_assets.rs +++ b/backend/windmill-api/src/static_assets.rs @@ -23,7 +23,7 @@ pub async fn static_handler(OriginalUri(original_uri): OriginalUri) -> StaticFil } #[derive(RustEmbed)] -#[folder = "../../frontend/build/"] +#[folder = "${FRONTEND_BUILD_DIR:-../../frontend/build/}"] struct Asset; pub struct StaticFile(Uri); diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..5ad4516f5c --- /dev/null +++ b/flake.lock @@ -0,0 +1,95 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1730785428, + "narHash": "sha256-Zwl8YgTVJTEum+L+0zVAWvXAGbWAuXHax3KzuejaDyo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4aa36568d413aca0ea84a1684d2d46f55dbabad7", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", + "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_2" + }, + "locked": { + "lastModified": 1730946479, + "narHash": "sha256-AxGJ3BRc44o3RBcfXxZqjVYftVtJ2sl+/WEjiLUmXRY=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "7fba269fe89ffad47206e0afba233d337c04cf08", + "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 0000000000..d6fbd0fdf2 --- /dev/null +++ b/flake.nix @@ -0,0 +1,136 @@ +{ + inputs = { + nixpkgs.url = "nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + + outputs = { self, nixpkgs, flake-utils, rust-overlay }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + buildInputs = with pkgs; [ + openssl.dev libxml2.dev xmlsec.dev libxslt.dev + rust-bin.beta.latest.default nodejs go + xcaddy sqlx-cli pkg-config + ]; + environment = { + NODE_ENV = "development"; + NODE_OPTIONS = "--max-old-space-size=16384"; + DATABASE_URL = "postgres://postgres:changeme@127.0.0.1:5432/"; + PKG_CONFIG_PATH = pkgs.lib.makeSearchPath "lib/pkgconfig" (with pkgs; [ + openssl.dev + libxml2.dev + xmlsec.dev + libxslt.dev + ]); + }; + rustcTarget = pkgs.hostPlatform.rust.rustcTarget; + fetch_librusty_v8 = { version, shas }: pkgs.fetchurl { + name = "librusty_v8-${version}"; + url = "https://github.com/denoland/rusty_v8/releases/download/v${version}/librusty_v8_release_${rustcTarget}.a.gz"; + sha256 = shas.${system}; + }; + in { + devShell = pkgs.mkShell { + inherit (environment) NODE_ENV NODE_OPTIONS DATABASE_URL PKG_CONFIG_PATH; + buildInputs = buildInputs; + packages = [ + (pkgs.writeScriptBin "wm-caddy" '' + cd ./frontend + xcaddy build $* \ + --with github.com/mholt/caddy-l4@145ec36251a44286f05a10d231d8bfb3a8192e09 \ + --with github.com/RussellLuo/caddy-ext/layer4@ab1e18cfe426012af351a68463937ae2e934a2a1 + '') + (pkgs.writeScriptBin "wm-build" '' + cd ./frontend + echo $(pwd) + npm install + npm run ${if pkgs.stdenv.isDarwin then "generate-backend-client-mac" else "generate-backend-client"} + npm run build $* + '') + (pkgs.writeScriptBin "wm-migrate" '' + cd ./backend + sqlx database reset + sqlx database create + sqlx migrate run + '') + (pkgs.writeScriptBin "wm-setup" '' + wm-build + wm-caddy + wm-migrate + '') + (pkgs.writeScriptBin "wm" '' + cd ./frontend + npm run dev $* + '') + ]; + }; + packages.windmill-client = pkgs.stdenv.mkDerivation { + pname = "windmill-client"; + version = (pkgs.lib.strings.trim (builtins.readFile ./version.txt)); + + src = ./.; + buildInputs = with pkgs; [ nodejs go ]; + + buildPhase = '' + export HOME=$(pwd) + npm config set strict-ssl false + cd frontend + npm install --verbose + npm run generate-backend-client-mac + NODE_OPTIONS="--max-old-space-size=8192" npm run build + ''; + + installPhase = '' + mkdir -p $out/build + cp -r build $out/build + ''; + }; + packages.windmill = pkgs.rustPlatform.buildRustPackage { + inherit (environment) DATABASE_URL PKG_CONFIG_PATH; + + pname = "windmill"; + version = (pkgs.lib.strings.trim (builtins.readFile ./version.txt)); + + src = ./.; + nativeBuildInputs = buildInputs ++ [ self.packages.${system}.windmill-client ]; + + cargoRoot = "backend"; + cargoLock = { + lockFile = ./backend/Cargo.lock; + outputHashes = { + "php-parser-rs-0.1.3" = "sha256-ZeI3KgUPmtjlRfq6eAYveqt8Ay35gwj6B9iOQRjQa9A="; + "progenitor-0.3.0" = "sha256-F6XRZFVIN6/HfcM8yI/PyNke45FL7jbcznIiqj22eIQ="; + "rustpython-ast-0.3.1" = "sha256-q9N+z3F6YICQuUMp3a10OS792tCq0GiSSlkcaLxi3Gs="; + "tiberius-0.12.2" = "sha256-s/S0K3hE+JNCrNVxoSCSs4myLHvukBYTwk2A5vZ7Ae8="; + "tinyvector-0.1.0" = "sha256-NYGhofU4rh+2IAM+zwe04YQdXY8Aa4gTmn2V2HtzRfI="; + }; + }; + + buildFeatures = [ "enterprise" ]; + doCheck = false; + preBuild = '' + export HOME=$(pwd) + npm config set strict-ssl false + cd backend + sqlx database create + sqlx migrate run + ''; + + FRONTEND_BUILD_DIR = "${self.packages.${system}.windmill-client}/build"; + RUSTY_V8_ARCHIVE = (fetch_librusty_v8 { + version = "130.0.1"; + shas = { + x86_64-linux = pkgs.lib.fakeHash; + aarch64-linux = pkgs.lib.fakeHash; + x86_64-darwin = pkgs.lib.fakeHash; + aarch64-darwin = "sha256-d1QTLt8gOUFxACes4oyIYgDF/srLOEk+5p5Oj1ECajQ="; + }; + }); + }; + }); +}