Compare commits

...

1 commit

Author SHA1 Message Date
Samuel Meenzen
88b24310b5
chore: format nix using alejandra 2024-05-09 15:20:48 +02:00
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
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
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 = ./.; }
).defaultNix
{src = ./.;}
)
.defaultNix

View file

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

View file

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

View file

@ -1,16 +1,18 @@
# Keep sorted
{ default
, inputs
, mdbook
, stdenv
{
default,
inputs,
mdbook,
stdenv,
}:
stdenv.mkDerivation {
pname = "${default.pname}-book";
version = default.version;
src = let filter = inputs.nix-filter.lib; in filter {
src = let
filter = inputs.nix-filter.lib;
in
filter {
root = inputs.self;
# Keep sorted

View file

@ -1,28 +1,28 @@
{ lib
, pkgsBuildHost
, rust
, stdenv
{
lib,
pkgsBuildHost,
rust,
stdenv,
}:
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" ]
["-C" "relocation-model=static"]
++ lib.optionals
(stdenv.buildPlatform.config != stdenv.hostPlatform.config)
[ "-l" "c" ]
["-l" "c"]
++ lib.optionals
# This check has to match the one [here][0]. We only need to set
# these flags when using a different linker. Don't ask me why, though,
@ -46,15 +46,13 @@ lib.optionalAttrs stdenv.hostPlatform.isStatic {
]
);
}
# 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/5cdb38bb16c6d0a38779db14fcc766bc1b2394d6/pkgs/build-support/rust/lib/default.nix#L57-L80
//
(
// (
let
inherit (rust.lib) envVars;
in
@ -64,32 +62,27 @@ lib.optionalAttrs stdenv.hostPlatform.isStatic {
(
let
inherit (stdenv.targetPlatform.rust) cargoEnvVarTarget;
in
{
in {
"CC_${cargoEnvVarTarget}" = envVars.ccForTarget;
"CXX_${cargoEnvVarTarget}" = envVars.cxxForTarget;
"CARGO_TARGET_${cargoEnvVarTarget}_LINKER" =
envVars.linkerForTarget;
}
)
//
(
// (
let
inherit (stdenv.hostPlatform.rust) cargoEnvVarTarget rustcTarget;
in
{
in {
"CC_${cargoEnvVarTarget}" = envVars.ccForHost;
"CXX_${cargoEnvVarTarget}" = envVars.cxxForHost;
"CARGO_TARGET_${cargoEnvVarTarget}_LINKER" = envVars.linkerForHost;
CARGO_BUILD_TARGET = rustcTarget;
}
)
//
(
// (
let
inherit (stdenv.buildPlatform.rust) cargoEnvVarTarget;
in
{
in {
"CC_${cargoEnvVarTarget}" = envVars.ccForBuild;
"CXX_${cargoEnvVarTarget}" = envVars.cxxForBuild;
"CARGO_TARGET_${cargoEnvVarTarget}_LINKER" = envVars.linkerForBuild;

View file

@ -1,21 +1,18 @@
# Dependencies (keep sorted)
{ craneLib
, inputs
, lib
, pkgsBuildHost
, rocksdb
, rust
, stdenv
# Options (keep sorted)
, default-features ? true
, features ? []
, profile ? "release"
}:
let
buildDepsOnlyEnv =
let
{
craneLib,
inputs,
lib,
pkgsBuildHost,
rocksdb,
rust,
stdenv,
# Options (keep sorted)
default-features ? true,
features ? [],
profile ? "release",
}: let
buildDepsOnlyEnv = let
rocksdb' = rocksdb.override {
enableJemalloc = builtins.elem "jemalloc" features;
};
@ -25,19 +22,21 @@ let
ROCKSDB_INCLUDE_DIR = "${rocksdb'}/include";
ROCKSDB_LIB_DIR = "${rocksdb'}/lib";
}
//
(import ./cross-compilation-env.nix {
// (import ./cross-compilation-env.nix {
# Keep sorted
inherit
lib
pkgsBuildHost
rust
stdenv;
stdenv
;
});
buildPackageEnv = {
buildPackageEnv =
{
CONDUIT_VERSION_EXTRA = inputs.self.shortRev or inputs.self.dirtyShortRev;
} // buildDepsOnlyEnv;
}
// buildDepsOnlyEnv;
commonAttrs = {
inherit
@ -45,9 +44,13 @@ let
cargoToml = "${inputs.self}/Cargo.toml";
})
pname
version;
version
;
src = let filter = inputs.nix-filter.lib; in filter {
src = let
filter = inputs.nix-filter.lib;
in
filter {
root = inputs.self;
# Keep sorted
@ -68,19 +71,22 @@ let
CARGO_PROFILE = profile;
};
in
craneLib.buildPackage ( commonAttrs // {
cargoArtifacts = craneLib.buildDepsOnly (commonAttrs // {
craneLib.buildPackage (commonAttrs
// {
cargoArtifacts = craneLib.buildDepsOnly (commonAttrs
// {
env = buildDepsOnlyEnv;
});
cargoExtraArgs = "--locked "
cargoExtraArgs =
"--locked "
+ lib.optionalString
(!default-features)
"--no-default-features "
+ lib.optionalString
(features != [])
"--features " + (builtins.concatStringsSep "," features);
"--features "
+ (builtins.concatStringsSep "," features);
# This is redundant with CI
doCheck = false;
@ -92,4 +98,4 @@ craneLib.buildPackage ( commonAttrs // {
};
meta.mainProgram = commonAttrs.pname;
})
})

View file

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

View file

@ -1,21 +1,24 @@
# Keep sorted
{ cargo-deb
, default
, engage
, go
, inputs
, jq
, lychee
, mdbook
, mkShell
, olm
, system
, taplo
, toolchain
{
alejandra,
cargo-deb,
default,
engage,
go,
inputs,
jq,
lychee,
mdbook,
mkShell,
olm,
system,
taplo,
toolchain,
}:
mkShell {
env = default.env // {
env =
default.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.
@ -23,7 +26,9 @@ mkShell {
};
# Development tools
nativeBuildInputs = default.nativeBuildInputs ++ [
nativeBuildInputs =
default.nativeBuildInputs
++ [
# Always use nightly rustfmt because most of its options are unstable
#
# This needs to come before `toolchain` in this list, otherwise
@ -57,5 +62,8 @@ mkShell {
# Useful for editing the book locally
mdbook
# nix formatter
alejandra
];
}