2022-10-15 22:02:13 +02:00
|
|
|
{
|
2023-04-05 01:56:51 +02:00
|
|
|
inputs = {
|
2024-04-22 02:15:02 +02:00
|
|
|
attic.url = "github:zhaofengli/attic?ref=main";
|
2024-05-02 05:36:07 +02:00
|
|
|
complement = { url = "github:matrix-org/complement?ref=main"; flake = false; };
|
2024-04-22 02:15:02 +02:00
|
|
|
crane = { url = "github:ipetkov/crane?ref=master"; inputs.nixpkgs.follows = "nixpkgs"; };
|
2024-05-02 05:36:07 +02:00
|
|
|
fenix = { url = "github:nix-community/fenix?ref=main"; inputs.nixpkgs.follows = "nixpkgs"; };
|
|
|
|
flake-compat = { url = "github:edolstra/flake-compat?ref=master"; flake = false; };
|
|
|
|
flake-utils.url = "github:numtide/flake-utils?ref=main";
|
|
|
|
nix-filter.url = "github:numtide/nix-filter?ref=main";
|
2024-04-22 02:15:02 +02:00
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
|
2024-04-24 21:09:52 +02:00
|
|
|
rocksdb = { url = "github:facebook/rocksdb?ref=v9.1.1"; flake = false; };
|
2023-04-05 01:56:51 +02:00
|
|
|
};
|
|
|
|
|
2024-04-22 00:33:54 +02:00
|
|
|
outputs = inputs:
|
|
|
|
inputs.flake-utils.lib.eachDefaultSystem (system:
|
2023-04-05 01:56:51 +02:00
|
|
|
let
|
2024-04-22 00:33:54 +02:00
|
|
|
pkgsHost = inputs.nixpkgs.legacyPackages.${system};
|
2023-04-05 04:11:34 +02:00
|
|
|
|
2023-04-05 01:56:51 +02:00
|
|
|
# The Rust toolchain to use
|
2024-04-22 00:33:54 +02:00
|
|
|
toolchain = inputs.fenix.packages.${system}.fromToolchainFile {
|
2024-01-26 05:39:59 +01:00
|
|
|
file = ./rust-toolchain.toml;
|
2023-04-05 01:56:51 +02:00
|
|
|
|
2024-01-26 05:39:59 +01:00
|
|
|
# See also `rust-toolchain.toml`
|
2024-04-28 17:45:42 +02:00
|
|
|
sha256 = "sha256-e4mlaJehWBymYxJGgnbuCObVlqMlQSilZ8FljG9zPHY=";
|
2023-04-05 01:56:51 +02:00
|
|
|
};
|
|
|
|
|
2024-04-22 00:28:35 +02:00
|
|
|
scope = pkgs: pkgs.lib.makeScope pkgs.newScope (self: {
|
|
|
|
book = self.callPackage ./nix/pkgs/book {};
|
|
|
|
complement = self.callPackage ./nix/pkgs/complement {};
|
|
|
|
craneLib = ((inputs.crane.mkLib pkgs).overrideToolchain toolchain);
|
|
|
|
inherit inputs;
|
|
|
|
main = self.callPackage ./nix/pkgs/main {};
|
|
|
|
oci-image = self.callPackage ./nix/pkgs/oci-image {};
|
|
|
|
rocksdb = pkgs.rocksdb.overrideAttrs (old: {
|
|
|
|
src = inputs.rocksdb;
|
|
|
|
version = pkgs.lib.removePrefix
|
|
|
|
"v"
|
|
|
|
(builtins.fromJSON (builtins.readFile ./flake.lock))
|
|
|
|
.nodes.rocksdb.original.ref;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
scopeHost = (scope pkgsHost);
|
2024-01-26 05:39:59 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
packages = {
|
2024-04-22 00:28:35 +02:00
|
|
|
default = scopeHost.main;
|
|
|
|
jemalloc = scopeHost.main.override { features = ["jemalloc"]; };
|
|
|
|
hmalloc = scopeHost.main.override { features = ["hardened_malloc"]; };
|
|
|
|
|
|
|
|
oci-image = scopeHost.oci-image;
|
|
|
|
oci-image-jemalloc = scopeHost.oci-image.override {
|
|
|
|
main = scopeHost.main.override {
|
|
|
|
features = ["jemalloc"];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
oci-image-hmalloc = scopeHost.oci-image.override {
|
|
|
|
main = scopeHost.main.override {
|
|
|
|
features = ["hardened_malloc"];
|
|
|
|
};
|
|
|
|
};
|
2024-03-17 23:06:10 +01:00
|
|
|
|
2024-04-22 00:28:35 +02:00
|
|
|
book = scopeHost.book;
|
2024-03-17 23:06:10 +01:00
|
|
|
|
2024-04-22 00:28:35 +02:00
|
|
|
complement = scopeHost.complement;
|
2024-01-30 00:48:30 +01:00
|
|
|
}
|
|
|
|
//
|
|
|
|
builtins.listToAttrs
|
|
|
|
(builtins.concatLists
|
|
|
|
(builtins.map
|
|
|
|
(crossSystem:
|
|
|
|
let
|
|
|
|
binaryName = "static-${crossSystem}";
|
|
|
|
pkgsCrossStatic =
|
2024-04-22 00:33:54 +02:00
|
|
|
(import inputs.nixpkgs {
|
2024-01-30 00:48:30 +01:00
|
|
|
inherit system;
|
|
|
|
crossSystem = {
|
|
|
|
config = crossSystem;
|
|
|
|
};
|
|
|
|
}).pkgsStatic;
|
2024-04-22 00:28:35 +02:00
|
|
|
scopeCrossStatic = scope pkgsCrossStatic;
|
2024-01-30 00:48:30 +01:00
|
|
|
in
|
|
|
|
[
|
|
|
|
# An output for a statically-linked binary
|
|
|
|
{
|
|
|
|
name = binaryName;
|
2024-04-22 00:28:35 +02:00
|
|
|
value = scopeCrossStatic.main;
|
2024-01-30 00:48:30 +01:00
|
|
|
}
|
|
|
|
|
2024-04-11 02:31:00 +02:00
|
|
|
# An output for a statically-linked binary with jemalloc
|
|
|
|
{
|
|
|
|
name = "${binaryName}-jemalloc";
|
2024-04-22 00:28:35 +02:00
|
|
|
value = scopeCrossStatic.main.override {
|
|
|
|
features = ["jemalloc"];
|
|
|
|
};
|
2024-04-11 02:31:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# An output for a statically-linked binary with hardened_malloc
|
|
|
|
{
|
|
|
|
name = "${binaryName}-hmalloc";
|
2024-04-22 00:28:35 +02:00
|
|
|
value = scopeCrossStatic.main.override {
|
|
|
|
features = ["hardened_malloc"];
|
|
|
|
};
|
2024-04-11 02:31:00 +02:00
|
|
|
}
|
|
|
|
|
2024-01-30 00:48:30 +01:00
|
|
|
# An output for an OCI image based on that binary
|
|
|
|
{
|
|
|
|
name = "oci-image-${crossSystem}";
|
2024-04-22 00:28:35 +02:00
|
|
|
value = scopeCrossStatic.oci-image;
|
2024-01-30 00:48:30 +01:00
|
|
|
}
|
2024-04-11 02:31:00 +02:00
|
|
|
|
|
|
|
# An output for an OCI image based on that binary with jemalloc
|
|
|
|
{
|
|
|
|
name = "oci-image-${crossSystem}-jemalloc";
|
2024-04-22 00:28:35 +02:00
|
|
|
value = scopeCrossStatic.oci-image.override {
|
|
|
|
main = scopeCrossStatic.main.override {
|
|
|
|
features = ["jemalloc"];
|
|
|
|
};
|
|
|
|
};
|
2024-04-11 02:31:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# An output for an OCI image based on that binary with hardened_malloc
|
|
|
|
{
|
|
|
|
name = "oci-image-${crossSystem}-hmalloc";
|
2024-04-22 00:28:35 +02:00
|
|
|
value = scopeCrossStatic.oci-image.override {
|
|
|
|
main = scopeCrossStatic.main.override {
|
|
|
|
features = ["hardened_malloc"];
|
|
|
|
};
|
|
|
|
};
|
2024-04-11 02:31:00 +02:00
|
|
|
}
|
2024-01-30 00:48:30 +01:00
|
|
|
]
|
|
|
|
)
|
|
|
|
[
|
|
|
|
"x86_64-unknown-linux-musl"
|
|
|
|
"aarch64-unknown-linux-musl"
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
2024-01-26 05:39:59 +01:00
|
|
|
|
|
|
|
devShells.default = pkgsHost.mkShell {
|
2024-04-22 00:28:35 +02:00
|
|
|
env = scopeHost.main.env // {
|
2023-12-21 01:11:49 +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-26 05:39:59 +01:00
|
|
|
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
|
2024-04-22 00:28:35 +02:00
|
|
|
|
|
|
|
# Convenient way to access a pinned version of Complement's source
|
|
|
|
# code.
|
|
|
|
COMPLEMENT_SRC = inputs.complement.outPath;
|
2023-12-21 01:11:49 +01:00
|
|
|
};
|
2023-07-16 22:38:33 +02:00
|
|
|
|
2023-04-05 01:56:51 +02:00
|
|
|
# Development tools
|
2024-04-22 00:28:35 +02:00
|
|
|
packages = [
|
2024-01-26 05:39:59 +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.
|
2024-04-22 00:33:54 +02:00
|
|
|
inputs.fenix.packages.${system}.latest.rustfmt
|
2024-01-26 05:39:59 +01:00
|
|
|
|
|
|
|
toolchain
|
2024-04-22 00:28:35 +02:00
|
|
|
]
|
|
|
|
++ (with pkgsHost; [
|
2023-12-21 01:33:31 +01:00
|
|
|
engage
|
2024-04-22 07:43:53 +02:00
|
|
|
cargo-audit
|
2024-01-29 00:53:27 +01:00
|
|
|
|
2024-03-06 03:42:17 +01:00
|
|
|
# Needed for producing Debian packages
|
|
|
|
cargo-deb
|
|
|
|
|
2024-01-29 00:53:27 +01:00
|
|
|
# Needed for Complement
|
|
|
|
go
|
|
|
|
olm
|
|
|
|
|
|
|
|
# Needed for our script for Complement
|
|
|
|
jq
|
2024-03-17 23:06:10 +01:00
|
|
|
|
|
|
|
# Needed for finding broken markdown links
|
|
|
|
lychee
|
2024-03-21 23:40:10 +01:00
|
|
|
|
|
|
|
# Useful for editing the book locally
|
|
|
|
mdbook
|
2024-04-22 00:28:35 +02:00
|
|
|
])
|
|
|
|
++
|
|
|
|
scopeHost.main.nativeBuildInputs;
|
2023-04-05 01:56:51 +02:00
|
|
|
};
|
|
|
|
});
|
2022-10-15 22:02:13 +02:00
|
|
|
}
|