2022-10-15 22:02:13 +02:00
|
|
|
{
|
2023-04-05 01:56:51 +02:00
|
|
|
inputs = {
|
2023-06-18 02:02:10 +02:00
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
|
2023-04-05 01:56:51 +02:00
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
2024-01-18 22:05:55 +01:00
|
|
|
nix-filter.url = "github:numtide/nix-filter";
|
2023-04-05 01:56:51 +02:00
|
|
|
|
|
|
|
fenix = {
|
|
|
|
url = "github:nix-community/fenix";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-04-05 02:30:30 +02:00
|
|
|
crane = {
|
|
|
|
url = "github:ipetkov/crane";
|
2023-04-05 01:56:51 +02:00
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
2023-01-27 22:10:21 +01:00
|
|
|
};
|
2024-01-25 20:34:46 +01:00
|
|
|
attic.url = "github:zhaofengli/attic?ref=main";
|
2023-04-05 01:56:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
outputs =
|
|
|
|
{ self
|
|
|
|
, nixpkgs
|
|
|
|
, flake-utils
|
2024-01-18 22:05:55 +01:00
|
|
|
, nix-filter
|
2023-04-05 01:56:51 +02:00
|
|
|
|
|
|
|
, fenix
|
2023-04-05 02:30:30 +02:00
|
|
|
, crane
|
2024-01-25 20:34:46 +01:00
|
|
|
, ...
|
2023-04-05 01:56:51 +02:00
|
|
|
}: flake-utils.lib.eachDefaultSystem (system:
|
|
|
|
let
|
2024-01-23 07:25:08 +01:00
|
|
|
pkgsHost = nixpkgs.legacyPackages.${system};
|
2023-04-05 01:56:51 +02:00
|
|
|
|
|
|
|
# Nix-accessible `Cargo.toml`
|
|
|
|
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
|
|
|
|
|
|
|
# The Rust toolchain to use
|
2024-01-23 07:48:58 +01:00
|
|
|
toolchain = fenix.packages.${system}.fromToolchainFile {
|
|
|
|
file = ./rust-toolchain.toml;
|
2023-04-05 01:56:51 +02:00
|
|
|
|
2024-01-23 07:48:58 +01:00
|
|
|
# See also `rust-toolchain.toml`
|
2023-06-18 02:04:11 +02:00
|
|
|
sha256 = "sha256-gdYqng0y9iHYzYPAdkC/ka3DRny3La/S5G8ASj0Ayyc=";
|
2023-04-05 01:56:51 +02:00
|
|
|
};
|
|
|
|
|
2024-01-23 07:26:16 +01:00
|
|
|
builder = pkgs:
|
2024-01-23 07:48:58 +01:00
|
|
|
((crane.mkLib pkgs).overrideToolchain toolchain).buildPackage;
|
2023-07-16 22:38:33 +02:00
|
|
|
|
2024-01-23 07:26:16 +01:00
|
|
|
nativeBuildInputs = pkgs: [
|
|
|
|
pkgs.rustPlatform.bindgenHook
|
2024-01-23 19:45:02 +01:00
|
|
|
];
|
2023-04-05 02:52:15 +02:00
|
|
|
|
2024-01-23 07:26:16 +01:00
|
|
|
env = pkgs: {
|
|
|
|
ROCKSDB_INCLUDE_DIR = "${pkgs.rocksdb}/include";
|
|
|
|
ROCKSDB_LIB_DIR = "${pkgs.rocksdb}/lib";
|
2023-12-24 06:12:42 +01:00
|
|
|
};
|
2024-01-23 07:56:00 +01:00
|
|
|
|
|
|
|
package = pkgs: builder pkgs {
|
2024-01-18 22:05:55 +01:00
|
|
|
src = nix-filter {
|
|
|
|
root = ./.;
|
|
|
|
include = [
|
|
|
|
"src"
|
|
|
|
"Cargo.toml"
|
|
|
|
"Cargo.lock"
|
|
|
|
];
|
|
|
|
};
|
2023-04-05 01:56:51 +02:00
|
|
|
|
2023-12-24 06:12:42 +01:00
|
|
|
# This is redundant with CI
|
|
|
|
doCheck = false;
|
|
|
|
|
2024-01-23 07:56:00 +01:00
|
|
|
env = env pkgs;
|
|
|
|
nativeBuildInputs = nativeBuildInputs pkgs;
|
2023-12-24 06:12:42 +01:00
|
|
|
|
|
|
|
meta.mainProgram = cargoToml.package.name;
|
2023-04-05 01:56:51 +02:00
|
|
|
};
|
2024-01-23 07:56:00 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
packages.default = package pkgsHost;
|
2023-04-05 01:56:51 +02:00
|
|
|
|
2024-01-18 22:31:46 +01:00
|
|
|
packages.oci-image =
|
|
|
|
let
|
|
|
|
package = self.packages.${system}.default;
|
|
|
|
in
|
2024-01-23 07:25:08 +01:00
|
|
|
pkgsHost.dockerTools.buildImage {
|
2024-01-18 22:31:46 +01:00
|
|
|
name = package.pname;
|
|
|
|
tag = "latest";
|
|
|
|
config = {
|
|
|
|
# Use the `tini` init system so that signals (e.g. ctrl+c/SIGINT) are
|
|
|
|
# handled as expected
|
|
|
|
Entrypoint = [
|
2024-01-23 07:25:08 +01:00
|
|
|
"${pkgsHost.lib.getExe' pkgsHost.tini "tini"}"
|
2024-01-18 22:31:46 +01:00
|
|
|
"--"
|
|
|
|
];
|
|
|
|
Cmd = [
|
2024-01-23 07:25:08 +01:00
|
|
|
"${pkgsHost.lib.getExe package}"
|
2024-01-18 22:31:46 +01:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-01-23 07:25:08 +01:00
|
|
|
devShells.default = pkgsHost.mkShell {
|
2024-01-23 07:26:16 +01:00
|
|
|
env = env pkgsHost // {
|
2023-12-24 06:12:42 +01:00
|
|
|
# Rust Analyzer needs to be able to find the path to default crate
|
|
|
|
# sources, and it can read this environment variable to do so. The
|
|
|
|
# `rust-src` component is required in order for this to work.
|
2024-01-23 07:48:58 +01:00
|
|
|
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
|
2023-12-24 06:12:42 +01:00
|
|
|
};
|
2023-07-16 22:38:33 +02:00
|
|
|
|
2023-04-05 01:56:51 +02:00
|
|
|
# Development tools
|
2024-01-23 07:26:16 +01:00
|
|
|
nativeBuildInputs = nativeBuildInputs pkgsHost ++ [
|
2024-01-23 07:48:58 +01:00
|
|
|
# Always use nightly rustfmt because most of its options are unstable
|
|
|
|
#
|
|
|
|
# This needs to come before `toolchain` in this list, otherwise
|
|
|
|
# `$PATH` will have stable rustfmt instead.
|
|
|
|
fenix.packages.${system}.latest.rustfmt
|
|
|
|
|
|
|
|
toolchain
|
2024-01-23 07:25:08 +01:00
|
|
|
] ++ (with pkgsHost; [
|
2023-12-21 00:29:09 +01:00
|
|
|
engage
|
2023-04-05 01:56:51 +02:00
|
|
|
]);
|
|
|
|
};
|
|
|
|
});
|
2022-10-15 22:02:13 +02:00
|
|
|
}
|