Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: switch to nixfmt #323

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 45 additions & 34 deletions checks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
}:
with flake-utils.lib.system;
with nixlib.lib;
with self.lib; let
assertRustOutputs = flake: name:
with self.lib;
let
assertRustOutputs =
flake: name:
assert name != "default";
assert name != "rust";
assert flake ? checks;
Expand All @@ -18,14 +20,14 @@ with self.lib; let
assert flake.overlays ? default;
assert flake.overlays ? fenix;
assert flake.overlays ? rust-overlay;
system:
assert flake.checks.${system} ? clippy;
assert flake.checks.${system} ? fmt;
assert flake.checks.${system} ? nextest;
assert flake.devShells.${system} ? default;
mapAttrs' (n: nameValuePair "${name}-check-${n}") flake.checks.${system}
// mapAttrs' (n: nameValuePair "${name}-shell-${n}") flake.devShells.${system}
// mapAttrs' (n: nameValuePair "${name}-package-${n}") flake.packages.${system};
system:
assert flake.checks.${system} ? clippy;
assert flake.checks.${system} ? fmt;
assert flake.checks.${system} ? nextest;
assert flake.devShells.${system} ? default;
mapAttrs' (n: nameValuePair "${name}-check-${n}") flake.checks.${system}
// mapAttrs' (n: nameValuePair "${name}-shell-${n}") flake.devShells.${system}
// mapAttrs' (n: nameValuePair "${name}-package-${n}") flake.packages.${system};

flakes.rust.complex = (import ../examples/rust-complex/flake.nix).outputs {
nixify = self;
Expand All @@ -47,33 +49,38 @@ with self.lib; let
nixify = self;
};
in
genAttrs [
genAttrs
[
aarch64-darwin
aarch64-linux
x86_64-darwin
x86_64-linux
]
(system: let
isDarwin = system == aarch64-darwin || system == x86_64-darwin;
assertRustPackages = attrs: name: x:
assert attrs.${system} ? "${name}-aarch64-apple-darwin" || !isDarwin;
assert attrs.${system} ? "${name}-aarch64-apple-darwin-oci" || !isDarwin;
assert attrs.${system} ? "${name}-aarch64-unknown-linux-gnu";
assert attrs.${system} ? "${name}-aarch64-unknown-linux-gnu-oci";
assert attrs.${system} ? "${name}-aarch64-unknown-linux-musl";
assert attrs.${system} ? "${name}-aarch64-unknown-linux-musl-oci";
assert attrs.${system} ? "${name}-armv7-unknown-linux-musleabihf";
assert attrs.${system} ? "${name}-armv7-unknown-linux-musleabihf-oci";
assert attrs.${system} ? "${name}-x86_64-apple-darwin" || system != x86_64-darwin;
assert attrs.${system} ? "${name}-x86_64-apple-darwin-oci" || system != x86_64-darwin;
assert attrs.${system} ? "${name}-x86_64-pc-windows-gnu";
assert attrs.${system} ? "${name}-x86_64-pc-windows-gnu-oci";
assert attrs.${system} ? "${name}-x86_64-unknown-linux-gnu";
assert attrs.${system} ? "${name}-x86_64-unknown-linux-gnu-oci";
assert attrs.${system} ? "${name}-x86_64-unknown-linux-musl";
assert attrs.${system} ? "${name}-x86_64-unknown-linux-musl-oci";
assert attrs.${system} ? ${name}; x;
in
(
system:
let
isDarwin = system == aarch64-darwin || system == x86_64-darwin;
assertRustPackages =
attrs: name: x:
assert attrs.${system} ? "${name}-aarch64-apple-darwin" || !isDarwin;
assert attrs.${system} ? "${name}-aarch64-apple-darwin-oci" || !isDarwin;
assert attrs.${system} ? "${name}-aarch64-unknown-linux-gnu";
assert attrs.${system} ? "${name}-aarch64-unknown-linux-gnu-oci";
assert attrs.${system} ? "${name}-aarch64-unknown-linux-musl";
assert attrs.${system} ? "${name}-aarch64-unknown-linux-musl-oci";
assert attrs.${system} ? "${name}-armv7-unknown-linux-musleabihf";
assert attrs.${system} ? "${name}-armv7-unknown-linux-musleabihf-oci";
assert attrs.${system} ? "${name}-x86_64-apple-darwin" || system != x86_64-darwin;
assert attrs.${system} ? "${name}-x86_64-apple-darwin-oci" || system != x86_64-darwin;
assert attrs.${system} ? "${name}-x86_64-pc-windows-gnu";
assert attrs.${system} ? "${name}-x86_64-pc-windows-gnu-oci";
assert attrs.${system} ? "${name}-x86_64-unknown-linux-gnu";
assert attrs.${system} ? "${name}-x86_64-unknown-linux-gnu-oci";
assert attrs.${system} ? "${name}-x86_64-unknown-linux-musl";
assert attrs.${system} ? "${name}-x86_64-unknown-linux-musl-oci";
assert attrs.${system} ? ${name};
x;
in
assert flakes.rust.complex.checks.${system} ? doctest;
assert flakes.rust.complex.packages.${system} ? default;
assert flakes.rust.hello-multibin.packages.${system} ? default;
Expand All @@ -84,9 +91,13 @@ in
assert flakes.rust.lib.packages.${system} ? rust-lib-wasm32-wasip2;
assert flakes.rust.workspace.packages.${system} ? default;
assert flakes.rust.workspace.packages.${system} ? rust-workspace-wasm32-wasip2;
(assertRustPackages flakes.rust.complex.packages "rust-complex")
(assertRustPackages flakes.rust.complex.packages "rust-complex")
(assertRustPackages flakes.rust.hello-multibin.packages "rust-hello-multibin")
(assertRustPackages flakes.rust.hello.packages "rust-hello")
(assertRustPackages flakes.rust.lib.packages "rust-lib")
(assertRustPackages flakes.rust.workspace.packages "rust-workspace")
foldl (checks: example: checks // (assertRustOutputs flakes.rust.${example} "rust-${example}" system)) {} (attrNames flakes.rust))
foldl
(checks: example: checks // (assertRustOutputs flakes.rust.${example} "rust-${example}" system))
{ }
(attrNames flakes.rust)
)
3 changes: 2 additions & 1 deletion examples/rust-complex/flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
inputs.nixify.url = "github:rvolosatovs/nixify";

outputs = {nixify, ...}:
outputs =
{ nixify, ... }:
nixify.lib.rust.mkFlake {
src = ./.;

Expand Down
3 changes: 2 additions & 1 deletion examples/rust-hello-multibin/flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
inputs.nixify.url = "github:rvolosatovs/nixify";

outputs = {nixify, ...}:
outputs =
{ nixify, ... }:
nixify.lib.rust.mkFlake {
src = ./.;
};
Expand Down
3 changes: 2 additions & 1 deletion examples/rust-hello/flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
inputs.nixify.url = "github:rvolosatovs/nixify";

outputs = {nixify, ...}:
outputs =
{ nixify, ... }:
nixify.lib.rust.mkFlake {
src = ./.;
excludePaths = [
Expand Down
3 changes: 2 additions & 1 deletion examples/rust-lib/flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
inputs.nixify.url = "github:rvolosatovs/nixify";

outputs = {nixify, ...}:
outputs =
{ nixify, ... }:
nixify.lib.rust.mkFlake {
src = ./.;
cargoLock = ./Cargo.test.lock;
Expand Down
3 changes: 2 additions & 1 deletion examples/rust-workspace/flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
inputs.nixify.url = "github:rvolosatovs/nixify";

outputs = {nixify, ...}:
outputs =
{ nixify, ... }:
nixify.lib.rust.mkFlake {
src = ./.;
name = "rust-workspace";
Expand Down
56 changes: 29 additions & 27 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,40 @@
inputs.rust-overlay.inputs.nixpkgs.follows = "nixpkgs-nixos";
inputs.rust-overlay.url = "github:oxalica/rust-overlay";

outputs = inputs: let
lib = import ./lib inputs;
in
outputs =
inputs:
let
lib = import ./lib inputs;
in
with lib;
mkFlake {
excludePaths = [
".github"
".gitignore"
"flake.lock"
"flake.nix"
"LICENSE"
"README.md"
];
mkFlake {
excludePaths = [
".github"
".gitignore"
"flake.lock"
"flake.nix"
"LICENSE"
"README.md"
];

withDevShells = {
withDevShells =
{
pkgs,
devShells,
...
}:
extendDerivations {
buildInputs = with pkgs; [
buildah
wasmtime
zig
];
}
devShells;
}
// {
inherit lib;
extendDerivations {
buildInputs = with pkgs; [
buildah
wasmtime
zig
];
} devShells;
}
// {
inherit lib;

checks = import ./checks inputs;
templates = import ./templates inputs;
};
checks = import ./checks inputs;
templates = import ./templates inputs;
};
}
43 changes: 22 additions & 21 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
nixlib,
nix-filter,
...
} @ inputs:
}@inputs:
with flake-utils.lib.system;
with nixlib.lib;
with builtins; let
with builtins;
let
f = self': {
eq = x: y: x == y;

Expand All @@ -16,24 +17,24 @@ with builtins; let

extendDerivations = import ./extendDerivations.nix inputs;

filterSource = {
include ? null,
exclude ? self'.defaultExcludePaths,
src,
}:
nix-filter.lib.filter ({
filterSource =
{
include ? null,
exclude ? self'.defaultExcludePaths,
src,
}:
nix-filter.lib.filter (
{
inherit exclude;
root = src;
}
// optionalAttrs (include != null) {
inherit include;
});
}
);

readTOML = file: fromTOML (readFile file);
readTOMLOr = path: def:
if pathExists path
then self'.readTOML path
else def;
readTOMLOr = path: def: if pathExists path then self'.readTOML path else def;

defaultExcludePaths = [
".codecov.yml"
Expand All @@ -44,7 +45,7 @@ with builtins; let
"flake.nix"
];

defaultNixpkgsConfig = {};
defaultNixpkgsConfig = { };

defaultSystems = [
aarch64-darwin
Expand All @@ -53,12 +54,12 @@ with builtins; let
x86_64-linux
];

defaultWithApps = {apps, ...}: apps;
defaultWithChecks = {checks, ...}: checks;
defaultWithDevShells = {devShells, ...}: devShells;
defaultWithFormatter = {formatter, ...}: formatter;
defaultWithOverlays = {overlays, ...}: overlays;
defaultWithPackages = {packages, ...}: packages;
defaultWithApps = { apps, ... }: apps;
defaultWithChecks = { checks, ... }: checks;
defaultWithDevShells = { devShells, ... }: devShells;
defaultWithFormatter = { formatter, ... }: formatter;
defaultWithOverlays = { overlays, ... }: overlays;
defaultWithPackages = { packages, ... }: packages;
};
in
fix f
fix f
44 changes: 24 additions & 20 deletions lib/extendDerivations.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@
}:
with nixlib.lib;
with builtins;
{
buildInputs ? [],
depsBuildBuild ? [],
env ? null,
inputsFrom ? [],
nativeBuildInputs ? [],
packages ? [],
}:
mapAttrs (n: v:
v.overrideAttrs (attrs:
{
buildInputs = (attrs.buildInputs or []) ++ buildInputs;
depsBuildBuild = (attrs.depsBuildBuild or []) ++ depsBuildBuild;
inputsFrom = (attrs.inputsFrom or []) ++ inputsFrom;
nativeBuildInputs = (attrs.nativeBuildInputs or []) ++ nativeBuildInputs;
packages = (attrs.packages or []) ++ packages;
}
// optionalAttrs (env != null) {
env = (attrs.env or {}) // env;
}))
{
buildInputs ? [ ],
depsBuildBuild ? [ ],
env ? null,
inputsFrom ? [ ],
nativeBuildInputs ? [ ],
packages ? [ ],
}:
mapAttrs (
n: v:
v.overrideAttrs (
attrs:
{
buildInputs = (attrs.buildInputs or [ ]) ++ buildInputs;
depsBuildBuild = (attrs.depsBuildBuild or [ ]) ++ depsBuildBuild;
inputsFrom = (attrs.inputsFrom or [ ]) ++ inputsFrom;
nativeBuildInputs = (attrs.nativeBuildInputs or [ ]) ++ nativeBuildInputs;
packages = (attrs.packages or [ ]) ++ packages;
}
// optionalAttrs (env != null) {
env = (attrs.env or { }) // env;
}
)
)
Loading
Loading