From c8507bb5009d4615641882e6d4360bfb96f9edce Mon Sep 17 00:00:00 2001 From: Borodinov Ilya Date: Sat, 21 Sep 2024 22:24:52 +0300 Subject: [PATCH] downpatch --- Cargo.toml | 2 +- flake.nix | 183 ++++++++++++++++++++++++++++++++--------------------- 2 files changed, 113 insertions(+), 72 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8247677c..82f98f71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -121,7 +121,7 @@ surrealdb = { version = "2", path = "sdk", features = [ surrealdb-core = { version = "2", path = "core" } tempfile = "3.8.1" thiserror = "1.0.63" -tokio = { version = "1.40.0", features = ["macros", "signal"] } +tokio = { version = "1", features = ["macros", "signal"] } tokio-stream = "0.1" tokio-tungstenite = "0.23.1" tokio-util = { version = "0.7.11", features = ["io"] } diff --git a/flake.nix b/flake.nix index 9e136cdd..c059f482 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,5 @@ { - description = - "A scalable, distributed, collaborative, document-graph database, for the realtime web"; + description = "A scalable, distributed, collaborative, document-graph database, for the realtime web"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11-small"; @@ -19,7 +18,8 @@ }; }; - outputs = inputs: + outputs = + inputs: with inputs; # Make systems available as variables to prevent typos @@ -29,12 +29,19 @@ # are used to express the output but not themselves paths in the output. let - nativeSystems = [ aarch64-darwin aarch64-linux x86_64-darwin x86_64-linux ]; + nativeSystems = [ + aarch64-darwin + aarch64-linux + x86_64-darwin + x86_64-linux + ]; - # Build the output set for each default system and map system sets into - # attributes, resulting in paths such as: - # nix build .#packages.x86_64-linux. - in flake-utils.lib.eachSystem nativeSystems (system: + in + # Build the output set for each default system and map system sets into + # attributes, resulting in paths such as: + # nix build .#packages.x86_64-linux. + flake-utils.lib.eachSystem nativeSystems ( + system: let @@ -47,81 +54,115 @@ flake = self; }; - mkRustToolchain = {target, extraComponents ? []}: + mkRustToolchain = + { + target, + extraComponents ? [ ], + }: with fenix.packages.${system}; - combine ([ - stable.rustc - stable.cargo - targets.${target}.stable.rust-std - ] ++ extraComponents); + combine ( + [ + stable.rustc + stable.cargo + targets.${target}.stable.rust-std + ] + ++ extraComponents + ); buildPlatform = pkgs.stdenv.buildPlatform.config; - # Make platforms available as variables to prevent typos - in with util.platforms; + in + # Make platforms available as variables to prevent typos + with util.platforms; rec { - packages = { - # nix build - default = - packages.${buildPlatform} or packages.x86_64-unknown-linux-gnu; + packages = + { + # nix build + default = packages.${buildPlatform} or packages.x86_64-unknown-linux-gnu; - # nix build .#docker-image - docker-image = import ./pkg/nix/drv/docker.nix { - inherit util; - inherit (pkgs) cacert dockerTools; - package = packages.x86_64-unknown-linux-gnu; - }; - - # nix build .#static-binary - static-binary = packages.x86_64-unknown-linux-musl; - - # nix build .#wasm - wasm = packages.wasm32-unknown-unknown; - - # nix build .#windows-binary - windows-binary = packages.x86_64-pc-windows-gnu; - } // (pkgs.lib.attrsets.mapAttrs (target: _: - let - spec = - import ./pkg/nix/spec/${target}.nix { inherit pkgs target util; }; - in import ./pkg/nix/drv/binary.nix { - inherit pkgs util spec crane; - rustToolchain = mkRustToolchain { inherit target; }; - }) util.platforms); - - devShells = { - # nix develop - default = - devShells.${buildPlatform} or devShells.x86_64-unknown-linux-gnu; - - # nix develop .#static-binary - static-binary = devShells.x86_64-unknown-linux-musl; - - # nix develop .#wasm - wasm = devShells.wasm32-unknown-unknown; - - # nix develop .#windows-binary - windows-binary = devShells.x86_64-pc-windows-gnu; - } // (pkgs.lib.attrsets.mapAttrs (target: _: - let - spec = (import ./pkg/nix/spec/${target}.nix) { - inherit pkgs target util; + # nix build .#docker-image + docker-image = import ./pkg/nix/drv/docker.nix { + inherit util; + inherit (pkgs) cacert dockerTools; + package = packages.x86_64-unknown-linux-gnu; }; - extraComponents = with fenix.packages.${system}; [ targets.${target}.stable.rust-src rust-analyzer targets.${target}.stable.rustfmt ]; - rustToolchain = mkRustToolchain { inherit target extraComponents; }; - buildSpec = spec.buildSpec; - in pkgs.mkShell (buildSpec // { - hardeningDisable = [ "fortify" ]; - depsBuildBuild = buildSpec.depsBuildBuild or [ ] - ++ [ rustToolchain ] ++ (with pkgs; [ nixfmt cargo-watch wasm-pack pre-commit cargo-make]); + # nix build .#static-binary + static-binary = packages.x86_64-unknown-linux-musl; - inherit (util) SURREAL_BUILD_METADATA; - })) util.platforms); + # nix build .#wasm + wasm = packages.wasm32-unknown-unknown; + + # nix build .#windows-binary + windows-binary = packages.x86_64-pc-windows-gnu; + } + // (pkgs.lib.attrsets.mapAttrs ( + target: _: + let + spec = import ./pkg/nix/spec/${target}.nix { inherit pkgs target util; }; + in + import ./pkg/nix/drv/binary.nix { + inherit + pkgs + util + spec + crane + ; + rustToolchain = mkRustToolchain { inherit target; }; + } + ) util.platforms); + + devShells = + { + # nix develop + default = devShells.${buildPlatform} or devShells.x86_64-unknown-linux-gnu; + + # nix develop .#static-binary + static-binary = devShells.x86_64-unknown-linux-musl; + + # nix develop .#wasm + wasm = devShells.wasm32-unknown-unknown; + + # nix develop .#windows-binary + windows-binary = devShells.x86_64-pc-windows-gnu; + } + // (pkgs.lib.attrsets.mapAttrs ( + target: _: + let + spec = (import ./pkg/nix/spec/${target}.nix) { inherit pkgs target util; }; + extraComponents = with fenix.packages.${system}; [ + targets.${target}.stable.rust-src + rust-analyzer + targets.${target}.stable.rustfmt + ]; + rustToolchain = mkRustToolchain { inherit target extraComponents; }; + buildSpec = spec.buildSpec; + in + pkgs.mkShell ( + buildSpec + // { + hardeningDisable = [ "fortify" ]; + + depsBuildBuild = + buildSpec.depsBuildBuild or [ ] + #++ [ rustToolchain ] + ++ (with pkgs; [ + nixfmt + cargo-watch + wasm-pack + pre-commit + cargo-make + ]); + + inherit (util) SURREAL_BUILD_METADATA; + } + ) + ) util.platforms); # nix run apps.default = flake-utils.lib.mkApp { drv = packages.default; }; - }); + } + ); }