chore: format nix using alejandra

merge-requests/675/head
Samuel Meenzen 2 months ago
parent 3ad7675bbf
commit 88b24310b5
No known key found for this signature in database

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

@ -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"

@ -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: pkgs.lib.makeScope pkgs.newScope (self: { mkScope = pkgs:
pkgs.lib.makeScope pkgs.newScope (self: {
craneLib = craneLib =
(inputs.crane.mkLib pkgs).overrideToolchain self.toolchain; (inputs.crane.mkLib pkgs).overrideToolchain self.toolchain;
@ -34,8 +34,7 @@
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: {
@ -51,7 +50,8 @@
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}
@ -63,22 +63,23 @@
}; };
}); });
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;

@ -1,16 +1,18 @@
# 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
src = let filter = inputs.nix-filter.lib; in filter { filter = inputs.nix-filter.lib;
in
filter {
root = inputs.self; root = inputs.self;
# Keep sorted # Keep sorted

@ -1,18 +1,18 @@
{ 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 # This disables PIE for static builds, which isn't great in terms of
# security. Unfortunately, my hand is forced because nixpkgs' # security. Unfortunately, my hand is forced because nixpkgs'
# `libstdc++.a` is built without `-fPIE`, which precludes us from # `libstdc++.a` is built without `-fPIE`, which precludes us from
@ -46,15 +46,13 @@ lib.optionalAttrs stdenv.hostPlatform.isStatic {
] ]
); );
} }
# 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
@ -64,32 +62,27 @@ lib.optionalAttrs stdenv.hostPlatform.isStatic {
( (
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; "CC_${cargoEnvVarTarget}" = envVars.ccForHost;
"CXX_${cargoEnvVarTarget}" = envVars.cxxForHost; "CXX_${cargoEnvVarTarget}" = envVars.cxxForHost;
"CARGO_TARGET_${cargoEnvVarTarget}_LINKER" = envVars.linkerForHost; "CARGO_TARGET_${cargoEnvVarTarget}_LINKER" = envVars.linkerForHost;
CARGO_BUILD_TARGET = rustcTarget; CARGO_BUILD_TARGET = rustcTarget;
} }
) )
// // (
(
let let
inherit (stdenv.buildPlatform.rust) cargoEnvVarTarget; inherit (stdenv.buildPlatform.rust) cargoEnvVarTarget;
in in {
{
"CC_${cargoEnvVarTarget}" = envVars.ccForBuild; "CC_${cargoEnvVarTarget}" = envVars.ccForBuild;
"CXX_${cargoEnvVarTarget}" = envVars.cxxForBuild; "CXX_${cargoEnvVarTarget}" = envVars.cxxForBuild;
"CARGO_TARGET_${cargoEnvVarTarget}_LINKER" = envVars.linkerForBuild; "CARGO_TARGET_${cargoEnvVarTarget}_LINKER" = envVars.linkerForBuild;

@ -1,21 +1,18 @@
# 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
buildDepsOnlyEnv =
let
rocksdb' = rocksdb.override { rocksdb' = rocksdb.override {
enableJemalloc = builtins.elem "jemalloc" features; enableJemalloc = builtins.elem "jemalloc" features;
}; };
@ -25,19 +22,21 @@ let
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; CONDUIT_VERSION_EXTRA = inputs.self.shortRev or inputs.self.dirtyShortRev;
} // buildDepsOnlyEnv; }
// buildDepsOnlyEnv;
commonAttrs = { commonAttrs = {
inherit inherit
@ -45,9 +44,13 @@ 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
filter = inputs.nix-filter.lib;
in
filter {
root = inputs.self; root = inputs.self;
# Keep sorted # Keep sorted
@ -68,19 +71,22 @@ let
CARGO_PROFILE = profile; CARGO_PROFILE = profile;
}; };
in in
craneLib.buildPackage (commonAttrs
craneLib.buildPackage ( commonAttrs // { // {
cargoArtifacts = craneLib.buildDepsOnly (commonAttrs // { cargoArtifacts = craneLib.buildDepsOnly (commonAttrs
// {
env = buildDepsOnlyEnv; env = buildDepsOnlyEnv;
}); });
cargoExtraArgs = "--locked " cargoExtraArgs =
"--locked "
+ lib.optionalString + lib.optionalString
(!default-features) (!default-features)
"--no-default-features " "--no-default-features "
+ lib.optionalString + lib.optionalString
(features != []) (features != [])
"--features " + (builtins.concatStringsSep "," features); "--features "
+ (builtins.concatStringsSep "," features);
# This is redundant with CI # This is redundant with CI
doCheck = false; doCheck = false;

@ -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";

@ -1,21 +1,24 @@
# 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 =
default.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
# `rust-src` component is required in order for this to work. # `rust-src` component is required in order for this to work.
@ -23,7 +26,9 @@ mkShell {
}; };
# Development tools # Development tools
nativeBuildInputs = default.nativeBuildInputs ++ [ nativeBuildInputs =
default.nativeBuildInputs
++ [
# 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
@ -57,5 +62,8 @@ mkShell {
# Useful for editing the book locally # Useful for editing the book locally
mdbook mdbook
# nix formatter
alejandra
]; ];
} }

Loading…
Cancel
Save