From 09199b0ea7c5e3de515d7e5e3c9cc37b9cf2f13d Mon Sep 17 00:00:00 2001 From: Shuroii Date: Thu, 3 Jul 2025 12:47:22 +0200 Subject: [PATCH] style: Format nix nixfmt-rfc-style for flake nixpkgs-fmt for nix/ directory --- flake.nix | 1118 ++++++++++++----------- nix/pkgs/book/default.nix | 2 +- nix/pkgs/complement/default.nix | 45 +- nix/pkgs/main/cross-compilation-env.nix | 59 +- nix/pkgs/main/default.nix | 272 +++--- nix/pkgs/oci-image/default.nix | 9 +- 6 files changed, 780 insertions(+), 725 deletions(-) diff --git a/flake.nix b/flake.nix index 52fdc10b..f8eba0f2 100644 --- a/flake.nix +++ b/flake.nix @@ -2,577 +2,627 @@ inputs = { attic.url = "github:zhaofengli/attic?ref=main"; cachix.url = "github:cachix/cachix?ref=master"; - complement = { url = "github:girlbossceo/complement?ref=main"; flake = false; }; - crane = { url = "github:ipetkov/crane?ref=master"; }; - fenix = { url = "github:nix-community/fenix?ref=main"; inputs.nixpkgs.follows = "nixpkgs"; }; - flake-compat = { url = "github:edolstra/flake-compat?ref=master"; flake = false; }; + complement = { + url = "github:girlbossceo/complement?ref=main"; + flake = false; + }; + crane = { + url = "github:ipetkov/crane?ref=master"; + }; + 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"; nixpkgs.url = "github:NixOS/nixpkgs?ref=nixpkgs-unstable"; - rocksdb = { url = "github:girlbossceo/rocksdb?ref=v9.11.1"; flake = false; }; - liburing = { url = "github:axboe/liburing?ref=master"; flake = false; }; + rocksdb = { + url = "github:girlbossceo/rocksdb?ref=v9.11.1"; + flake = false; + }; + liburing = { + url = "github:axboe/liburing?ref=master"; + flake = false; + }; }; - outputs = inputs: - inputs.flake-utils.lib.eachDefaultSystem (system: - let - pkgsHost = import inputs.nixpkgs{ - inherit system; - }; - pkgsHostStatic = pkgsHost.pkgsStatic; - - # The Rust toolchain to use - toolchain = inputs.fenix.packages.${system}.fromToolchainFile { - file = ./rust-toolchain.toml; - - # See also `rust-toolchain.toml` - sha256 = "sha256-KUm16pHj+cRedf8vxs/Hd2YWxpOrWZ7UOrwhILdSJBU="; - }; - - mkScope = pkgs: pkgs.lib.makeScope pkgs.newScope (self: { - inherit pkgs; - 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 {}; - tini = pkgs.tini.overrideAttrs { - # newer clang/gcc is unhappy with tini-static: - patches = [ (pkgs.fetchpatch { - url = "https://patch-diff.githubusercontent.com/raw/krallin/tini/pull/224.patch"; - hash = "sha256-4bTfAhRyIT71VALhHY13hUgbjLEUyvgkIJMt3w9ag3k="; - }) - ]; - }; - liburing = pkgs.liburing.overrideAttrs { - # Tests weren't building - outputs = [ "out" "dev" "man" ]; - buildFlags = [ "library" ]; - src = inputs.liburing; - }; - rocksdb = (pkgs.rocksdb.override { - liburing = self.liburing; - }).overrideAttrs (old: { - src = inputs.rocksdb; - version = pkgs.lib.removePrefix - "v" - (builtins.fromJSON (builtins.readFile ./flake.lock)) - .nodes.rocksdb.original.ref; - # 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 = []; - cmakeFlags = pkgs.lib.subtractLists - [ - # no real reason to have snappy or zlib, no one uses this - "-DWITH_SNAPPY=1" - "-DZLIB=1" - "-DWITH_ZLIB=1" - # we dont need to use ldb or sst_dump (core_tools) - "-DWITH_CORE_TOOLS=1" - # we dont need to build rocksdb tests - "-DWITH_TESTS=1" - # we use rust-rocksdb via C interface and dont need C++ RTTI - "-DUSE_RTTI=1" - # this doesn't exist in RocksDB, and USE_SSE is deprecated for - # PORTABLE=$(march) - "-DFORCE_SSE42=1" - # PORTABLE will get set in main/default.nix - "-DPORTABLE=1" - ] - old.cmakeFlags - ++ [ - # no real reason to have snappy, no one uses this - "-DWITH_SNAPPY=0" - "-DZLIB=0" - "-DWITH_ZLIB=0" - # we dont need to use ldb or sst_dump (core_tools) - "-DWITH_CORE_TOOLS=0" - # we dont need trace tools - "-DWITH_TRACE_TOOLS=0" - # we dont need to build rocksdb tests - "-DWITH_TESTS=0" - # we use rust-rocksdb via C interface and dont need C++ RTTI - "-DUSE_RTTI=0" - ]; - - # outputs has "tools" which we dont need or use - outputs = [ "out" ]; - - # preInstall hooks has stuff for messing with ldb/sst_dump which we dont need or use - preInstall = ""; - }); - }); - - scopeHost = mkScope pkgsHost; - scopeHostStatic = mkScope pkgsHostStatic; - scopeCrossLinux = mkScope pkgsHost.pkgsLinux.pkgsStatic; - mkCrossScope = crossSystem: - let pkgsCrossStatic = (import inputs.nixpkgs { + outputs = + inputs: + inputs.flake-utils.lib.eachDefaultSystem ( + system: + let + pkgsHost = import inputs.nixpkgs { inherit system; - crossSystem = { - config = crossSystem; - }; - }).pkgsStatic; - in - mkScope pkgsCrossStatic; + }; + pkgsHostStatic = pkgsHost.pkgsStatic; - 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"; + # The Rust toolchain to use + toolchain = inputs.fenix.packages.${system}.fromToolchainFile { + file = ./rust-toolchain.toml; - # Convenient way to access a pinned version of Complement's source - # code. - COMPLEMENT_SRC = inputs.complement.outPath; - - # Needed for Complement: - CGO_CFLAGS = "-Wl,--no-gc-sections"; - CGO_LDFLAGS = "-Wl,--no-gc-sections"; + # See also `rust-toolchain.toml` + sha256 = "sha256-X/4ZBHO3iW0fOenQ3foEvscgAPJYl2abspaBThDOukI="; }; - # 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 + mkScope = + pkgs: + pkgs.lib.makeScope pkgs.newScope (self: { + inherit pkgs; + 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 { }; + tini = pkgs.tini.overrideAttrs { + # newer clang/gcc is unhappy with tini-static: + patches = [ + (pkgs.fetchpatch { + url = "https://patch-diff.githubusercontent.com/raw/krallin/tini/pull/224.patch"; + hash = "sha256-4bTfAhRyIT71VALhHY13hUgbjLEUyvgkIJMt3w9ag3k="; + }) + ]; + }; + liburing = pkgs.liburing.overrideAttrs { + # Tests weren't building + outputs = [ + "out" + "dev" + "man" + ]; + buildFlags = [ "library" ]; + src = inputs.liburing; + }; + rocksdb = + (pkgs.rocksdb.override { + liburing = self.liburing; + }).overrideAttrs + (old: { + src = inputs.rocksdb; + version = pkgs.lib.removePrefix "v" (builtins.fromJSON (builtins.readFile ./flake.lock)) + .nodes.rocksdb.original.ref; + # 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 = [ ]; + cmakeFlags = + pkgs.lib.subtractLists [ + # no real reason to have snappy or zlib, no one uses this + "-DWITH_SNAPPY=1" + "-DZLIB=1" + "-DWITH_ZLIB=1" + # we dont need to use ldb or sst_dump (core_tools) + "-DWITH_CORE_TOOLS=1" + # we dont need to build rocksdb tests + "-DWITH_TESTS=1" + # we use rust-rocksdb via C interface and dont need C++ RTTI + "-DUSE_RTTI=1" + # this doesn't exist in RocksDB, and USE_SSE is deprecated for + # PORTABLE=$(march) + "-DFORCE_SSE42=1" + # PORTABLE will get set in main/default.nix + "-DPORTABLE=1" + ] old.cmakeFlags + ++ [ + # no real reason to have snappy, no one uses this + "-DWITH_SNAPPY=0" + "-DZLIB=0" + "-DWITH_ZLIB=0" + # we dont need to use ldb or sst_dump (core_tools) + "-DWITH_CORE_TOOLS=0" + # we dont need trace tools + "-DWITH_TRACE_TOOLS=0" + # we dont need to build rocksdb tests + "-DWITH_TESTS=0" + # we use rust-rocksdb via C interface and dont need C++ RTTI + "-DUSE_RTTI=0" + ]; - toolchain - ] - ++ (with pkgsHost.pkgs; [ - # Required by hardened-malloc.rs dep - binutils + # outputs has "tools" which we dont need or use + outputs = [ "out" ]; - cargo-audit - cargo-auditable + # preInstall hooks has stuff for messing with ldb/sst_dump which we dont need or use + preInstall = ""; + }); + }); - # Needed for producing Debian packages - cargo-deb + scopeHost = mkScope pkgsHost; + scopeHostStatic = mkScope pkgsHostStatic; + scopeCrossLinux = mkScope pkgsHost.pkgsLinux.pkgsStatic; + mkCrossScope = + crossSystem: + let + pkgsCrossStatic = + (import inputs.nixpkgs { + inherit system; + crossSystem = { + config = crossSystem; + }; + }).pkgsStatic; + in + mkScope pkgsCrossStatic; - # Needed for CI to check validity of produced Debian packages (dpkg-deb) - dpkg + 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"; - engage + # Convenient way to access a pinned version of Complement's source + # code. + COMPLEMENT_SRC = inputs.complement.outPath; - # Needed for Complement - go + # Needed for Complement: + CGO_CFLAGS = "-Wl,--no-gc-sections"; + CGO_LDFLAGS = "-Wl,--no-gc-sections"; + }; - # Needed for our script for Complement - jq - gotestfmt - - # Needed for finding broken markdown links - lychee - - # Needed for linting markdown files - markdownlint-cli - - # Useful for editing the book locally - mdbook - - # used for rust caching in CI to speed it up - sccache - ] - # liburing is Linux-exclusive - ++ lib.optional stdenv.hostPlatform.isLinux liburing - ++ lib.optional stdenv.hostPlatform.isLinux numactl) - ++ scope.main.buildInputs - ++ scope.main.propagatedBuildInputs - ++ scope.main.nativeBuildInputs; - }; - in - { - packages = { - default = scopeHost.main.override { - disable_features = [ - # dont include experimental features - "experimental" - # jemalloc profiling/stats features are expensive and shouldn't - # be expected on non-debug builds. - "jemalloc_prof" - "jemalloc_stats" - # this is non-functional on nix for some reason - "hardened_malloc" - # conduwuit_mods is a development-only hot reload feature - "conduwuit_mods" - ]; - }; - default-debug = scopeHost.main.override { - profile = "dev"; - # debug build users expect full logs - disable_release_max_log_level = true; - disable_features = [ - # dont include experimental features - "experimental" - # this is non-functional on nix for some reason - "hardened_malloc" - # conduwuit_mods is a development-only hot reload feature - "conduwuit_mods" - ]; - }; - # just a test profile used for things like CI and complement - default-test = scopeHost.main.override { - profile = "test"; - disable_release_max_log_level = true; - disable_features = [ - # dont include experimental features - "experimental" - # this is non-functional on nix for some reason - "hardened_malloc" - # conduwuit_mods is a development-only hot reload feature - "conduwuit_mods" - ]; - }; - all-features = scopeHost.main.override { - all_features = true; - disable_features = [ - # dont include experimental features - "experimental" - # jemalloc profiling/stats features are expensive and shouldn't - # be expected on non-debug builds. - "jemalloc_prof" - "jemalloc_stats" - # this is non-functional on nix for some reason - "hardened_malloc" - # conduwuit_mods is a development-only hot reload feature - "conduwuit_mods" - ]; - }; - all-features-debug = scopeHost.main.override { - profile = "dev"; - all_features = true; - # debug build users expect full logs - disable_release_max_log_level = true; - disable_features = [ - # dont include experimental features - "experimental" - # this is non-functional on nix for some reason - "hardened_malloc" - # conduwuit_mods is a development-only hot reload feature - "conduwuit_mods" - ]; - }; - hmalloc = scopeHost.main.override { features = ["hardened_malloc"]; }; - - oci-image = scopeHost.oci-image; - oci-image-all-features = scopeHost.oci-image.override { - main = scopeHost.main.override { - all_features = true; - disable_features = [ - # dont include experimental features - "experimental" - # jemalloc profiling/stats features are expensive and shouldn't - # be expected on non-debug builds. - "jemalloc_prof" - "jemalloc_stats" - # this is non-functional on nix for some reason - "hardened_malloc" - # conduwuit_mods is a development-only hot reload feature - "conduwuit_mods" - ]; - }; - }; - oci-image-all-features-debug = scopeHost.oci-image.override { - main = scopeHost.main.override { - profile = "dev"; - all_features = true; - # debug build users expect full logs - disable_release_max_log_level = true; - disable_features = [ - # dont include experimental features - "experimental" - # this is non-functional on nix for some reason - "hardened_malloc" - # conduwuit_mods is a development-only hot reload feature - "conduwuit_mods" - ]; - }; - }; - oci-image-hmalloc = scopeHost.oci-image.override { - main = scopeHost.main.override { - features = ["hardened_malloc"]; - }; - }; - - book = scopeHost.book; - - complement = scopeHost.complement; - static-complement = scopeHostStatic.complement; - # macOS containers don't exist, so the complement images must be forced to linux - linux-complement = (mkCrossScope "${pkgsHost.hostPlatform.qemuArch}-linux-musl").complement; - } - // - builtins.listToAttrs - (builtins.concatLists - (builtins.map - (crossSystem: - let - binaryName = "static-${crossSystem}"; - scopeCrossStatic = mkCrossScope crossSystem; - in + # Development tools + packages = [ - # An output for a statically-linked binary - { - name = binaryName; - value = scopeCrossStatic.main; - } + # 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 - # An output for a statically-linked binary with x86_64 haswell - # target optimisations - { - name = "${binaryName}-x86_64-haswell-optimised"; - value = scopeCrossStatic.main.override { - x86_64_haswell_target_optimised = (if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false); - }; - } + toolchain + ] + ++ ( + with pkgsHost.pkgs; + [ + # Required by hardened-malloc.rs dep + binutils - # An output for a statically-linked unstripped debug ("dev") binary - { - name = "${binaryName}-debug"; - value = scopeCrossStatic.main.override { - profile = "dev"; - # debug build users expect full logs - disable_release_max_log_level = true; - }; - } + cargo-audit + cargo-auditable - # An output for a statically-linked unstripped debug binary with the - # "test" profile (for CI usage only) - { - name = "${binaryName}-test"; - value = scopeCrossStatic.main.override { - profile = "test"; - disable_release_max_log_level = true; - disable_features = [ - # dont include experimental features - "experimental" - # this is non-functional on nix for some reason - "hardened_malloc" - # conduwuit_mods is a development-only hot reload feature - "conduwuit_mods" - ]; - }; - } + # Needed for producing Debian packages + cargo-deb - # An output for a statically-linked binary with `--all-features` - { - name = "${binaryName}-all-features"; - value = scopeCrossStatic.main.override { - all_features = true; - disable_features = [ - # dont include experimental features - "experimental" - # jemalloc profiling/stats features are expensive and shouldn't - # be expected on non-debug builds. - "jemalloc_prof" - "jemalloc_stats" - # this is non-functional on nix for some reason - "hardened_malloc" - # conduwuit_mods is a development-only hot reload feature - "conduwuit_mods" - ]; - }; - } + # Needed for CI to check validity of produced Debian packages (dpkg-deb) + dpkg - # An output for a statically-linked binary with `--all-features` and with x86_64 haswell - # target optimisations - { - name = "${binaryName}-all-features-x86_64-haswell-optimised"; - value = scopeCrossStatic.main.override { - all_features = true; - disable_features = [ - # dont include experimental features - "experimental" - # jemalloc profiling/stats features are expensive and shouldn't - # be expected on non-debug builds. - "jemalloc_prof" - "jemalloc_stats" - # this is non-functional on nix for some reason - "hardened_malloc" - # conduwuit_mods is a development-only hot reload feature - "conduwuit_mods" - ]; - x86_64_haswell_target_optimised = (if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false); - }; - } + engage - # An output for a statically-linked unstripped debug ("dev") binary with `--all-features` - { - name = "${binaryName}-all-features-debug"; - value = scopeCrossStatic.main.override { - profile = "dev"; - all_features = true; - # debug build users expect full logs - disable_release_max_log_level = true; - disable_features = [ - # dont include experimental features - "experimental" - # this is non-functional on nix for some reason - "hardened_malloc" - # conduwuit_mods is a development-only hot reload feature - "conduwuit_mods" - ]; - }; - } + # Needed for Complement + go - # An output for a statically-linked binary with hardened_malloc - { - name = "${binaryName}-hmalloc"; - value = scopeCrossStatic.main.override { - features = ["hardened_malloc"]; - }; - } + # Needed for our script for Complement + jq + gotestfmt - # An output for an OCI image based on that binary - { - name = "oci-image-${crossSystem}"; - value = scopeCrossStatic.oci-image; - } + # Needed for finding broken markdown links + lychee - # An output for an OCI image based on that binary with x86_64 haswell - # target optimisations - { - name = "oci-image-${crossSystem}-x86_64-haswell-optimised"; - value = scopeCrossStatic.oci-image.override { - main = scopeCrossStatic.main.override { - x86_64_haswell_target_optimised = (if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false); - }; - }; - } + # Needed for linting markdown files + markdownlint-cli - # An output for an OCI image based on that unstripped debug ("dev") binary - { - name = "oci-image-${crossSystem}-debug"; - value = scopeCrossStatic.oci-image.override { - main = scopeCrossStatic.main.override { + # Useful for editing the book locally + mdbook + + # used for rust caching in CI to speed it up + sccache + ] + # liburing is Linux-exclusive + ++ lib.optional stdenv.hostPlatform.isLinux liburing + ++ lib.optional stdenv.hostPlatform.isLinux numactl + ) + ++ scope.main.buildInputs + ++ scope.main.propagatedBuildInputs + ++ scope.main.nativeBuildInputs; + }; + in + { + packages = + { + default = scopeHost.main.override { + disable_features = [ + # dont include experimental features + "experimental" + # jemalloc profiling/stats features are expensive and shouldn't + # be expected on non-debug builds. + "jemalloc_prof" + "jemalloc_stats" + # this is non-functional on nix for some reason + "hardened_malloc" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" + ]; + }; + default-debug = scopeHost.main.override { + profile = "dev"; + # debug build users expect full logs + disable_release_max_log_level = true; + disable_features = [ + # dont include experimental features + "experimental" + # this is non-functional on nix for some reason + "hardened_malloc" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" + ]; + }; + # just a test profile used for things like CI and complement + default-test = scopeHost.main.override { + profile = "test"; + disable_release_max_log_level = true; + disable_features = [ + # dont include experimental features + "experimental" + # this is non-functional on nix for some reason + "hardened_malloc" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" + ]; + }; + all-features = scopeHost.main.override { + all_features = true; + disable_features = [ + # dont include experimental features + "experimental" + # jemalloc profiling/stats features are expensive and shouldn't + # be expected on non-debug builds. + "jemalloc_prof" + "jemalloc_stats" + # this is non-functional on nix for some reason + "hardened_malloc" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" + ]; + }; + all-features-debug = scopeHost.main.override { + profile = "dev"; + all_features = true; + # debug build users expect full logs + disable_release_max_log_level = true; + disable_features = [ + # dont include experimental features + "experimental" + # this is non-functional on nix for some reason + "hardened_malloc" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" + ]; + }; + hmalloc = scopeHost.main.override { features = [ "hardened_malloc" ]; }; + + oci-image = scopeHost.oci-image; + oci-image-all-features = scopeHost.oci-image.override { + main = scopeHost.main.override { + all_features = true; + disable_features = [ + # dont include experimental features + "experimental" + # jemalloc profiling/stats features are expensive and shouldn't + # be expected on non-debug builds. + "jemalloc_prof" + "jemalloc_stats" + # this is non-functional on nix for some reason + "hardened_malloc" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" + ]; + }; + }; + oci-image-all-features-debug = scopeHost.oci-image.override { + main = scopeHost.main.override { + profile = "dev"; + all_features = true; + # debug build users expect full logs + disable_release_max_log_level = true; + disable_features = [ + # dont include experimental features + "experimental" + # this is non-functional on nix for some reason + "hardened_malloc" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" + ]; + }; + }; + oci-image-hmalloc = scopeHost.oci-image.override { + main = scopeHost.main.override { + features = [ "hardened_malloc" ]; + }; + }; + + book = scopeHost.book; + + complement = scopeHost.complement; + static-complement = scopeHostStatic.complement; + # macOS containers don't exist, so the complement images must be forced to linux + linux-complement = (mkCrossScope "${pkgsHost.hostPlatform.qemuArch}-linux-musl").complement; + } + // builtins.listToAttrs ( + builtins.concatLists ( + builtins.map + ( + crossSystem: + let + binaryName = "static-${crossSystem}"; + scopeCrossStatic = mkCrossScope crossSystem; + in + [ + # An output for a statically-linked binary + { + name = binaryName; + value = scopeCrossStatic.main; + } + + # An output for a statically-linked binary with x86_64 haswell + # target optimisations + { + name = "${binaryName}-x86_64-haswell-optimised"; + value = scopeCrossStatic.main.override { + x86_64_haswell_target_optimised = ( + if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false + ); + }; + } + + # An output for a statically-linked unstripped debug ("dev") binary + { + name = "${binaryName}-debug"; + value = scopeCrossStatic.main.override { profile = "dev"; # debug build users expect full logs disable_release_max_log_level = true; - }; - }; - } + }; + } - # 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; - disable_features = [ - # dont include experimental features - "experimental" - # jemalloc profiling/stats features are expensive and shouldn't - # be expected on non-debug builds. - "jemalloc_prof" - "jemalloc_stats" - # this is non-functional on nix for some reason - "hardened_malloc" - # conduwuit_mods is a development-only hot reload feature - "conduwuit_mods" - ]; - }; - }; - } + # An output for a statically-linked unstripped debug binary with the + # "test" profile (for CI usage only) + { + name = "${binaryName}-test"; + value = scopeCrossStatic.main.override { + profile = "test"; + disable_release_max_log_level = true; + disable_features = [ + # dont include experimental features + "experimental" + # this is non-functional on nix for some reason + "hardened_malloc" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" + ]; + }; + } - # An output for an OCI image based on that binary with `--all-features` and with x86_64 haswell - # target optimisations - { - name = "oci-image-${crossSystem}-all-features-x86_64-haswell-optimised"; - value = scopeCrossStatic.oci-image.override { - main = scopeCrossStatic.main.override { - all_features = true; - disable_features = [ - # dont include experimental features - "experimental" - # jemalloc profiling/stats features are expensive and shouldn't - # be expected on non-debug builds. - "jemalloc_prof" - "jemalloc_stats" - # this is non-functional on nix for some reason - "hardened_malloc" - # conduwuit_mods is a development-only hot reload feature - "conduwuit_mods" - ]; - x86_64_haswell_target_optimised = (if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false); - }; - }; - } + # An output for a statically-linked binary with `--all-features` + { + name = "${binaryName}-all-features"; + value = scopeCrossStatic.main.override { + all_features = true; + disable_features = [ + # dont include experimental features + "experimental" + # jemalloc profiling/stats features are expensive and shouldn't + # be expected on non-debug builds. + "jemalloc_prof" + "jemalloc_stats" + # this is non-functional on nix for some reason + "hardened_malloc" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" + ]; + }; + } - # An output for an OCI image based on that unstripped debug ("dev") binary with `--all-features` - { - name = "oci-image-${crossSystem}-all-features-debug"; - value = scopeCrossStatic.oci-image.override { - main = scopeCrossStatic.main.override { - profile = "dev"; - all_features = true; - # debug build users expect full logs - disable_release_max_log_level = true; - disable_features = [ - # dont include experimental features - "experimental" - # this is non-functional on nix for some reason - "hardened_malloc" - # conduwuit_mods is a development-only hot reload feature - "conduwuit_mods" - ]; - }; - }; - } + # An output for a statically-linked binary with `--all-features` and with x86_64 haswell + # target optimisations + { + name = "${binaryName}-all-features-x86_64-haswell-optimised"; + value = scopeCrossStatic.main.override { + all_features = true; + disable_features = [ + # dont include experimental features + "experimental" + # jemalloc profiling/stats features are expensive and shouldn't + # be expected on non-debug builds. + "jemalloc_prof" + "jemalloc_stats" + # this is non-functional on nix for some reason + "hardened_malloc" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" + ]; + x86_64_haswell_target_optimised = ( + if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false + ); + }; + } - # An output for an OCI image based on that binary with hardened_malloc - { - name = "oci-image-${crossSystem}-hmalloc"; - value = scopeCrossStatic.oci-image.override { - main = scopeCrossStatic.main.override { - features = ["hardened_malloc"]; - }; - }; - } + # An output for a statically-linked unstripped debug ("dev") binary with `--all-features` + { + name = "${binaryName}-all-features-debug"; + value = scopeCrossStatic.main.override { + profile = "dev"; + all_features = true; + # debug build users expect full logs + disable_release_max_log_level = true; + disable_features = [ + # dont include experimental features + "experimental" + # this is non-functional on nix for some reason + "hardened_malloc" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" + ]; + }; + } - # An output for a complement OCI image for the specified platform - { - name = "complement-${crossSystem}"; - value = scopeCrossStatic.complement; - } - ] + # An output for a statically-linked binary with hardened_malloc + { + name = "${binaryName}-hmalloc"; + value = scopeCrossStatic.main.override { + features = [ "hardened_malloc" ]; + }; + } + + # An output for an OCI image based on that binary + { + name = "oci-image-${crossSystem}"; + value = scopeCrossStatic.oci-image; + } + + # An output for an OCI image based on that binary with x86_64 haswell + # target optimisations + { + name = "oci-image-${crossSystem}-x86_64-haswell-optimised"; + value = scopeCrossStatic.oci-image.override { + main = scopeCrossStatic.main.override { + x86_64_haswell_target_optimised = ( + if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false + ); + }; + }; + } + + # An output for an OCI image based on that unstripped debug ("dev") binary + { + name = "oci-image-${crossSystem}-debug"; + value = scopeCrossStatic.oci-image.override { + main = scopeCrossStatic.main.override { + profile = "dev"; + # debug build users expect full logs + disable_release_max_log_level = true; + }; + }; + } + + # 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; + disable_features = [ + # dont include experimental features + "experimental" + # jemalloc profiling/stats features are expensive and shouldn't + # be expected on non-debug builds. + "jemalloc_prof" + "jemalloc_stats" + # this is non-functional on nix for some reason + "hardened_malloc" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" + ]; + }; + }; + } + + # An output for an OCI image based on that binary with `--all-features` and with x86_64 haswell + # target optimisations + { + name = "oci-image-${crossSystem}-all-features-x86_64-haswell-optimised"; + value = scopeCrossStatic.oci-image.override { + main = scopeCrossStatic.main.override { + all_features = true; + disable_features = [ + # dont include experimental features + "experimental" + # jemalloc profiling/stats features are expensive and shouldn't + # be expected on non-debug builds. + "jemalloc_prof" + "jemalloc_stats" + # this is non-functional on nix for some reason + "hardened_malloc" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" + ]; + x86_64_haswell_target_optimised = ( + if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false + ); + }; + }; + } + + # An output for an OCI image based on that unstripped debug ("dev") binary with `--all-features` + { + name = "oci-image-${crossSystem}-all-features-debug"; + value = scopeCrossStatic.oci-image.override { + main = scopeCrossStatic.main.override { + profile = "dev"; + all_features = true; + # debug build users expect full logs + disable_release_max_log_level = true; + disable_features = [ + # dont include experimental features + "experimental" + # this is non-functional on nix for some reason + "hardened_malloc" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" + ]; + }; + }; + } + + # An output for an OCI image based on that binary with hardened_malloc + { + name = "oci-image-${crossSystem}-hmalloc"; + value = scopeCrossStatic.oci-image.override { + main = scopeCrossStatic.main.override { + features = [ "hardened_malloc" ]; + }; + }; + } + + # An output for a complement OCI image for the specified platform + { + name = "complement-${crossSystem}"; + value = scopeCrossStatic.complement; + } + ] + ) + [ + #"x86_64-apple-darwin" + #"aarch64-apple-darwin" + "x86_64-linux-gnu" + "x86_64-linux-musl" + "aarch64-linux-musl" + ] ) - [ - #"x86_64-apple-darwin" - #"aarch64-apple-darwin" - "x86_64-linux-gnu" - "x86_64-linux-musl" - "aarch64-linux-musl" - ] + ); + + devShells.default = mkDevShell scopeHostStatic; + devShells.all-features = mkDevShell ( + scopeHostStatic.overrideScope ( + final: prev: { + main = prev.main.override { + all_features = true; + disable_features = [ + # dont include experimental features + "experimental" + # jemalloc profiling/stats features are expensive and shouldn't + # be expected on non-debug builds. + "jemalloc_prof" + "jemalloc_stats" + # this is non-functional on nix for some reason + "hardened_malloc" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" + ]; + }; + } ) ); - - devShells.default = mkDevShell scopeHostStatic; - devShells.all-features = mkDevShell - (scopeHostStatic.overrideScope (final: prev: { - main = prev.main.override { - all_features = true; - disable_features = [ - # dont include experimental features - "experimental" - # jemalloc profiling/stats features are expensive and shouldn't - # be expected on non-debug builds. - "jemalloc_prof" - "jemalloc_stats" - # this is non-functional on nix for some reason - "hardened_malloc" - # conduwuit_mods is a development-only hot reload feature - "conduwuit_mods" - ]; - }; - })); - devShells.no-features = mkDevShell - (scopeHostStatic.overrideScope (final: prev: { - main = prev.main.override { default_features = false; }; - })); - devShells.dynamic = mkDevShell scopeHost; - }); + devShells.no-features = mkDevShell ( + scopeHostStatic.overrideScope ( + final: prev: { + main = prev.main.override { default_features = false; }; + } + ) + ); + devShells.dynamic = mkDevShell scopeHost; + } + ); } diff --git a/nix/pkgs/book/default.nix b/nix/pkgs/book/default.nix index 3995ab79..882a37b6 100644 --- a/nix/pkgs/book/default.nix +++ b/nix/pkgs/book/default.nix @@ -1,6 +1,6 @@ { inputs -# Dependencies + # Dependencies , main , mdbook , stdenv diff --git a/nix/pkgs/complement/default.nix b/nix/pkgs/complement/default.nix index 1295cb03..f86a01d4 100644 --- a/nix/pkgs/complement/default.nix +++ b/nix/pkgs/complement/default.nix @@ -16,24 +16,24 @@ let all_features = true; disable_release_max_log_level = true; disable_features = [ - # console/CLI stuff isn't used or relevant for complement - "console" - "tokio_console" - # sentry telemetry isn't useful for complement, disabled by default anyways - "sentry_telemetry" - "perf_measurements" - # this is non-functional on nix for some reason - "hardened_malloc" - # dont include experimental features - "experimental" - # compression isn't needed for complement - "brotli_compression" - "gzip_compression" - "zstd_compression" - # complement doesn't need hot reloading - "conduwuit_mods" - # complement doesn't have URL preview media tests - "url_preview" + # console/CLI stuff isn't used or relevant for complement + "console" + "tokio_console" + # sentry telemetry isn't useful for complement, disabled by default anyways + "sentry_telemetry" + "perf_measurements" + # this is non-functional on nix for some reason + "hardened_malloc" + # dont include experimental features + "experimental" + # compression isn't needed for complement + "brotli_compression" + "gzip_compression" + "zstd_compression" + # complement doesn't need hot reloading + "conduwuit_mods" + # complement doesn't have URL preview media tests + "url_preview" ]; }; @@ -68,11 +68,12 @@ dockerTools.buildImage { "${lib.getExe start}" ]; - Entrypoint = if !stdenv.hostPlatform.isDarwin + Entrypoint = + if !stdenv.hostPlatform.isDarwin # Use the `tini` init system so that signals (e.g. ctrl+c/SIGINT) # are handled as expected then [ "${lib.getExe' tini "tini"}" "--" ] - else []; + else [ ]; Env = [ "CONTINUWUITY_TLS__KEY=${./private_key.key}" @@ -82,8 +83,8 @@ dockerTools.buildImage { ]; ExposedPorts = { - "8008/tcp" = {}; - "8448/tcp" = {}; + "8008/tcp" = { }; + "8448/tcp" = { }; }; }; } diff --git a/nix/pkgs/main/cross-compilation-env.nix b/nix/pkgs/main/cross-compilation-env.nix index 0f326c92..2ee580a4 100644 --- a/nix/pkgs/main/cross-compilation-env.nix +++ b/nix/pkgs/main/cross-compilation-env.nix @@ -4,51 +4,52 @@ , stdenv }: -lib.optionalAttrs stdenv.hostPlatform.isStatic { - ROCKSDB_STATIC = ""; -} +lib.optionalAttrs stdenv.hostPlatform.isStatic + { + ROCKSDB_STATIC = ""; + } // { CARGO_BUILD_RUSTFLAGS = lib.concatStringsSep " " - ([] - # This disables PIE for static builds, which isn't great in terms - # of security. Unfortunately, my hand is forced because nixpkgs' - # `libstdc++.a` is built without `-fPIE`, which precludes us from - # leaving PIE enabled. - ++ lib.optionals - stdenv.hostPlatform.isStatic - [ "-C" "relocation-model=static" ] - ++ lib.optionals - (stdenv.buildPlatform.config != stdenv.hostPlatform.config) - [ - "-l" - "c" + ([ ] + # This disables PIE for static builds, which isn't great in terms + # of security. Unfortunately, my hand is forced because nixpkgs' + # `libstdc++.a` is built without `-fPIE`, which precludes us from + # leaving PIE enabled. + ++ lib.optionals + stdenv.hostPlatform.isStatic + [ "-C" "relocation-model=static" ] + ++ lib.optionals + (stdenv.buildPlatform.config != stdenv.hostPlatform.config) + [ + "-l" + "c" - "-l" - "stdc++" + "-l" + "stdc++" - "-L" - "${stdenv.cc.cc.lib}/${stdenv.hostPlatform.config}/lib" - ] + "-L" + "${stdenv.cc.cc.lib}/${stdenv.hostPlatform.config}/lib" + ] ); } -# What follows is stolen from [here][0]. Its purpose is to properly -# configure compilers and linkers for various stages of the build, and -# even covers the case of build scripts that need native code compiled and -# run on the build platform (I think). -# -# [0]: https://github.com/NixOS/nixpkgs/blob/nixpkgs-unstable/pkgs/build-support/rust/lib/default.nix#L48-L68 -// + # What follows is stolen from [here][0]. Its purpose is to properly + # configure compilers and linkers for various stages of the build, and + # even covers the case of build scripts that need native code compiled and + # run on the build platform (I think). + # + # [0]: https://github.com/NixOS/nixpkgs/blob/nixpkgs-unstable/pkgs/build-support/rust/lib/default.nix#L48-L68 + // ( let inherit (rust.lib) envVars; in lib.optionalAttrs (stdenv.targetPlatform.rust.rustcTarget - != stdenv.hostPlatform.rust.rustcTarget) + != stdenv.hostPlatform.rust.rustcTarget) ( let inherit (stdenv.targetPlatform.rust) cargoEnvVarTarget; diff --git a/nix/pkgs/main/default.nix b/nix/pkgs/main/default.nix index f2fffec0..e7d15308 100644 --- a/nix/pkgs/main/default.nix +++ b/nix/pkgs/main/default.nix @@ -12,144 +12,146 @@ , rust-jemalloc-sys , stdenv -# Options (keep sorted) + # Options (keep sorted) , all_features ? false , default_features ? true -# default list of disabled features + # default list of disabled features , disable_features ? [ - # dont include experimental features - "experimental" - # jemalloc profiling/stats features are expensive and shouldn't - # be expected on non-debug builds. - "jemalloc_prof" - "jemalloc_stats" - # this is non-functional on nix for some reason - "hardened_malloc" - # conduwuit_mods is a development-only hot reload feature - "conduwuit_mods" -] + # dont include experimental features + "experimental" + # jemalloc profiling/stats features are expensive and shouldn't + # be expected on non-debug builds. + "jemalloc_prof" + "jemalloc_stats" + # this is non-functional on nix for some reason + "hardened_malloc" + # conduwuit_mods is a development-only hot reload feature + "conduwuit_mods" + ] , disable_release_max_log_level ? false -, features ? [] +, features ? [ ] , profile ? "release" -# rocksdb compiled with -march=haswell and target-cpu=haswell rustflag -# haswell is pretty much any x86 cpu made in the last 12 years, and -# supports modern CPU extensions that rocksdb can make use of. -# disable if trying to make a portable x86_64 build for very old hardware + # rocksdb compiled with -march=haswell and target-cpu=haswell rustflag + # haswell is pretty much any x86 cpu made in the last 12 years, and + # supports modern CPU extensions that rocksdb can make use of. + # disable if trying to make a portable x86_64 build for very old hardware , x86_64_haswell_target_optimised ? false }: let -# We perform default-feature unification in nix, because some of the dependencies -# on the nix side depend on feature values. -crateFeatures = path: - let manifest = lib.importTOML "${path}/Cargo.toml"; in - lib.remove "default" (lib.attrNames manifest.features); -crateDefaultFeatures = path: - (lib.importTOML "${path}/Cargo.toml").features.default; -allDefaultFeatures = crateDefaultFeatures "${inputs.self}/src/main"; -allFeatures = crateFeatures "${inputs.self}/src/main"; -features' = lib.unique - (features ++ - lib.optionals default_features allDefaultFeatures ++ - lib.optionals all_features allFeatures); -disable_features' = disable_features ++ lib.optionals disable_release_max_log_level ["release_max_log_level"]; -features'' = lib.subtractLists disable_features' features'; + # We perform default-feature unification in nix, because some of the dependencies + # on the nix side depend on feature values. + crateFeatures = path: + let manifest = lib.importTOML "${path}/Cargo.toml"; in + lib.remove "default" (lib.attrNames manifest.features); + crateDefaultFeatures = path: + (lib.importTOML "${path}/Cargo.toml").features.default; + allDefaultFeatures = crateDefaultFeatures "${inputs.self}/src/main"; + allFeatures = crateFeatures "${inputs.self}/src/main"; + features' = lib.unique + (features ++ + lib.optionals default_features allDefaultFeatures ++ + lib.optionals all_features allFeatures); + disable_features' = disable_features ++ lib.optionals disable_release_max_log_level [ "release_max_log_level" ]; + features'' = lib.subtractLists disable_features' features'; -featureEnabled = feature : builtins.elem feature features''; + featureEnabled = feature: builtins.elem feature features''; -enableLiburing = featureEnabled "io_uring" && !stdenv.hostPlatform.isDarwin; + enableLiburing = featureEnabled "io_uring" && !stdenv.hostPlatform.isDarwin; -# This derivation will set the JEMALLOC_OVERRIDE variable, causing the -# tikv-jemalloc-sys crate to use the nixpkgs jemalloc instead of building it's -# own. In order for this to work, we need to set flags on the build that match -# whatever flags tikv-jemalloc-sys was going to use. These are dependent on -# which features we enable in tikv-jemalloc-sys. -rust-jemalloc-sys' = (rust-jemalloc-sys.override { - # tikv-jemalloc-sys/unprefixed_malloc_on_supported_platforms feature - unprefixed = true; -}).overrideAttrs (old: { - configureFlags = old.configureFlags ++ - # we dont need docs - [ "--disable-doc" ] ++ - # we dont need cxx/C++ integration - [ "--disable-cxx" ] ++ - # tikv-jemalloc-sys/profiling feature - lib.optional (featureEnabled "jemalloc_prof") "--enable-prof" ++ - # tikv-jemalloc-sys/stats feature - (if (featureEnabled "jemalloc_stats") then [ "--enable-stats" ] else [ "--disable-stats" ]); -}); - -buildDepsOnlyEnv = - let - rocksdb' = (rocksdb.override { - jemalloc = lib.optional (featureEnabled "jemalloc") rust-jemalloc-sys'; - # rocksdb fails to build with prefixed jemalloc, which is required on - # darwin due to [1]. In this case, fall back to building rocksdb with - # libc malloc. This should not cause conflicts, because all of the - # jemalloc symbols are prefixed. - # - # [1]: https://github.com/tikv/jemallocator/blob/ab0676d77e81268cd09b059260c75b38dbef2d51/jemalloc-sys/src/env.rs#L17 - enableJemalloc = featureEnabled "jemalloc" && !stdenv.hostPlatform.isDarwin; - - # for some reason enableLiburing in nixpkgs rocksdb is default true - # which breaks Darwin entirely - enableLiburing = enableLiburing; - }).overrideAttrs (old: { - enableLiburing = enableLiburing; - cmakeFlags = (if x86_64_haswell_target_optimised then (lib.subtractLists [ - # dont make a portable build if x86_64_haswell_target_optimised is enabled - "-DPORTABLE=1" - ] old.cmakeFlags - ++ [ "-DPORTABLE=haswell" ]) else ([ "-DPORTABLE=1" ]) - ) - ++ old.cmakeFlags; - - # outputs has "tools" which we dont need or use - outputs = [ "out" ]; - - # preInstall hooks has stuff for messing with ldb/sst_dump which we dont need or use - preInstall = ""; - }); - in - { - # https://crane.dev/faq/rebuilds-bindgen.html - NIX_OUTPATH_USED_AS_RANDOM_SEED = "aaaaaaaaaa"; - - CARGO_PROFILE = profile; - ROCKSDB_INCLUDE_DIR = "${rocksdb'}/include"; - ROCKSDB_LIB_DIR = "${rocksdb'}/lib"; - } - // - (import ./cross-compilation-env.nix { - # Keep sorted - inherit - lib - pkgsBuildHost - rust - stdenv; + # This derivation will set the JEMALLOC_OVERRIDE variable, causing the + # tikv-jemalloc-sys crate to use the nixpkgs jemalloc instead of building it's + # own. In order for this to work, we need to set flags on the build that match + # whatever flags tikv-jemalloc-sys was going to use. These are dependent on + # which features we enable in tikv-jemalloc-sys. + rust-jemalloc-sys' = (rust-jemalloc-sys.override { + # tikv-jemalloc-sys/unprefixed_malloc_on_supported_platforms feature + unprefixed = true; + }).overrideAttrs (old: { + configureFlags = old.configureFlags ++ + # we dont need docs + [ "--disable-doc" ] ++ + # we dont need cxx/C++ integration + [ "--disable-cxx" ] ++ + # tikv-jemalloc-sys/profiling feature + lib.optional (featureEnabled "jemalloc_prof") "--enable-prof" ++ + # tikv-jemalloc-sys/stats feature + (if (featureEnabled "jemalloc_stats") then [ "--enable-stats" ] else [ "--disable-stats" ]); }); -buildPackageEnv = { - GIT_COMMIT_HASH = inputs.self.rev or inputs.self.dirtyRev or ""; - GIT_COMMIT_HASH_SHORT = inputs.self.shortRev or inputs.self.dirtyShortRev or ""; -} // buildDepsOnlyEnv // { - # Only needed in static stdenv because these are transitive dependencies of rocksdb - CARGO_BUILD_RUSTFLAGS = buildDepsOnlyEnv.CARGO_BUILD_RUSTFLAGS - + lib.optionalString (enableLiburing && stdenv.hostPlatform.isStatic) + buildDepsOnlyEnv = + let + rocksdb' = (rocksdb.override { + jemalloc = lib.optional (featureEnabled "jemalloc") rust-jemalloc-sys'; + # rocksdb fails to build with prefixed jemalloc, which is required on + # darwin due to [1]. In this case, fall back to building rocksdb with + # libc malloc. This should not cause conflicts, because all of the + # jemalloc symbols are prefixed. + # + # [1]: https://github.com/tikv/jemallocator/blob/ab0676d77e81268cd09b059260c75b38dbef2d51/jemalloc-sys/src/env.rs#L17 + enableJemalloc = featureEnabled "jemalloc" && !stdenv.hostPlatform.isDarwin; + + # for some reason enableLiburing in nixpkgs rocksdb is default true + # which breaks Darwin entirely + enableLiburing = enableLiburing; + }).overrideAttrs (old: { + enableLiburing = enableLiburing; + cmakeFlags = (if x86_64_haswell_target_optimised then + (lib.subtractLists [ + # dont make a portable build if x86_64_haswell_target_optimised is enabled + "-DPORTABLE=1" + ] + old.cmakeFlags + ++ [ "-DPORTABLE=haswell" ]) else ([ "-DPORTABLE=1" ]) + ) + ++ old.cmakeFlags; + + # outputs has "tools" which we dont need or use + outputs = [ "out" ]; + + # preInstall hooks has stuff for messing with ldb/sst_dump which we dont need or use + preInstall = ""; + }); + in + { + # https://crane.dev/faq/rebuilds-bindgen.html + NIX_OUTPATH_USED_AS_RANDOM_SEED = "aaaaaaaaaa"; + + CARGO_PROFILE = profile; + ROCKSDB_INCLUDE_DIR = "${rocksdb'}/include"; + ROCKSDB_LIB_DIR = "${rocksdb'}/lib"; + } + // + (import ./cross-compilation-env.nix { + # Keep sorted + inherit + lib + pkgsBuildHost + rust + stdenv; + }); + + buildPackageEnv = { + GIT_COMMIT_HASH = inputs.self.rev or inputs.self.dirtyRev or ""; + GIT_COMMIT_HASH_SHORT = inputs.self.shortRev or inputs.self.dirtyShortRev or ""; + } // buildDepsOnlyEnv // { + # Only needed in static stdenv because these are transitive dependencies of rocksdb + CARGO_BUILD_RUSTFLAGS = buildDepsOnlyEnv.CARGO_BUILD_RUSTFLAGS + + lib.optionalString (enableLiburing && stdenv.hostPlatform.isStatic) " -L${lib.getLib liburing}/lib -luring" - + lib.optionalString x86_64_haswell_target_optimised + + lib.optionalString x86_64_haswell_target_optimised " -Ctarget-cpu=haswell"; -}; + }; -commonAttrs = { - inherit - (craneLib.crateNameFromCargoToml { - cargoToml = "${inputs.self}/Cargo.toml"; - }) - pname - version; + commonAttrs = { + inherit + (craneLib.crateNameFromCargoToml { + cargoToml = "${inputs.self}/Cargo.toml"; + }) + pname + version; src = let filter = inputs.nix-filter.lib; in filter { root = inputs.self; @@ -167,22 +169,22 @@ commonAttrs = { cargoExtraArgs = "--no-default-features --locked " + lib.optionalString - (features'' != []) - "--features " + (builtins.concatStringsSep "," features''); + (features'' != [ ]) + "--features " + (builtins.concatStringsSep "," features''); dontStrip = profile == "dev" || profile == "test"; dontPatchELF = profile == "dev" || profile == "test"; buildInputs = lib.optional (featureEnabled "jemalloc") rust-jemalloc-sys' - # needed to build Rust applications on macOS - ++ lib.optionals stdenv.hostPlatform.isDarwin [ - # https://github.com/NixOS/nixpkgs/issues/206242 - # ld: library not found for -liconv - libiconv - # https://stackoverflow.com/questions/69869574/properly-adding-darwin-apple-sdk-to-a-nix-shell - # https://discourse.nixos.org/t/compile-a-rust-binary-on-macos-dbcrossbar/8612 - pkgsBuildHost.darwin.apple_sdk.frameworks.Security - ]; + # needed to build Rust applications on macOS + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + # https://github.com/NixOS/nixpkgs/issues/206242 + # ld: library not found for -liconv + libiconv + # https://stackoverflow.com/questions/69869574/properly-adding-darwin-apple-sdk-to-a-nix-shell + # https://discourse.nixos.org/t/compile-a-rust-binary-on-macos-dbcrossbar/8612 + pkgsBuildHost.darwin.apple_sdk.frameworks.Security + ]; nativeBuildInputs = [ # bindgen needs the build platform's libclang. Apparently due to "splicing @@ -195,11 +197,11 @@ commonAttrs = { # differing values for `NIX_CFLAGS_COMPILE`, which contributes to spurious # rebuilds of bindgen and its depedents. jq - ]; - }; + ]; + }; in -craneLib.buildPackage ( commonAttrs // { +craneLib.buildPackage (commonAttrs // { cargoArtifacts = craneLib.buildDepsOnly (commonAttrs // { env = buildDepsOnlyEnv; }); @@ -208,8 +210,8 @@ craneLib.buildPackage ( commonAttrs // { cargoExtraArgs = "--no-default-features --locked " + lib.optionalString - (features'' != []) - "--features " + (builtins.concatStringsSep "," features''); + (features'' != [ ]) + "--features " + (builtins.concatStringsSep "," features''); env = buildPackageEnv; diff --git a/nix/pkgs/oci-image/default.nix b/nix/pkgs/oci-image/default.nix index 953407ef..3b6e3226 100644 --- a/nix/pkgs/oci-image/default.nix +++ b/nix/pkgs/oci-image/default.nix @@ -1,6 +1,6 @@ { inputs -# Dependencies + # Dependencies , dockerTools , lib , main @@ -17,11 +17,12 @@ dockerTools.buildLayeredImage { main ]; config = { - Entrypoint = if !stdenv.hostPlatform.isDarwin + Entrypoint = + if !stdenv.hostPlatform.isDarwin # Use the `tini` init system so that signals (e.g. ctrl+c/SIGINT) # are handled as expected then [ "${lib.getExe' tini "tini"}" "--" ] - else []; + else [ ]; Cmd = [ "${lib.getExe main}" ]; @@ -31,7 +32,7 @@ dockerTools.buildLayeredImage { Labels = { "org.opencontainers.image.authors" = "June Clementine Strawberry and Jason Volk "; - "org.opencontainers.image.created" ="@${toString inputs.self.lastModified}"; + "org.opencontainers.image.created" = "@${toString inputs.self.lastModified}"; "org.opencontainers.image.description" = "a very cool Matrix chat homeserver written in Rust"; "org.opencontainers.image.documentation" = "https://continuwuity.org/"; "org.opencontainers.image.licenses" = "Apache-2.0";