chore: Apply nixfmt
(cherry picked from commit d11c2029c5a33ec522f46dd3e00fec8db2c3729b)
This commit is contained in:
parent
eba8c06c9d
commit
83dece62b2
3 changed files with 184 additions and 138 deletions
|
|
@ -1,80 +1,94 @@
|
||||||
{ lib, inputs, withSystem, ... }: {
|
{
|
||||||
|
lib,
|
||||||
|
inputs,
|
||||||
|
withSystem,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
imports = [
|
imports = [
|
||||||
inputs.pre-commit-hooks-nix.flakeModule
|
inputs.pre-commit-hooks-nix.flakeModule
|
||||||
inputs.hercules-ci-effects.flakeModule
|
inputs.hercules-ci-effects.flakeModule
|
||||||
];
|
];
|
||||||
perSystem = { config, pkgs, ... }: {
|
perSystem =
|
||||||
|
{ config, pkgs, ... }:
|
||||||
|
{
|
||||||
|
|
||||||
pre-commit.settings.hooks.nixfmt-rfc-style.enable = true;
|
pre-commit.settings.hooks.nixfmt-rfc-style.enable = true;
|
||||||
# Temporarily disable rustfmt due to configuration issues
|
# Temporarily disable rustfmt due to configuration issues
|
||||||
# pre-commit.settings.hooks.rustfmt.enable = true;
|
# pre-commit.settings.hooks.rustfmt.enable = true;
|
||||||
pre-commit.settings.settings.rust.cargoManifestPath = "./rust/Cargo.toml";
|
pre-commit.settings.settings.rust.cargoManifestPath = "./rust/Cargo.toml";
|
||||||
|
|
||||||
# Check that we're using ///-style doc comments in Rust code.
|
# Check that we're using ///-style doc comments in Rust code.
|
||||||
#
|
#
|
||||||
# Unfortunately, rustfmt won't do this for us yet - at least not
|
# Unfortunately, rustfmt won't do this for us yet - at least not
|
||||||
# without nightly, and it might do too much.
|
# without nightly, and it might do too much.
|
||||||
pre-commit.settings.hooks.rust-doc-comments = {
|
pre-commit.settings.hooks.rust-doc-comments = {
|
||||||
enable = true;
|
enable = true;
|
||||||
files = "\\.rs$";
|
files = "\\.rs$";
|
||||||
entry = "${pkgs.writeScript "rust-doc-comments" ''
|
entry = "${pkgs.writeScript "rust-doc-comments" ''
|
||||||
#!${pkgs.runtimeShell}
|
#!${pkgs.runtimeShell}
|
||||||
set -uxo pipefail
|
set -uxo pipefail
|
||||||
grep -n -C3 --color=always -F '/**' "$@"
|
grep -n -C3 --color=always -F '/**' "$@"
|
||||||
r=$?
|
r=$?
|
||||||
set -e
|
set -e
|
||||||
if [ $r -eq 0 ]; then
|
if [ $r -eq 0 ]; then
|
||||||
echo "Please replace /**-style comments by /// style comments in Rust code."
|
echo "Please replace /**-style comments by /// style comments in Rust code."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
''}";
|
''}";
|
||||||
|
};
|
||||||
|
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
name = "nix-bindings-devshell";
|
||||||
|
strictDeps = true;
|
||||||
|
inputsFrom = [ config.nci.outputs.nix-bindings.devShell ];
|
||||||
|
inherit (config.nci.outputs.nix-bindings.devShell.env)
|
||||||
|
LIBCLANG_PATH
|
||||||
|
NIX_CC_UNWRAPPED
|
||||||
|
;
|
||||||
|
NIX_DEBUG_INFO_DIRS =
|
||||||
|
let
|
||||||
|
# TODO: add to Nixpkgs lib
|
||||||
|
getDebug =
|
||||||
|
pkg:
|
||||||
|
if pkg ? debug then
|
||||||
|
pkg.debug
|
||||||
|
else if pkg ? lib then
|
||||||
|
pkg.lib
|
||||||
|
else
|
||||||
|
pkg;
|
||||||
|
in
|
||||||
|
"${getDebug config.packages.nix}/lib/debug";
|
||||||
|
buildInputs = [
|
||||||
|
config.packages.nix
|
||||||
|
];
|
||||||
|
nativeBuildInputs = [
|
||||||
|
pkgs.rust-analyzer
|
||||||
|
pkgs.nixfmt-rfc-style
|
||||||
|
pkgs.rustfmt
|
||||||
|
pkgs.pkg-config
|
||||||
|
pkgs.clang-tools # clangd
|
||||||
|
pkgs.valgrind
|
||||||
|
pkgs.gdb
|
||||||
|
pkgs.hci
|
||||||
|
# TODO: set up cargo-valgrind in shell and build
|
||||||
|
# currently both this and `cargo install cargo-valgrind`
|
||||||
|
# produce a binary that says ENOENT.
|
||||||
|
# pkgs.cargo-valgrind
|
||||||
|
];
|
||||||
|
shellHook = ''
|
||||||
|
${config.pre-commit.installationScript}
|
||||||
|
source ${../rust/bindgen-gcc.sh}
|
||||||
|
echo 1>&2 "Welcome to the development shell!"
|
||||||
|
'';
|
||||||
|
# rust-analyzer needs a NIX_PATH for some reason
|
||||||
|
NIX_PATH = "nixpkgs=${inputs.nixpkgs}";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
herculesCI =
|
||||||
devShells.default = pkgs.mkShell {
|
hci@{ config, ... }:
|
||||||
name = "nix-bindings-devshell";
|
{
|
||||||
strictDeps = true;
|
ciSystems = [ "x86_64-linux" ];
|
||||||
inputsFrom = [ config.nci.outputs.nix-bindings.devShell ];
|
|
||||||
inherit (config.nci.outputs.nix-bindings.devShell.env)
|
|
||||||
LIBCLANG_PATH
|
|
||||||
NIX_CC_UNWRAPPED
|
|
||||||
;
|
|
||||||
NIX_DEBUG_INFO_DIRS =
|
|
||||||
let
|
|
||||||
# TODO: add to Nixpkgs lib
|
|
||||||
getDebug = pkg:
|
|
||||||
if pkg?debug then pkg.debug
|
|
||||||
else if pkg?lib then pkg.lib
|
|
||||||
else pkg;
|
|
||||||
in
|
|
||||||
"${getDebug config.packages.nix}/lib/debug";
|
|
||||||
buildInputs = [
|
|
||||||
config.packages.nix
|
|
||||||
];
|
|
||||||
nativeBuildInputs = [
|
|
||||||
pkgs.rust-analyzer
|
|
||||||
pkgs.nixfmt-rfc-style
|
|
||||||
pkgs.rustfmt
|
|
||||||
pkgs.pkg-config
|
|
||||||
pkgs.clang-tools # clangd
|
|
||||||
pkgs.valgrind
|
|
||||||
pkgs.gdb
|
|
||||||
pkgs.hci
|
|
||||||
# TODO: set up cargo-valgrind in shell and build
|
|
||||||
# currently both this and `cargo install cargo-valgrind`
|
|
||||||
# produce a binary that says ENOENT.
|
|
||||||
# pkgs.cargo-valgrind
|
|
||||||
];
|
|
||||||
shellHook = ''
|
|
||||||
${config.pre-commit.installationScript}
|
|
||||||
source ${../rust/bindgen-gcc.sh}
|
|
||||||
echo 1>&2 "Welcome to the development shell!"
|
|
||||||
'';
|
|
||||||
# rust-analyzer needs a NIX_PATH for some reason
|
|
||||||
NIX_PATH = "nixpkgs=${inputs.nixpkgs}";
|
|
||||||
};
|
};
|
||||||
};
|
|
||||||
herculesCI = hci@{ config, ... }: {
|
|
||||||
ciSystems = [ "x86_64-linux" ];
|
|
||||||
};
|
|
||||||
flake = { };
|
flake = { };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
36
flake.nix
36
flake.nix
|
|
@ -10,19 +10,36 @@
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = inputs@{ self, flake-parts, ... }:
|
outputs =
|
||||||
flake-parts.lib.mkFlake
|
inputs@{ self, flake-parts, ... }:
|
||||||
{ inherit inputs; }
|
flake-parts.lib.mkFlake { inherit inputs; } (
|
||||||
({ lib, ... }: {
|
{
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
imports = [
|
imports = [
|
||||||
inputs.nix-cargo-integration.flakeModule
|
inputs.nix-cargo-integration.flakeModule
|
||||||
inputs.flake-parts.flakeModules.partitions
|
inputs.flake-parts.flakeModules.partitions
|
||||||
./rust/nci.nix
|
./rust/nci.nix
|
||||||
];
|
];
|
||||||
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
systems = [
|
||||||
perSystem = { config, self', inputs', pkgs, ... }: {
|
"x86_64-linux"
|
||||||
packages.nix = inputs'.nix.packages.nix;
|
"aarch64-linux"
|
||||||
};
|
"x86_64-darwin"
|
||||||
|
"aarch64-darwin"
|
||||||
|
];
|
||||||
|
perSystem =
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
self',
|
||||||
|
inputs',
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
packages.nix = inputs'.nix.packages.nix;
|
||||||
|
};
|
||||||
|
|
||||||
partitionedAttrs.devShells = "dev";
|
partitionedAttrs.devShells = "dev";
|
||||||
partitionedAttrs.checks = "dev";
|
partitionedAttrs.checks = "dev";
|
||||||
|
|
@ -31,5 +48,6 @@
|
||||||
partitions.dev.module = {
|
partitions.dev.module = {
|
||||||
imports = [ ./dev/flake-module.nix ];
|
imports = [ ./dev/flake-module.nix ];
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
132
rust/nci.nix
132
rust/nci.nix
|
|
@ -1,69 +1,83 @@
|
||||||
{
|
{
|
||||||
perSystem = { lib, config, pkgs, ... }: {
|
perSystem =
|
||||||
# https://flake.parts/options/nix-cargo-integration
|
{
|
||||||
nci.projects.nix-bindings = {
|
lib,
|
||||||
path = ./.;
|
config,
|
||||||
drvConfig = {
|
pkgs,
|
||||||
mkDerivation = {
|
...
|
||||||
buildInputs = [
|
}:
|
||||||
# stdbool.h
|
{
|
||||||
pkgs.stdenv.cc
|
# https://flake.parts/options/nix-cargo-integration
|
||||||
] ++
|
nci.projects.nix-bindings = {
|
||||||
(if config.packages.nix?libs
|
path = ./.;
|
||||||
then
|
drvConfig = {
|
||||||
let l = config.packages.nix.libs; in [
|
mkDerivation = {
|
||||||
l.nix-expr-c
|
buildInputs = [
|
||||||
l.nix-store-c
|
# stdbool.h
|
||||||
l.nix-util-c
|
pkgs.stdenv.cc
|
||||||
l.nix-flake-c
|
|
||||||
]
|
]
|
||||||
else [ config.packages.nix ]);
|
++ (
|
||||||
nativeBuildInputs = [
|
if config.packages.nix ? libs then
|
||||||
pkgs.pkg-config
|
let
|
||||||
];
|
l = config.packages.nix.libs;
|
||||||
# bindgen uses clang to generate bindings, but it doesn't know where to
|
in
|
||||||
# find our stdenv cc's headers, so when it's gcc, we need to tell it.
|
[
|
||||||
postConfigure = lib.optionalString pkgs.stdenv.cc.isGNU ''
|
l.nix-expr-c
|
||||||
source ${./bindgen-gcc.sh}
|
l.nix-store-c
|
||||||
'';
|
l.nix-util-c
|
||||||
# Prepare the environment for Nix to work.
|
l.nix-flake-c
|
||||||
# Nix does not provide a suitable environment for running itself in
|
]
|
||||||
# the sandbox - not by default. We configure it to use a relocated store.
|
else
|
||||||
preCheck = ''
|
[ config.packages.nix ]
|
||||||
# nix needs a home directory
|
);
|
||||||
export HOME="$(mktemp -d $TMPDIR/home.XXXXXX)"
|
nativeBuildInputs = [
|
||||||
|
pkgs.pkg-config
|
||||||
|
];
|
||||||
|
# bindgen uses clang to generate bindings, but it doesn't know where to
|
||||||
|
# find our stdenv cc's headers, so when it's gcc, we need to tell it.
|
||||||
|
postConfigure = lib.optionalString pkgs.stdenv.cc.isGNU ''
|
||||||
|
source ${./bindgen-gcc.sh}
|
||||||
|
'';
|
||||||
|
# Prepare the environment for Nix to work.
|
||||||
|
# Nix does not provide a suitable environment for running itself in
|
||||||
|
# the sandbox - not by default. We configure it to use a relocated store.
|
||||||
|
preCheck = ''
|
||||||
|
# nix needs a home directory
|
||||||
|
export HOME="$(mktemp -d $TMPDIR/home.XXXXXX)"
|
||||||
|
|
||||||
# configure a relocated store
|
# configure a relocated store
|
||||||
store_data=$(mktemp -d $TMPDIR/store-data.XXXXXX)
|
store_data=$(mktemp -d $TMPDIR/store-data.XXXXXX)
|
||||||
export NIX_REMOTE="$store_data"
|
export NIX_REMOTE="$store_data"
|
||||||
export NIX_BUILD_HOOK=
|
export NIX_BUILD_HOOK=
|
||||||
export NIX_CONF_DIR=$store_data/etc
|
export NIX_CONF_DIR=$store_data/etc
|
||||||
export NIX_LOCALSTATE_DIR=$store_data/nix/var
|
export NIX_LOCALSTATE_DIR=$store_data/nix/var
|
||||||
export NIX_LOG_DIR=$store_data/nix/var/log/nix
|
export NIX_LOG_DIR=$store_data/nix/var/log/nix
|
||||||
export NIX_STATE_DIR=$store_data/nix/var/nix
|
export NIX_STATE_DIR=$store_data/nix/var/nix
|
||||||
|
|
||||||
echo "Configuring relocated store at $NIX_REMOTE..."
|
echo "Configuring relocated store at $NIX_REMOTE..."
|
||||||
|
|
||||||
# Init ahead of time, because concurrent initialization is flaky
|
# Init ahead of time, because concurrent initialization is flaky
|
||||||
${# Not using nativeBuildInputs because this should (hopefully) be
|
${
|
||||||
# the only place where we need a nix binary. Let's stay in control.
|
# Not using nativeBuildInputs because this should (hopefully) be
|
||||||
pkgs.buildPackages.nix}/bin/nix-store --init
|
# the only place where we need a nix binary. Let's stay in control.
|
||||||
|
pkgs.buildPackages.nix
|
||||||
|
}/bin/nix-store --init
|
||||||
|
|
||||||
echo "Store initialized."
|
echo "Store initialized."
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
# NOTE: duplicated in flake.nix devShell
|
# NOTE: duplicated in flake.nix devShell
|
||||||
env = {
|
env = {
|
||||||
LIBCLANG_PATH =
|
LIBCLANG_PATH = lib.makeLibraryPath [ pkgs.buildPackages.llvmPackages.clang-unwrapped ];
|
||||||
lib.makeLibraryPath [ pkgs.buildPackages.llvmPackages.clang-unwrapped ];
|
BINDGEN_EXTRA_CLANG_ARGS =
|
||||||
BINDGEN_EXTRA_CLANG_ARGS =
|
# Work around missing [[deprecated]] in clang
|
||||||
# Work around missing [[deprecated]] in clang
|
"-x c++ -std=c++2a";
|
||||||
"-x c++ -std=c++2a";
|
}
|
||||||
} // lib.optionalAttrs pkgs.stdenv.cc.isGNU {
|
// lib.optionalAttrs pkgs.stdenv.cc.isGNU {
|
||||||
# Avoid cc wrapper, because we only need to add the compiler/"system" dirs
|
# Avoid cc wrapper, because we only need to add the compiler/"system" dirs
|
||||||
NIX_CC_UNWRAPPED = "${pkgs.stdenv.cc.cc}/bin/gcc";
|
NIX_CC_UNWRAPPED = "${pkgs.stdenv.cc.cc}/bin/gcc";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue