Skip to content

Commit

Permalink
treewide: nixpkgs-fmt -> nixfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
nikstur committed Sep 6, 2024
1 parent 8143368 commit 82340a6
Show file tree
Hide file tree
Showing 9 changed files with 309 additions and 177 deletions.
25 changes: 18 additions & 7 deletions examples/crane/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@
bombon.inputs.nixpkgs.follows = "nixpkgs";
};

outputs = { self, nixpkgs, crane, flake-utils, bombon, ... }:
flake-utils.lib.eachDefaultSystem (system:
outputs =
{
self,
nixpkgs,
crane,
flake-utils,
bombon,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};

Expand All @@ -33,11 +42,12 @@
];
};

my-crate = bombon.lib.${system}.passthruVendoredSbom.rust
(craneLib.buildPackage (commonArgs // {
my-crate = bombon.lib.${system}.passthruVendoredSbom.rust (craneLib.buildPackage (
commonArgs
// {
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
}))
{ inherit pkgs; };
}
)) { inherit pkgs; };
in
{
checks = {
Expand All @@ -55,5 +65,6 @@
# Inherit inputs from checks.
checks = self.checks.${system};
};
});
}
);
}
7 changes: 6 additions & 1 deletion examples/flakes/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
bombon.inputs.nixpkgs.follows = "nixpkgs";
};

outputs = { self, nixpkgs, bombon }:
outputs =
{
self,
nixpkgs,
bombon,
}:
let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
Expand Down
196 changes: 110 additions & 86 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,99 +21,123 @@

};

outputs = inputs@{ self, flake-parts, systems, ... }: flake-parts.lib.mkFlake { inherit inputs; } {
systems = import systems;

imports =
let
# This is effectively just boilerplate to allow us to keep the `lib`
# output.
libOutputModule = { lib, ... }: flake-parts.lib.mkTransposedPerSystemModule {
name = "lib";
option = lib.mkOption {
type = lib.types.lazyAttrsOf lib.types.anything;
default = { };
};
file = "";
outputs =
inputs@{
self,
flake-parts,
systems,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = import systems;

imports =
let
# This is effectively just boilerplate to allow us to keep the `lib`
# output.
libOutputModule =
{ lib, ... }:
flake-parts.lib.mkTransposedPerSystemModule {
name = "lib";
option = lib.mkOption {
type = lib.types.lazyAttrsOf lib.types.anything;
default = { };
};
file = "";
};
in
[
inputs.pre-commit-hooks-nix.flakeModule
libOutputModule
];

flake = {
templates.default = {
path = builtins.filterSource (path: type: baseNameOf path == "flake.nix") ./examples/flakes;
description = "Build a Bom for GNU hello";
};
in
[
inputs.pre-commit-hooks-nix.flakeModule
libOutputModule
];

flake = {
templates.default = {
path = builtins.filterSource (path: type: baseNameOf path == "flake.nix")
./examples/flakes;
description = "Build a Bom for GNU hello";
};
};

perSystem = { config, system, pkgs, lib, ... }:
let
bombon = import ./. { inherit pkgs; };
inherit (bombon) transformer buildBom passthruVendoredSbom;
in
{
lib = { inherit buildBom passthruVendoredSbom; };

packages = {
# This is mostly here for development
inherit transformer;
default = transformer;
sbom = buildBom transformer { };
};
perSystem =
{
config,
system,
pkgs,
lib,
...
}:
let
bombon = import ./. { inherit pkgs; };
inherit (bombon) transformer buildBom passthruVendoredSbom;
in
{
lib = {
inherit buildBom passthruVendoredSbom;
};

packages = {
# This is mostly here for development
inherit transformer;
default = transformer;
sbom = buildBom transformer { };
};

checks = {
clippy = transformer.overrideAttrs (_: previousAttrs: {
pname = previousAttrs.pname + "-clippy";
nativeCheckInputs = (previousAttrs.nativeCheckInputs or [ ]) ++ [ pkgs.clippy ];
checkPhase = "cargo clippy";
});
rustfmt = transformer.overrideAttrs (_: previousAttrs: {
pname = previousAttrs.pname + "-rustfmt";
nativeCheckInputs = (previousAttrs.nativeCheckInputs or [ ]) ++ [ pkgs.rustfmt ];
checkPhase = "cargo fmt --check";
});
} // import ./nix/tests { inherit pkgs buildBom passthruVendoredSbom; };

pre-commit = {
check.enable = true;

settings = {
hooks = {
nixpkgs-fmt.enable = true;
typos.enable = true;
statix = {
enable = true;
settings.ignore = [ "sources.nix" ];
checks = {
clippy = transformer.overrideAttrs (
_: previousAttrs: {
pname = previousAttrs.pname + "-clippy";
nativeCheckInputs = (previousAttrs.nativeCheckInputs or [ ]) ++ [ pkgs.clippy ];
checkPhase = "cargo clippy";
}
);
rustfmt = transformer.overrideAttrs (
_: previousAttrs: {
pname = previousAttrs.pname + "-rustfmt";
nativeCheckInputs = (previousAttrs.nativeCheckInputs or [ ]) ++ [ pkgs.rustfmt ];
checkPhase = "cargo fmt --check";
}
);
} // import ./nix/tests { inherit pkgs buildBom passthruVendoredSbom; };

pre-commit = {
check.enable = true;

settings = {
hooks = {
nixfmt-rfc-style = {
enable = true;
excludes = [ "sources.nix" ];
};
typos.enable = true;
statix = {
enable = true;
settings.ignore = [ "sources.nix" ];
};
};
};
};
};

devShells.default = pkgs.mkShell {
shellHook = ''
${config.pre-commit.installationScript}
'';

packages = [
pkgs.niv
pkgs.clippy
pkgs.rustfmt
pkgs.cargo-machete
pkgs.cargo-edit
pkgs.cargo-bloat
pkgs.cargo-deny
pkgs.cargo-cyclonedx
];

inputsFrom = [ transformer ];

RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
};
devShells.default = pkgs.mkShell {
shellHook = ''
${config.pre-commit.installationScript}
'';

packages = [
pkgs.niv
pkgs.clippy
pkgs.rustfmt
pkgs.cargo-machete
pkgs.cargo-edit
pkgs.cargo-bloat
pkgs.cargo-deny
pkgs.cargo-cyclonedx
];

inputsFrom = [ transformer ];

RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
};

};
};
};
};
}
20 changes: 11 additions & 9 deletions nix/build-bom.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{ lib
, runCommand
, transformer
, buildtimeDependencies
, runtimeDependencies
{
lib,
runCommand,
transformer,
buildtimeDependencies,
runtimeDependencies,
}:

drv: { extraPaths ? [ ]
, includeBuildtimeDependencies ? false
}:
drv:
{
extraPaths ? [ ],
includeBuildtimeDependencies ? false,
}:

let
flags = lib.optionals includeBuildtimeDependencies [
Expand All @@ -21,4 +24,3 @@ runCommand "${drv.name}.cdx.json" { nativeBuildInputs = [ transformer ]; } ''
${runtimeDependencies drv extraPaths} \
$out
''

Loading

0 comments on commit 82340a6

Please sign in to comment.