diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000000..4fac2ab4b4d --- /dev/null +++ b/flake.lock @@ -0,0 +1,127 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1656928814, + "narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1662136632, + "narHash": "sha256-RwW/aA3ueQPsilQLi7NOfUnn8MgM6WMV+oRpW+nkDMI=", + "owner": "nix-community", + "repo": "naersk", + "rev": "8d2f4d00cb24cda8e5bdd802b827a0eaeff34eec", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1662096612, + "narHash": "sha256-R+Q8l5JuyJryRPdiIaYpO5O3A55rT+/pItBrKcy7LM4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "21de2b973f9fee595a7a1ac4693efff791245c34", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1659446231, + "narHash": "sha256-hekabNdTdgR/iLsgce5TGWmfIDZ86qjPhxDg/8TlzhE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "eabc38219184cc3e04a974fe31857d8e0eac098d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-21.11-small", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1659102345, + "narHash": "sha256-Vbzlz254EMZvn28BhpN8JOi5EuKqnHZ3ujFYgFcSGvk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "11b60e4f80d87794a2a4a8a256391b37c59a1ea7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1662173844, + "narHash": "sha256-+ZgW98Y8fZkgFSylE+Mzalumw+kw3SVivZznbJqQaj8=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "8ac6d40380dc4ec86f1ff591d5c14c8ae1d77a18", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000000..b808a70db86 --- /dev/null +++ b/flake.nix @@ -0,0 +1,60 @@ +{ + description = "SurrealDB - a scalable, distributed, collaborative, document-graph database, for the realtime web"; + + inputs = { + # We have to use an older NixOS release here because `grpcio-sys` is not compatible with GCC 11 + # See https://github.com/tikv/client-rust/issues/365 + nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11-small"; + flake-utils.url = "github:numtide/flake-utils"; + naersk.url = "github:nix-community/naersk"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + + outputs = { self, flake-utils, naersk, nixpkgs, rust-overlay }: + flake-utils.lib.eachDefaultSystem (system: + let + + # Set the desired FoundationDB version here + # Specify only the major and minor parts using `major.minor` format + # You can find the versions available at + # https://search.nixos.org/packages?channel=22.05&from=0&size=50&sort=relevance&type=packages&query=foundationdb + fdbVersion = "6.1"; + + pkgs = (import nixpkgs) { + inherit system; + overlays = [ rust-overlay.overlays.default ]; + }; + + rustLatest = pkgs.rust-bin.stable.latest; + + naersk' = pkgs.callPackage naersk { + cargo = rustLatest.default; + rustc = rustLatest.default; + }; + + fdbPkgVersion = builtins.replaceStrings ["."] [""] fdbVersion; + fdbFeatureVersion = builtins.replaceStrings ["."] ["_"] fdbVersion; + + commonArgs = { + nativeBuildInputs = with pkgs; [ pkg-config ]; + buildInputs = with pkgs; [ cmake perl protobuf openssl clang fdbPackages."foundationdb${fdbPkgVersion}" ]; + LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib"; + }; + + in rec { + # For `nix build` & `nix run`: + packages.default = naersk'.buildPackage (commonArgs // { + src = ./.; + cargoBuildOptions = options: options ++ [ ''--features "storage-tikv storage-fdb-${fdbFeatureVersion}"'' ]; + }); + + # For `nix develop` + devShell = pkgs.mkShell (commonArgs // { + hardeningDisable = [ "fortify" ]; + buildInputs = with pkgs; [ + rustLatest.default rustLatest.rustfmt rustLatest.clippy rust-analyzer + ]; + }); + } + ); +}