style: Format nix

nixfmt-rfc-style for flake
nixpkgs-fmt for nix/ directory
This commit is contained in:
Shuroii 2025-07-03 12:47:22 +02:00 committed by Jade Ellis
parent 0e2fdc415c
commit 09199b0ea7
No known key found for this signature in database
GPG key ID: 8705A2A3EBF77BD2
6 changed files with 780 additions and 725 deletions

142
flake.nix
View file

@ -2,19 +2,38 @@
inputs = { inputs = {
attic.url = "github:zhaofengli/attic?ref=main"; attic.url = "github:zhaofengli/attic?ref=main";
cachix.url = "github:cachix/cachix?ref=master"; cachix.url = "github:cachix/cachix?ref=master";
complement = { url = "github:girlbossceo/complement?ref=main"; flake = false; }; complement = {
crane = { url = "github:ipetkov/crane?ref=master"; }; url = "github:girlbossceo/complement?ref=main";
fenix = { url = "github:nix-community/fenix?ref=main"; inputs.nixpkgs.follows = "nixpkgs"; }; flake = false;
flake-compat = { url = "github:edolstra/flake-compat?ref=master"; 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"; flake-utils.url = "github:numtide/flake-utils?ref=main";
nix-filter.url = "github:numtide/nix-filter?ref=main"; nix-filter.url = "github:numtide/nix-filter?ref=main";
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs?ref=nixpkgs-unstable";
rocksdb = { url = "github:girlbossceo/rocksdb?ref=v9.11.1"; flake = false; }; rocksdb = {
liburing = { url = "github:axboe/liburing?ref=master"; flake = false; }; url = "github:girlbossceo/rocksdb?ref=v9.11.1";
flake = false;
};
liburing = {
url = "github:axboe/liburing?ref=master";
flake = false;
};
}; };
outputs = inputs: outputs =
inputs.flake-utils.lib.eachDefaultSystem (system: inputs:
inputs.flake-utils.lib.eachDefaultSystem (
system:
let let
pkgsHost = import inputs.nixpkgs { pkgsHost = import inputs.nixpkgs {
inherit system; inherit system;
@ -26,10 +45,12 @@
file = ./rust-toolchain.toml; file = ./rust-toolchain.toml;
# See also `rust-toolchain.toml` # See also `rust-toolchain.toml`
sha256 = "sha256-KUm16pHj+cRedf8vxs/Hd2YWxpOrWZ7UOrwhILdSJBU="; sha256 = "sha256-X/4ZBHO3iW0fOenQ3foEvscgAPJYl2abspaBThDOukI=";
}; };
mkScope = pkgs: pkgs.lib.makeScope pkgs.newScope (self: { mkScope =
pkgs:
pkgs.lib.makeScope pkgs.newScope (self: {
inherit pkgs; inherit pkgs;
book = self.callPackage ./nix/pkgs/book { }; book = self.callPackage ./nix/pkgs/book { };
complement = self.callPackage ./nix/pkgs/complement { }; complement = self.callPackage ./nix/pkgs/complement { };
@ -39,7 +60,8 @@
oci-image = self.callPackage ./nix/pkgs/oci-image { }; oci-image = self.callPackage ./nix/pkgs/oci-image { };
tini = pkgs.tini.overrideAttrs { tini = pkgs.tini.overrideAttrs {
# newer clang/gcc is unhappy with tini-static: <https://3.dog/~strawberry/pb/c8y4> # newer clang/gcc is unhappy with tini-static: <https://3.dog/~strawberry/pb/c8y4>
patches = [ (pkgs.fetchpatch { patches = [
(pkgs.fetchpatch {
url = "https://patch-diff.githubusercontent.com/raw/krallin/tini/pull/224.patch"; url = "https://patch-diff.githubusercontent.com/raw/krallin/tini/pull/224.patch";
hash = "sha256-4bTfAhRyIT71VALhHY13hUgbjLEUyvgkIJMt3w9ag3k="; hash = "sha256-4bTfAhRyIT71VALhHY13hUgbjLEUyvgkIJMt3w9ag3k=";
}) })
@ -47,23 +69,27 @@
}; };
liburing = pkgs.liburing.overrideAttrs { liburing = pkgs.liburing.overrideAttrs {
# Tests weren't building # Tests weren't building
outputs = [ "out" "dev" "man" ]; outputs = [
"out"
"dev"
"man"
];
buildFlags = [ "library" ]; buildFlags = [ "library" ];
src = inputs.liburing; src = inputs.liburing;
}; };
rocksdb = (pkgs.rocksdb.override { rocksdb =
(pkgs.rocksdb.override {
liburing = self.liburing; liburing = self.liburing;
}).overrideAttrs (old: { }).overrideAttrs
(old: {
src = inputs.rocksdb; src = inputs.rocksdb;
version = pkgs.lib.removePrefix version = pkgs.lib.removePrefix "v" (builtins.fromJSON (builtins.readFile ./flake.lock))
"v"
(builtins.fromJSON (builtins.readFile ./flake.lock))
.nodes.rocksdb.original.ref; .nodes.rocksdb.original.ref;
# we have this already at https://github.com/girlbossceo/rocksdb/commit/a935c0273e1ba44eacf88ce3685a9b9831486155 # 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 # unsetting this so i don't have to revert it and make this nix exclusive
patches = [ ]; patches = [ ];
cmakeFlags = pkgs.lib.subtractLists cmakeFlags =
[ pkgs.lib.subtractLists [
# no real reason to have snappy or zlib, no one uses this # no real reason to have snappy or zlib, no one uses this
"-DWITH_SNAPPY=1" "-DWITH_SNAPPY=1"
"-DZLIB=1" "-DZLIB=1"
@ -79,8 +105,7 @@
"-DFORCE_SSE42=1" "-DFORCE_SSE42=1"
# PORTABLE will get set in main/default.nix # PORTABLE will get set in main/default.nix
"-DPORTABLE=1" "-DPORTABLE=1"
] ] old.cmakeFlags
old.cmakeFlags
++ [ ++ [
# no real reason to have snappy, no one uses this # no real reason to have snappy, no one uses this
"-DWITH_SNAPPY=0" "-DWITH_SNAPPY=0"
@ -107,8 +132,11 @@
scopeHost = mkScope pkgsHost; scopeHost = mkScope pkgsHost;
scopeHostStatic = mkScope pkgsHostStatic; scopeHostStatic = mkScope pkgsHostStatic;
scopeCrossLinux = mkScope pkgsHost.pkgsLinux.pkgsStatic; scopeCrossLinux = mkScope pkgsHost.pkgsLinux.pkgsStatic;
mkCrossScope = crossSystem: mkCrossScope =
let pkgsCrossStatic = (import inputs.nixpkgs { crossSystem:
let
pkgsCrossStatic =
(import inputs.nixpkgs {
inherit system; inherit system;
crossSystem = { crossSystem = {
config = crossSystem; config = crossSystem;
@ -117,7 +145,9 @@
in in
mkScope pkgsCrossStatic; mkScope pkgsCrossStatic;
mkDevShell = scope: scope.pkgs.mkShell { mkDevShell =
scope:
scope.pkgs.mkShell {
env = scope.main.env // { env = scope.main.env // {
# Rust Analyzer needs to be able to find the path to default crate # 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 # sources, and it can read this environment variable to do so. The
@ -134,7 +164,8 @@
}; };
# Development tools # Development tools
packages = [ packages =
[
# Always use nightly rustfmt because most of its options are unstable # Always use nightly rustfmt because most of its options are unstable
# #
# This needs to come before `toolchain` in this list, otherwise # This needs to come before `toolchain` in this list, otherwise
@ -143,7 +174,9 @@
toolchain toolchain
] ]
++ (with pkgsHost.pkgs; [ ++ (
with pkgsHost.pkgs;
[
# Required by hardened-malloc.rs dep # Required by hardened-malloc.rs dep
binutils binutils
@ -179,14 +212,16 @@
] ]
# liburing is Linux-exclusive # liburing is Linux-exclusive
++ lib.optional stdenv.hostPlatform.isLinux liburing ++ lib.optional stdenv.hostPlatform.isLinux liburing
++ lib.optional stdenv.hostPlatform.isLinux numactl) ++ lib.optional stdenv.hostPlatform.isLinux numactl
)
++ scope.main.buildInputs ++ scope.main.buildInputs
++ scope.main.propagatedBuildInputs ++ scope.main.propagatedBuildInputs
++ scope.main.nativeBuildInputs; ++ scope.main.nativeBuildInputs;
}; };
in in
{ {
packages = { packages =
{
default = scopeHost.main.override { default = scopeHost.main.override {
disable_features = [ disable_features = [
# dont include experimental features # dont include experimental features
@ -305,11 +340,11 @@
# macOS containers don't exist, so the complement images must be forced to linux # macOS containers don't exist, so the complement images must be forced to linux
linux-complement = (mkCrossScope "${pkgsHost.hostPlatform.qemuArch}-linux-musl").complement; linux-complement = (mkCrossScope "${pkgsHost.hostPlatform.qemuArch}-linux-musl").complement;
} }
// // builtins.listToAttrs (
builtins.listToAttrs builtins.concatLists (
(builtins.concatLists builtins.map
(builtins.map (
(crossSystem: crossSystem:
let let
binaryName = "static-${crossSystem}"; binaryName = "static-${crossSystem}";
scopeCrossStatic = mkCrossScope crossSystem; scopeCrossStatic = mkCrossScope crossSystem;
@ -326,7 +361,9 @@
{ {
name = "${binaryName}-x86_64-haswell-optimised"; name = "${binaryName}-x86_64-haswell-optimised";
value = scopeCrossStatic.main.override { value = scopeCrossStatic.main.override {
x86_64_haswell_target_optimised = (if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false); x86_64_haswell_target_optimised = (
if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false
);
}; };
} }
@ -396,7 +433,9 @@
# conduwuit_mods is a development-only hot reload feature # conduwuit_mods is a development-only hot reload feature
"conduwuit_mods" "conduwuit_mods"
]; ];
x86_64_haswell_target_optimised = (if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false); x86_64_haswell_target_optimised = (
if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false
);
}; };
} }
@ -439,7 +478,9 @@
name = "oci-image-${crossSystem}-x86_64-haswell-optimised"; name = "oci-image-${crossSystem}-x86_64-haswell-optimised";
value = scopeCrossStatic.oci-image.override { value = scopeCrossStatic.oci-image.override {
main = scopeCrossStatic.main.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); x86_64_haswell_target_optimised = (
if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false
);
}; };
}; };
} }
@ -497,7 +538,9 @@
# conduwuit_mods is a development-only hot reload feature # conduwuit_mods is a development-only hot reload feature
"conduwuit_mods" "conduwuit_mods"
]; ];
x86_64_haswell_target_optimised = (if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false); x86_64_haswell_target_optimised = (
if (crossSystem == "x86_64-linux-gnu" || crossSystem == "x86_64-linux-musl") then true else false
);
}; };
}; };
} }
@ -551,8 +594,9 @@
); );
devShells.default = mkDevShell scopeHostStatic; devShells.default = mkDevShell scopeHostStatic;
devShells.all-features = mkDevShell devShells.all-features = mkDevShell (
(scopeHostStatic.overrideScope (final: prev: { scopeHostStatic.overrideScope (
final: prev: {
main = prev.main.override { main = prev.main.override {
all_features = true; all_features = true;
disable_features = [ disable_features = [
@ -568,11 +612,17 @@
"conduwuit_mods" "conduwuit_mods"
]; ];
}; };
})); }
devShells.no-features = mkDevShell )
(scopeHostStatic.overrideScope (final: prev: { );
main = prev.main.override { default_features = false; }; devShells.no-features = mkDevShell (
})); scopeHostStatic.overrideScope (
devShells.dynamic = mkDevShell scopeHost; final: prev: {
}); main = prev.main.override { default_features = false; };
}
)
);
devShells.dynamic = mkDevShell scopeHost;
}
);
} }

View file

@ -68,7 +68,8 @@ dockerTools.buildImage {
"${lib.getExe start}" "${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) # Use the `tini` init system so that signals (e.g. ctrl+c/SIGINT)
# are handled as expected # are handled as expected
then [ "${lib.getExe' tini "tini"}" "--" ] then [ "${lib.getExe' tini "tini"}" "--" ]

View file

@ -4,7 +4,8 @@
, stdenv , stdenv
}: }:
lib.optionalAttrs stdenv.hostPlatform.isStatic { lib.optionalAttrs stdenv.hostPlatform.isStatic
{
ROCKSDB_STATIC = ""; ROCKSDB_STATIC = "";
} }
// //

View file

@ -96,10 +96,12 @@ buildDepsOnlyEnv =
enableLiburing = enableLiburing; enableLiburing = enableLiburing;
}).overrideAttrs (old: { }).overrideAttrs (old: {
enableLiburing = enableLiburing; enableLiburing = enableLiburing;
cmakeFlags = (if x86_64_haswell_target_optimised then (lib.subtractLists [ cmakeFlags = (if x86_64_haswell_target_optimised then
(lib.subtractLists [
# dont make a portable build if x86_64_haswell_target_optimised is enabled # dont make a portable build if x86_64_haswell_target_optimised is enabled
"-DPORTABLE=1" "-DPORTABLE=1"
] old.cmakeFlags ]
old.cmakeFlags
++ [ "-DPORTABLE=haswell" ]) else ([ "-DPORTABLE=1" ]) ++ [ "-DPORTABLE=haswell" ]) else ([ "-DPORTABLE=1" ])
) )
++ old.cmakeFlags; ++ old.cmakeFlags;

View file

@ -17,7 +17,8 @@ dockerTools.buildLayeredImage {
main main
]; ];
config = { config = {
Entrypoint = if !stdenv.hostPlatform.isDarwin Entrypoint =
if !stdenv.hostPlatform.isDarwin
# Use the `tini` init system so that signals (e.g. ctrl+c/SIGINT) # Use the `tini` init system so that signals (e.g. ctrl+c/SIGINT)
# are handled as expected # are handled as expected
then [ "${lib.getExe' tini "tini"}" "--" ] then [ "${lib.getExe' tini "tini"}" "--" ]