1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2024-12-25 06:04:54 +01:00

chore: format nix using alejandra

This commit is contained in:
Samuel Meenzen 2024-05-09 15:20:48 +02:00
parent 3ad7675bbf
commit 88b24310b5
No known key found for this signature in database
8 changed files with 264 additions and 240 deletions

View file

@ -1,10 +1,14 @@
(import (
import
( (
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in let
fetchTarball { lock = builtins.fromJSON (builtins.readFile ./flake.lock);
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; in
sha256 = lock.nodes.flake-compat.locked.narHash; fetchTarball {
} url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
) )
{ src = ./.; } {src = ./.;}
).defaultNix )
.defaultNix

View file

@ -35,6 +35,11 @@ group = "versions"
name = "lychee" name = "lychee"
script = "lychee --version" script = "lychee --version"
[[task]]
group = "versions"
name = "alejandra"
script = "alejandra --version"
[[task]] [[task]]
group = "lints" group = "lints"
name = "cargo-fmt" name = "cargo-fmt"
@ -66,6 +71,11 @@ group = "lints"
name = "lychee" name = "lychee"
script = "lychee --offline docs" script = "lychee --offline docs"
[[task]]
group = "lints"
name = "alejandra"
script = "alejandra --check ."
[[task]] [[task]]
group = "tests" group = "tests"
name = "cargo" name = "cargo"

View file

@ -19,10 +19,10 @@
attic.url = "github:zhaofengli/attic?ref=main"; attic.url = "github:zhaofengli/attic?ref=main";
}; };
outputs = inputs: outputs = inputs: let
let # Keep sorted
# Keep sorted mkScope = pkgs:
mkScope = pkgs: pkgs.lib.makeScope pkgs.newScope (self: { pkgs.lib.makeScope pkgs.newScope (self: {
craneLib = craneLib =
(inputs.crane.mkLib pkgs).overrideToolchain self.toolchain; (inputs.crane.mkLib pkgs).overrideToolchain self.toolchain;
@ -34,24 +34,24 @@
book = self.callPackage ./nix/pkgs/book {}; book = self.callPackage ./nix/pkgs/book {};
rocksdb = rocksdb = let
let
version = "9.1.1"; version = "9.1.1";
in in
pkgs.rocksdb.overrideAttrs (old: { pkgs.rocksdb.overrideAttrs (old: {
inherit version; inherit version;
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "facebook"; owner = "facebook";
repo = "rocksdb"; repo = "rocksdb";
rev = "v${version}"; rev = "v${version}";
hash = "sha256-/Xf0bzNJPclH9IP80QNaABfhj4IAR5LycYET18VFCXc="; hash = "sha256-/Xf0bzNJPclH9IP80QNaABfhj4IAR5LycYET18VFCXc=";
}; };
}); });
shell = self.callPackage ./nix/shell.nix {}; shell = self.callPackage ./nix/shell.nix {};
# The Rust toolchain to use # The Rust toolchain to use
toolchain = inputs toolchain =
inputs
.fenix .fenix
.packages .packages
.${pkgs.pkgsBuildHost.system} .${pkgs.pkgsBuildHost.system}
@ -62,23 +62,24 @@
sha256 = "sha256-opUgs6ckUQCyDxcB9Wy51pqhd0MPGHUVbwRKKPGiwZU="; sha256 = "sha256-opUgs6ckUQCyDxcB9Wy51pqhd0MPGHUVbwRKKPGiwZU=";
}; };
}); });
in in
inputs.flake-utils.lib.eachDefaultSystem (system: inputs.flake-utils.lib.eachDefaultSystem (
let system: let
pkgs = inputs.nixpkgs.legacyPackages.${system}; pkgs = inputs.nixpkgs.legacyPackages.${system};
in in {
{ packages =
packages = { {
default = (mkScope pkgs).default; default = (mkScope pkgs).default;
oci-image = (mkScope pkgs).oci-image; oci-image = (mkScope pkgs).oci-image;
book = (mkScope pkgs).book; book = (mkScope pkgs).book;
} }
// // builtins.listToAttrs
builtins.listToAttrs (
(builtins.concatLists builtins.concatLists
(builtins.map (
(crossSystem: builtins.map
let (
crossSystem: let
binaryName = "static-${crossSystem}"; binaryName = "static-${crossSystem}";
pkgsCrossStatic = pkgsCrossStatic =
(import inputs.nixpkgs { (import inputs.nixpkgs {
@ -86,9 +87,9 @@
crossSystem = { crossSystem = {
config = crossSystem; config = crossSystem;
}; };
}).pkgsStatic; })
in .pkgsStatic;
[ in [
# An output for a statically-linked binary # An output for a statically-linked binary
{ {
name = binaryName; name = binaryName;

View file

@ -1,27 +1,29 @@
# Keep sorted # Keep sorted
{ default {
, inputs default,
, mdbook inputs,
, stdenv mdbook,
stdenv,
}: }:
stdenv.mkDerivation { stdenv.mkDerivation {
pname = "${default.pname}-book"; pname = "${default.pname}-book";
version = default.version; version = default.version;
src = let
filter = inputs.nix-filter.lib;
in
filter {
root = inputs.self;
src = let filter = inputs.nix-filter.lib; in filter { # Keep sorted
root = inputs.self; include = [
"book.toml"
# Keep sorted "conduit-example.toml"
include = [ "debian/README.md"
"book.toml" "docs"
"conduit-example.toml" "README.md"
"debian/README.md" ];
"docs" };
"README.md"
];
};
nativeBuildInputs = [ nativeBuildInputs = [
mdbook mdbook

View file

@ -1,100 +1,93 @@
{ lib {
, pkgsBuildHost lib,
, rust pkgsBuildHost,
, stdenv rust,
stdenv,
}: }:
lib.optionalAttrs stdenv.hostPlatform.isStatic { lib.optionalAttrs stdenv.hostPlatform.isStatic {
ROCKSDB_STATIC = ""; ROCKSDB_STATIC = "";
} }
// // {
{
CARGO_BUILD_RUSTFLAGS = CARGO_BUILD_RUSTFLAGS =
lib.concatStringsSep lib.concatStringsSep
" " " "
([] (
# This disables PIE for static builds, which isn't great in terms of []
# security. Unfortunately, my hand is forced because nixpkgs' # This disables PIE for static builds, which isn't great in terms of
# `libstdc++.a` is built without `-fPIE`, which precludes us from # security. Unfortunately, my hand is forced because nixpkgs'
# leaving PIE enabled. # `libstdc++.a` is built without `-fPIE`, which precludes us from
++ lib.optionals # leaving PIE enabled.
stdenv.hostPlatform.isStatic ++ lib.optionals
[ "-C" "relocation-model=static" ] stdenv.hostPlatform.isStatic
++ lib.optionals ["-C" "relocation-model=static"]
(stdenv.buildPlatform.config != stdenv.hostPlatform.config) ++ lib.optionals
[ "-l" "c" ] (stdenv.buildPlatform.config != stdenv.hostPlatform.config)
++ lib.optionals ["-l" "c"]
# This check has to match the one [here][0]. We only need to set ++ lib.optionals
# these flags when using a different linker. Don't ask me why, though, # This check has to match the one [here][0]. We only need to set
# because I don't know. All I know is it breaks otherwise. # these flags when using a different linker. Don't ask me why, though,
# # because I don't know. All I know is it breaks otherwise.
# [0]: https://github.com/NixOS/nixpkgs/blob/5cdb38bb16c6d0a38779db14fcc766bc1b2394d6/pkgs/build-support/rust/lib/default.nix#L37-L40 #
( # [0]: https://github.com/NixOS/nixpkgs/blob/5cdb38bb16c6d0a38779db14fcc766bc1b2394d6/pkgs/build-support/rust/lib/default.nix#L37-L40
# Nixpkgs doesn't check for x86_64 here but we do, because I (
# observed a failure building statically for x86_64 without # Nixpkgs doesn't check for x86_64 here but we do, because I
# including it here. Linkers are weird. # observed a failure building statically for x86_64 without
(stdenv.hostPlatform.isAarch64 || stdenv.hostPlatform.isx86_64) # including it here. Linkers are weird.
&& stdenv.hostPlatform.isStatic (stdenv.hostPlatform.isAarch64 || stdenv.hostPlatform.isx86_64)
&& !stdenv.isDarwin && stdenv.hostPlatform.isStatic
&& !stdenv.cc.bintools.isLLVM && !stdenv.isDarwin
) && !stdenv.cc.bintools.isLLVM
[ )
"-l" [
"stdc++" "-l"
"-L" "stdc++"
"${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 # 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 # 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 # case of build scripts that need native code compiled and run on the build
# platform (I think). # platform (I think).
# #
# [0]: https://github.com/NixOS/nixpkgs/blob/5cdb38bb16c6d0a38779db14fcc766bc1b2394d6/pkgs/build-support/rust/lib/default.nix#L57-L80 # [0]: https://github.com/NixOS/nixpkgs/blob/5cdb38bb16c6d0a38779db14fcc766bc1b2394d6/pkgs/build-support/rust/lib/default.nix#L57-L80
// // (
(
let let
inherit (rust.lib) envVars; inherit (rust.lib) envVars;
in in
lib.optionalAttrs lib.optionalAttrs
(stdenv.targetPlatform.rust.rustcTarget (stdenv.targetPlatform.rust.rustcTarget
!= stdenv.hostPlatform.rust.rustcTarget) != stdenv.hostPlatform.rust.rustcTarget)
( (
let let
inherit (stdenv.targetPlatform.rust) cargoEnvVarTarget; inherit (stdenv.targetPlatform.rust) cargoEnvVarTarget;
in in {
{
"CC_${cargoEnvVarTarget}" = envVars.ccForTarget; "CC_${cargoEnvVarTarget}" = envVars.ccForTarget;
"CXX_${cargoEnvVarTarget}" = envVars.cxxForTarget; "CXX_${cargoEnvVarTarget}" = envVars.cxxForTarget;
"CARGO_TARGET_${cargoEnvVarTarget}_LINKER" = "CARGO_TARGET_${cargoEnvVarTarget}_LINKER" =
envVars.linkerForTarget; envVars.linkerForTarget;
} }
) )
// // (
( let
let inherit (stdenv.hostPlatform.rust) cargoEnvVarTarget rustcTarget;
inherit (stdenv.hostPlatform.rust) cargoEnvVarTarget rustcTarget; in {
in "CC_${cargoEnvVarTarget}" = envVars.ccForHost;
{ "CXX_${cargoEnvVarTarget}" = envVars.cxxForHost;
"CC_${cargoEnvVarTarget}" = envVars.ccForHost; "CARGO_TARGET_${cargoEnvVarTarget}_LINKER" = envVars.linkerForHost;
"CXX_${cargoEnvVarTarget}" = envVars.cxxForHost; CARGO_BUILD_TARGET = rustcTarget;
"CARGO_TARGET_${cargoEnvVarTarget}_LINKER" = envVars.linkerForHost; }
CARGO_BUILD_TARGET = rustcTarget; )
} // (
) let
// inherit (stdenv.buildPlatform.rust) cargoEnvVarTarget;
( in {
let "CC_${cargoEnvVarTarget}" = envVars.ccForBuild;
inherit (stdenv.buildPlatform.rust) cargoEnvVarTarget; "CXX_${cargoEnvVarTarget}" = envVars.cxxForBuild;
in "CARGO_TARGET_${cargoEnvVarTarget}_LINKER" = envVars.linkerForBuild;
{ HOST_CC = "${pkgsBuildHost.stdenv.cc}/bin/cc";
"CC_${cargoEnvVarTarget}" = envVars.ccForBuild; HOST_CXX = "${pkgsBuildHost.stdenv.cc}/bin/c++";
"CXX_${cargoEnvVarTarget}" = envVars.cxxForBuild; }
"CARGO_TARGET_${cargoEnvVarTarget}_LINKER" = envVars.linkerForBuild; )
HOST_CC = "${pkgsBuildHost.stdenv.cc}/bin/cc";
HOST_CXX = "${pkgsBuildHost.stdenv.cc}/bin/c++";
}
)
) )

View file

@ -1,43 +1,42 @@
# Dependencies (keep sorted) # Dependencies (keep sorted)
{ craneLib {
, inputs craneLib,
, lib inputs,
, pkgsBuildHost lib,
, rocksdb pkgsBuildHost,
, rust rocksdb,
, stdenv rust,
stdenv,
# Options (keep sorted) # Options (keep sorted)
, default-features ? true default-features ? true,
, features ? [] features ? [],
, profile ? "release" profile ? "release",
}: }: let
buildDepsOnlyEnv = let
let rocksdb' = rocksdb.override {
buildDepsOnlyEnv = enableJemalloc = builtins.elem "jemalloc" features;
let };
rocksdb' = rocksdb.override { in
enableJemalloc = builtins.elem "jemalloc" features;
};
in
{ {
NIX_OUTPATH_USED_AS_RANDOM_SEED = "randomseed"; # https://crane.dev/faq/rebuilds-bindgen.html NIX_OUTPATH_USED_AS_RANDOM_SEED = "randomseed"; # https://crane.dev/faq/rebuilds-bindgen.html
ROCKSDB_INCLUDE_DIR = "${rocksdb'}/include"; ROCKSDB_INCLUDE_DIR = "${rocksdb'}/include";
ROCKSDB_LIB_DIR = "${rocksdb'}/lib"; ROCKSDB_LIB_DIR = "${rocksdb'}/lib";
} }
// // (import ./cross-compilation-env.nix {
(import ./cross-compilation-env.nix {
# Keep sorted # Keep sorted
inherit inherit
lib lib
pkgsBuildHost pkgsBuildHost
rust rust
stdenv; stdenv
;
}); });
buildPackageEnv = { buildPackageEnv =
CONDUIT_VERSION_EXTRA = inputs.self.shortRev or inputs.self.dirtyShortRev; {
} // buildDepsOnlyEnv; CONDUIT_VERSION_EXTRA = inputs.self.shortRev or inputs.self.dirtyShortRev;
}
// buildDepsOnlyEnv;
commonAttrs = { commonAttrs = {
inherit inherit
@ -45,18 +44,22 @@ let
cargoToml = "${inputs.self}/Cargo.toml"; cargoToml = "${inputs.self}/Cargo.toml";
}) })
pname pname
version; version
;
src = let filter = inputs.nix-filter.lib; in filter { src = let
root = inputs.self; filter = inputs.nix-filter.lib;
in
filter {
root = inputs.self;
# Keep sorted # Keep sorted
include = [ include = [
"Cargo.lock" "Cargo.lock"
"Cargo.toml" "Cargo.toml"
"src" "src"
]; ];
}; };
nativeBuildInputs = [ nativeBuildInputs = [
# bindgen needs the build platform's libclang. Apparently due to "splicing # bindgen needs the build platform's libclang. Apparently due to "splicing
@ -68,28 +71,31 @@ let
CARGO_PROFILE = profile; CARGO_PROFILE = profile;
}; };
in in
craneLib.buildPackage (commonAttrs
// {
cargoArtifacts = craneLib.buildDepsOnly (commonAttrs
// {
env = buildDepsOnlyEnv;
});
craneLib.buildPackage ( commonAttrs // { cargoExtraArgs =
cargoArtifacts = craneLib.buildDepsOnly (commonAttrs // { "--locked "
env = buildDepsOnlyEnv; + lib.optionalString
}); (!default-features)
"--no-default-features "
+ lib.optionalString
(features != [])
"--features "
+ (builtins.concatStringsSep "," features);
cargoExtraArgs = "--locked " # This is redundant with CI
+ lib.optionalString doCheck = false;
(!default-features)
"--no-default-features "
+ lib.optionalString
(features != [])
"--features " + (builtins.concatStringsSep "," features);
# This is redundant with CI env = buildPackageEnv;
doCheck = false;
env = buildPackageEnv; passthru = {
env = buildPackageEnv;
};
passthru = { meta.mainProgram = commonAttrs.pname;
env = buildPackageEnv; })
};
meta.mainProgram = commonAttrs.pname;
})

View file

@ -1,10 +1,10 @@
# Keep sorted # Keep sorted
{ default {
, dockerTools default,
, lib dockerTools,
, tini lib,
tini,
}: }:
dockerTools.buildImage { dockerTools.buildImage {
name = default.pname; name = default.pname;
tag = "next"; tag = "next";

View file

@ -1,61 +1,69 @@
# Keep sorted # Keep sorted
{ cargo-deb {
, default alejandra,
, engage cargo-deb,
, go default,
, inputs engage,
, jq go,
, lychee inputs,
, mdbook jq,
, mkShell lychee,
, olm mdbook,
, system mkShell,
, taplo olm,
, toolchain system,
taplo,
toolchain,
}: }:
mkShell { mkShell {
env = default.env // { env =
# Rust Analyzer needs to be able to find the path to default crate default.env
# sources, and it can read this environment variable to do so. The // {
# `rust-src` component is required in order for this to work. # Rust Analyzer needs to be able to find the path to default crate
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library"; # 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";
};
# Development tools # Development tools
nativeBuildInputs = default.nativeBuildInputs ++ [ nativeBuildInputs =
# Always use nightly rustfmt because most of its options are unstable default.nativeBuildInputs
# ++ [
# This needs to come before `toolchain` in this list, otherwise # Always use nightly rustfmt because most of its options are unstable
# `$PATH` will have stable rustfmt instead. #
inputs.fenix.packages.${system}.latest.rustfmt # This needs to come before `toolchain` in this list, otherwise
# `$PATH` will have stable rustfmt instead.
inputs.fenix.packages.${system}.latest.rustfmt
# rust itself # rust itself
toolchain toolchain
# CI tests # CI tests
engage engage
# format toml files # format toml files
taplo taplo
# Needed for producing Debian packages # Needed for producing Debian packages
cargo-deb cargo-deb
# Needed for our script for Complement # Needed for our script for Complement
jq jq
# Needed for Complement # Needed for Complement
go go
olm olm
# Needed for our script for Complement # Needed for our script for Complement
jq jq
# Needed for finding broken markdown links # Needed for finding broken markdown links
lychee lychee
# Useful for editing the book locally # Useful for editing the book locally
mdbook mdbook
];
# nix formatter
alejandra
];
} }