surrealpatch/flake.nix

127 lines
3.8 KiB
Nix
Raw Normal View History

{
description =
"A scalable, distributed, collaborative, document-graph database, for the realtime web";
inputs = {
2022-12-08 16:33:12 +00:00
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11-small";
flake-utils.url = "github:numtide/flake-utils/v1.0.0";
crane = {
2023-04-07 19:56:02 +00:00
url = "github:ipetkov/crane/v0.12.0";
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = inputs:
with inputs;
# Make systems available as variables to prevent typos
with flake-utils.lib.system;
# let-in expressions, very similar to Rust's let bindings. These names
# are used to express the output but not themselves paths in the output.
let
2023-05-11 18:43:41 +00:00
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.<name>
in flake-utils.lib.eachSystem nativeSystems (system:
let
pkgs = import nixpkgs { inherit system; };
util = import ./pkg/nix/util.nix {
inherit system;
inherit (pkgs) lib;
systems = flake-utils.lib.system;
flake = self;
};
mkRustToolchain = target:
with fenix.packages.${system};
combine [
stable.rustc
stable.cargo
targets.${target}.stable.rust-std
];
buildPlatform = pkgs.stdenv.buildPlatform.config;
# Make platforms available as variables to prevent typos
in with util.platforms;
rec {
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;
2022-12-08 16:33:12 +00:00
# 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 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;
2022-12-08 16:33:12 +00:00
# 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;
};
rustToolchain = mkRustToolchain target;
buildSpec = spec.buildSpec;
in pkgs.mkShell (buildSpec // {
hardeningDisable = [ "fortify" ];
depsBuildBuild = buildSpec.depsBuildBuild or [ ]
2022-12-08 16:33:12 +00:00
++ [ rustToolchain ] ++ (with pkgs; [ nixfmt cargo-watch wasm-pack ]);
inherit (util) SURREAL_BUILD_METADATA;
})) util.platforms);
# nix run
apps.default = flake-utils.lib.mkApp { drv = packages.default; };
});
}