2022-10-15 20:02:13 +00:00
|
|
|
{
|
2023-04-04 23:56:51 +00:00
|
|
|
inputs = {
|
2024-04-22 00:15:02 +00:00
|
|
|
attic.url = "github:zhaofengli/attic?ref=main";
|
2024-06-16 01:24:25 +00:00
|
|
|
cachix.url = "github:cachix/cachix?ref=master";
|
2024-05-02 03:36:07 +00:00
|
|
|
complement = { url = "github:matrix-org/complement?ref=main"; flake = false; };
|
2024-04-22 00:15:02 +00:00
|
|
|
crane = { url = "github:ipetkov/crane?ref=master"; inputs.nixpkgs.follows = "nixpkgs"; };
|
2024-05-02 03:36:07 +00: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 00:15:02 +00:00
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
|
2024-05-03 21:04:23 +00:00
|
|
|
# https://github.com/girlbossceo/rocksdb/commit/db6df0b185774778457dabfcbd822cb81760cade
|
2024-07-02 19:40:45 +00:00
|
|
|
rocksdb = { url = "github:girlbossceo/rocksdb?ref=v9.3.1"; flake = false; };
|
2024-05-06 18:59:59 +00:00
|
|
|
liburing = { url = "github:axboe/liburing?ref=master"; flake = false; };
|
2023-04-04 23:56:51 +00:00
|
|
|
};
|
|
|
|
|
2024-04-21 22:33:54 +00:00
|
|
|
outputs = inputs:
|
|
|
|
inputs.flake-utils.lib.eachDefaultSystem (system:
|
2023-04-04 23:56:51 +00:00
|
|
|
let
|
2024-04-21 22:33:54 +00:00
|
|
|
pkgsHost = inputs.nixpkgs.legacyPackages.${system};
|
2024-05-23 22:50:41 +00:00
|
|
|
pkgsHostStatic = pkgsHost.pkgsStatic;
|
2023-04-05 02:11:34 +00:00
|
|
|
|
2023-04-04 23:56:51 +00:00
|
|
|
# The Rust toolchain to use
|
2024-04-21 22:33:54 +00:00
|
|
|
toolchain = inputs.fenix.packages.${system}.fromToolchainFile {
|
2024-01-26 04:39:59 +00:00
|
|
|
file = ./rust-toolchain.toml;
|
2023-04-04 23:56:51 +00:00
|
|
|
|
2024-01-26 04:39:59 +00:00
|
|
|
# See also `rust-toolchain.toml`
|
2024-05-03 14:59:36 +00:00
|
|
|
sha256 = "sha256-+syqAd2kX8KVa8/U2gz3blIQTTsYYt3U63xBWaGOSc8";
|
2023-04-04 23:56:51 +00:00
|
|
|
};
|
|
|
|
|
2024-05-23 22:46:48 +00:00
|
|
|
mkScope = pkgs: pkgs.lib.makeScope pkgs.newScope (self: {
|
|
|
|
inherit pkgs;
|
2024-04-21 22:28:35 +00:00
|
|
|
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;
|
2024-07-08 21:07:31 +00:00
|
|
|
# we have this already at https://github.com/girlbossceo/rocksdb/commit/a935c0273e1ba44eacf88ce3685a9b9831486155
|
|
|
|
# unsetting this so i don't have to revert it and make this nix exclusive
|
|
|
|
patches = [];
|
2024-07-08 23:51:05 +00:00
|
|
|
# no real reason to have snappy, no one uses this
|
|
|
|
cmakeFlags = pkgs.lib.subtractLists
|
|
|
|
[ "-DWITH_SNAPPY=1" ]
|
|
|
|
old.cmakeFlags;
|
2024-04-21 22:28:35 +00:00
|
|
|
});
|
2024-05-26 01:04:17 +00:00
|
|
|
# TODO: remove once https://github.com/NixOS/nixpkgs/pull/314945 is available
|
|
|
|
liburing = pkgs.liburing.overrideAttrs (old: {
|
|
|
|
# the configure script doesn't support these, and unconditionally
|
|
|
|
# builds both static and dynamic libraries.
|
|
|
|
configureFlags = pkgs.lib.subtractLists
|
|
|
|
[ "--enable-static" "--disable-shared" ]
|
|
|
|
old.configureFlags;
|
|
|
|
});
|
2024-04-21 22:28:35 +00:00
|
|
|
});
|
|
|
|
|
2024-05-23 22:46:48 +00:00
|
|
|
scopeHost = mkScope pkgsHost;
|
2024-05-23 22:50:41 +00:00
|
|
|
scopeHostStatic = mkScope pkgsHostStatic;
|
2024-05-23 22:46:48 +00:00
|
|
|
|
|
|
|
mkDevShell = scope: scope.pkgs.mkShell {
|
|
|
|
env = scope.main.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 = "${toolchain}/lib/rustlib/src/rust/library";
|
|
|
|
|
|
|
|
# Convenient way to access a pinned version of Complement's source
|
|
|
|
# code.
|
|
|
|
COMPLEMENT_SRC = inputs.complement.outPath;
|
2024-05-24 06:48:28 +00:00
|
|
|
|
|
|
|
# Needed for Complement
|
|
|
|
CGO_CFLAGS = "-I${scope.pkgs.olm}/include";
|
|
|
|
CGO_LDFLAGS = "-L${scope.pkgs.olm}/lib";
|
2024-05-23 22:46:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
# Development tools
|
|
|
|
packages = [
|
|
|
|
# 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.
|
|
|
|
inputs.fenix.packages.${system}.latest.rustfmt
|
|
|
|
|
|
|
|
toolchain
|
|
|
|
]
|
|
|
|
++ (with pkgsHost.pkgs; [
|
|
|
|
engage
|
|
|
|
cargo-audit
|
|
|
|
|
|
|
|
# Needed for producing Debian packages
|
|
|
|
cargo-deb
|
|
|
|
|
|
|
|
# Needed for Complement
|
|
|
|
go
|
|
|
|
|
|
|
|
# Needed for our script for Complement
|
|
|
|
jq
|
|
|
|
|
|
|
|
# Needed for finding broken markdown links
|
|
|
|
lychee
|
|
|
|
|
2024-07-03 07:32:18 +00:00
|
|
|
# Needed for linting markdown files
|
|
|
|
markdownlint-cli
|
|
|
|
|
2024-05-23 22:46:48 +00:00
|
|
|
# Useful for editing the book locally
|
|
|
|
mdbook
|
|
|
|
])
|
2024-05-25 00:04:34 +00:00
|
|
|
++ scope.main.buildInputs
|
2024-05-23 22:46:48 +00:00
|
|
|
++ scope.main.propagatedBuildInputs
|
|
|
|
++ scope.main.nativeBuildInputs;
|
2024-05-24 03:40:29 +00:00
|
|
|
|
|
|
|
meta.broken = scope.main.meta.broken;
|
2024-05-23 22:46:48 +00:00
|
|
|
};
|
2024-01-26 04:39:59 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
packages = {
|
2024-05-26 21:52:55 +00:00
|
|
|
default = scopeHost.main;
|
2024-07-07 17:38:38 +00:00
|
|
|
all-features = scopeHost.main.override {
|
|
|
|
all_features = true;
|
|
|
|
# this is non-functional on nix for some reason
|
|
|
|
disable_features = ["hardened_malloc"];
|
|
|
|
};
|
2024-04-21 22:28:35 +00:00
|
|
|
hmalloc = scopeHost.main.override { features = ["hardened_malloc"]; };
|
|
|
|
|
|
|
|
oci-image = scopeHost.oci-image;
|
2024-07-07 06:47:07 +00:00
|
|
|
oci-image-all-features = scopeHost.oci-image.override {
|
|
|
|
main = scopeHost.main.override {
|
|
|
|
all_features = true;
|
2024-07-07 17:38:38 +00:00
|
|
|
# this is non-functional on nix for some reason
|
|
|
|
disable_features = ["hardened_malloc"];
|
2024-07-07 06:47:07 +00:00
|
|
|
};
|
|
|
|
};
|
2024-04-21 22:28:35 +00:00
|
|
|
oci-image-hmalloc = scopeHost.oci-image.override {
|
|
|
|
main = scopeHost.main.override {
|
|
|
|
features = ["hardened_malloc"];
|
|
|
|
};
|
|
|
|
};
|
2024-03-17 22:06:10 +00:00
|
|
|
|
2024-04-21 22:28:35 +00:00
|
|
|
book = scopeHost.book;
|
2024-03-17 22:06:10 +00:00
|
|
|
|
2024-04-21 22:28:35 +00:00
|
|
|
complement = scopeHost.complement;
|
2024-05-24 03:53:13 +00:00
|
|
|
static-complement = scopeHostStatic.complement;
|
2024-01-29 23:48:30 +00:00
|
|
|
}
|
|
|
|
//
|
|
|
|
builtins.listToAttrs
|
|
|
|
(builtins.concatLists
|
|
|
|
(builtins.map
|
|
|
|
(crossSystem:
|
|
|
|
let
|
|
|
|
binaryName = "static-${crossSystem}";
|
|
|
|
pkgsCrossStatic =
|
2024-04-21 22:33:54 +00:00
|
|
|
(import inputs.nixpkgs {
|
2024-01-29 23:48:30 +00:00
|
|
|
inherit system;
|
|
|
|
crossSystem = {
|
|
|
|
config = crossSystem;
|
|
|
|
};
|
|
|
|
}).pkgsStatic;
|
2024-05-23 22:46:48 +00:00
|
|
|
scopeCrossStatic = mkScope pkgsCrossStatic;
|
2024-01-29 23:48:30 +00:00
|
|
|
in
|
|
|
|
[
|
|
|
|
# An output for a statically-linked binary
|
|
|
|
{
|
|
|
|
name = binaryName;
|
2024-04-21 22:28:35 +00:00
|
|
|
value = scopeCrossStatic.main;
|
2024-01-29 23:48:30 +00:00
|
|
|
}
|
|
|
|
|
2024-07-07 06:47:07 +00:00
|
|
|
# An output for a statically-linked binary with `--all-features`
|
|
|
|
{
|
|
|
|
name = "${binaryName}-all-features";
|
|
|
|
value = scopeCrossStatic.main.override {
|
|
|
|
all_features = true;
|
2024-07-07 17:38:38 +00:00
|
|
|
# this is non-functional on nix for some reason
|
|
|
|
disable_features = ["hardened_malloc"];
|
2024-07-07 06:47:07 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-04-11 00:31:00 +00:00
|
|
|
# An output for a statically-linked binary with hardened_malloc
|
|
|
|
{
|
|
|
|
name = "${binaryName}-hmalloc";
|
2024-04-21 22:28:35 +00:00
|
|
|
value = scopeCrossStatic.main.override {
|
|
|
|
features = ["hardened_malloc"];
|
|
|
|
};
|
2024-04-11 00:31:00 +00:00
|
|
|
}
|
|
|
|
|
2024-01-29 23:48:30 +00:00
|
|
|
# An output for an OCI image based on that binary
|
|
|
|
{
|
|
|
|
name = "oci-image-${crossSystem}";
|
2024-04-21 22:28:35 +00:00
|
|
|
value = scopeCrossStatic.oci-image;
|
2024-01-29 23:48:30 +00:00
|
|
|
}
|
2024-04-11 00:31:00 +00:00
|
|
|
|
2024-07-07 06:47:07 +00:00
|
|
|
# An output for an OCI image based on that binary with `--all-features`
|
|
|
|
{
|
|
|
|
name = "oci-image-${crossSystem}-all-features";
|
|
|
|
value = scopeCrossStatic.oci-image.override {
|
|
|
|
main = scopeCrossStatic.main.override {
|
|
|
|
all_features = true;
|
2024-07-07 17:38:38 +00:00
|
|
|
# this is non-functional on nix for some reason
|
|
|
|
disable_features = ["hardened_malloc"];
|
2024-07-07 06:47:07 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-04-11 00:31:00 +00:00
|
|
|
# An output for an OCI image based on that binary with hardened_malloc
|
|
|
|
{
|
|
|
|
name = "oci-image-${crossSystem}-hmalloc";
|
2024-04-21 22:28:35 +00:00
|
|
|
value = scopeCrossStatic.oci-image.override {
|
|
|
|
main = scopeCrossStatic.main.override {
|
|
|
|
features = ["hardened_malloc"];
|
|
|
|
};
|
|
|
|
};
|
2024-04-11 00:31:00 +00:00
|
|
|
}
|
2024-01-29 23:48:30 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
[
|
|
|
|
"x86_64-unknown-linux-musl"
|
|
|
|
"aarch64-unknown-linux-musl"
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
2024-01-26 04:39:59 +00:00
|
|
|
|
2024-05-23 22:50:41 +00:00
|
|
|
devShells.default = mkDevShell scopeHostStatic;
|
2024-05-23 23:18:50 +00:00
|
|
|
devShells.all-features = mkDevShell
|
|
|
|
(scopeHostStatic.overrideScope (final: prev: {
|
2024-07-07 17:38:38 +00:00
|
|
|
main = prev.main.override {
|
|
|
|
all_features = true;
|
|
|
|
# this is non-functional on nix for some reason
|
|
|
|
disable_features = ["hardened_malloc"];
|
|
|
|
};
|
2024-05-23 23:18:50 +00:00
|
|
|
}));
|
2024-05-23 23:31:06 +00:00
|
|
|
devShells.no-features = mkDevShell
|
|
|
|
(scopeHostStatic.overrideScope (final: prev: {
|
|
|
|
main = prev.main.override { default_features = false; };
|
|
|
|
}));
|
2024-05-24 03:41:23 +00:00
|
|
|
devShells.dynamic = mkDevShell scopeHost;
|
2023-04-04 23:56:51 +00:00
|
|
|
});
|
2022-10-15 20:02:13 +00:00
|
|
|
}
|