2022-10-15 23:02:13 +03:00
|
|
|
{
|
2023-04-05 02:56:51 +03:00
|
|
|
inputs = {
|
2023-06-18 03:02:10 +03:00
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
|
2023-04-05 02:56:51 +03:00
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
2024-01-19 00:05:55 +03:00
|
|
|
nix-filter.url = "github:numtide/nix-filter";
|
2023-04-05 02:56:51 +03:00
|
|
|
|
|
|
|
fenix = {
|
|
|
|
url = "github:nix-community/fenix";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-04-05 03:30:30 +03:00
|
|
|
crane = {
|
|
|
|
url = "github:ipetkov/crane";
|
2023-04-05 02:56:51 +03:00
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
2023-01-28 00:10:21 +03:00
|
|
|
};
|
2024-01-25 22:34:46 +03:00
|
|
|
attic.url = "github:zhaofengli/attic?ref=main";
|
2023-04-05 02:56:51 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
outputs =
|
|
|
|
{ self
|
|
|
|
, nixpkgs
|
|
|
|
, flake-utils
|
2024-01-19 00:05:55 +03:00
|
|
|
, nix-filter
|
2023-04-05 02:56:51 +03:00
|
|
|
|
|
|
|
, fenix
|
2023-04-05 03:30:30 +03:00
|
|
|
, crane
|
2024-01-25 22:34:46 +03:00
|
|
|
, ...
|
2023-04-05 02:56:51 +03:00
|
|
|
}: flake-utils.lib.eachDefaultSystem (system:
|
|
|
|
let
|
|
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
|
|
|
|
|
|
# Nix-accessible `Cargo.toml`
|
|
|
|
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
|
|
|
|
|
|
|
# The Rust toolchain to use
|
|
|
|
toolchain = fenix.packages.${system}.toolchainOf {
|
|
|
|
# Use the Rust version defined in `Cargo.toml`
|
|
|
|
channel = cargoToml.package.rust-version;
|
|
|
|
|
|
|
|
# THE rust-version HASH
|
2023-06-18 03:04:11 +03:00
|
|
|
sha256 = "sha256-gdYqng0y9iHYzYPAdkC/ka3DRny3La/S5G8ASj0Ayyc=";
|
2023-04-05 02:56:51 +03:00
|
|
|
};
|
|
|
|
|
2023-12-24 08:12:42 +03:00
|
|
|
mkToolchain = fenix.packages.${system}.combine;
|
|
|
|
|
|
|
|
buildToolchain = mkToolchain (with toolchain; [
|
|
|
|
cargo
|
|
|
|
rustc
|
|
|
|
]);
|
|
|
|
|
|
|
|
devToolchain = mkToolchain (with toolchain; [
|
|
|
|
cargo
|
|
|
|
clippy
|
|
|
|
rust-src
|
|
|
|
rustc
|
|
|
|
|
|
|
|
# Always use nightly rustfmt because most of its options are unstable
|
|
|
|
fenix.packages.${system}.latest.rustfmt
|
|
|
|
]);
|
|
|
|
|
|
|
|
builder =
|
|
|
|
((crane.mkLib pkgs).overrideToolchain buildToolchain).buildPackage;
|
2023-07-16 23:38:33 +03:00
|
|
|
|
2024-01-23 21:45:02 +03:00
|
|
|
nativeBuildInputs = [
|
|
|
|
pkgs.rustPlatform.bindgenHook
|
|
|
|
];
|
2023-04-05 03:52:15 +03:00
|
|
|
|
2023-12-24 08:12:42 +03:00
|
|
|
env = {
|
|
|
|
ROCKSDB_INCLUDE_DIR = "${pkgs.rocksdb}/include";
|
|
|
|
ROCKSDB_LIB_DIR = "${pkgs.rocksdb}/lib";
|
|
|
|
};
|
2023-04-05 02:56:51 +03:00
|
|
|
in
|
|
|
|
{
|
|
|
|
packages.default = builder {
|
2024-01-19 00:05:55 +03:00
|
|
|
src = nix-filter {
|
|
|
|
root = ./.;
|
|
|
|
include = [
|
|
|
|
"src"
|
|
|
|
"Cargo.toml"
|
|
|
|
"Cargo.lock"
|
|
|
|
];
|
|
|
|
};
|
2023-04-05 02:56:51 +03:00
|
|
|
|
2023-12-24 08:12:42 +03:00
|
|
|
# This is redundant with CI
|
|
|
|
doCheck = false;
|
|
|
|
|
2023-04-05 05:15:09 +03:00
|
|
|
inherit
|
2023-12-24 08:12:42 +03:00
|
|
|
env
|
2024-01-23 09:24:04 +03:00
|
|
|
nativeBuildInputs;
|
2023-12-24 08:12:42 +03:00
|
|
|
|
|
|
|
meta.mainProgram = cargoToml.package.name;
|
2023-04-05 02:56:51 +03:00
|
|
|
};
|
|
|
|
|
2024-01-19 00:31:46 +03:00
|
|
|
packages.oci-image =
|
|
|
|
let
|
|
|
|
package = self.packages.${system}.default;
|
|
|
|
in
|
|
|
|
pkgs.dockerTools.buildImage {
|
|
|
|
name = package.pname;
|
|
|
|
tag = "latest";
|
|
|
|
config = {
|
|
|
|
# Use the `tini` init system so that signals (e.g. ctrl+c/SIGINT) are
|
|
|
|
# handled as expected
|
|
|
|
Entrypoint = [
|
|
|
|
"${pkgs.lib.getExe' pkgs.tini "tini"}"
|
|
|
|
"--"
|
|
|
|
];
|
|
|
|
Cmd = [
|
|
|
|
"${pkgs.lib.getExe package}"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-01-23 09:24:04 +03:00
|
|
|
devShells.default = pkgs.mkShell {
|
2023-12-24 08:12:42 +03:00
|
|
|
env = env // {
|
|
|
|
# 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.
|
|
|
|
RUST_SRC_PATH = "${devToolchain}/lib/rustlib/src/rust/library";
|
|
|
|
};
|
2023-07-16 23:38:33 +03:00
|
|
|
|
2023-04-05 02:56:51 +03:00
|
|
|
# Development tools
|
2023-12-24 08:12:42 +03:00
|
|
|
nativeBuildInputs = nativeBuildInputs ++ [
|
|
|
|
devToolchain
|
|
|
|
] ++ (with pkgs; [
|
2023-12-21 02:29:09 +03:00
|
|
|
engage
|
2023-04-05 02:56:51 +03:00
|
|
|
]);
|
|
|
|
};
|
|
|
|
});
|
2022-10-15 23:02:13 +03:00
|
|
|
}
|