Skip to content

Commit

Permalink
Merge pull request #130 from nikstur/housekeeping
Browse files Browse the repository at this point in the history
Housekeeping
  • Loading branch information
nikstur committed Sep 6, 2024
2 parents a3c38ce + 82340a6 commit 1df4bd1
Show file tree
Hide file tree
Showing 12 changed files with 344 additions and 238 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
33 changes: 6 additions & 27 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

201 changes: 110 additions & 91 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@

systems.url = "github:nix-systems/default";

flake-utils = {
url = "github:numtide/flake-utils";
inputs.systems.follows = "systems";
};

flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
Expand All @@ -26,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;
};

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" ];
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 = {
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 1df4bd1

Please sign in to comment.