Skip to content

Commit

Permalink
Merge pull request #118 from nikstur/keep-overridability
Browse files Browse the repository at this point in the history
passthru-vendored: keep overridability of orginal drv
  • Loading branch information
nikstur authored Jul 16, 2024
2 parents 21d203a + ceea115 commit 35ce4ed
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ You can use the `passthruVendoredSbom.rust` function to add the
`bombonVendoredSbom` passthru derivation to a Rust package:

```nix
myPackageWithSbom = pkgs.callPackage (bombon.passthruVendoredSbom.rust myPackage) { };
myPackageWithSbom = bombon.passthruVendoredSbom.rust myPackage { inherit pkgs; };
```

Or using Flakes:

```nix
myPackageWithSbom = pkgs.callPackage (bombon.lib.${system}.passthruVendoredSbom.rust myPackage) { };
myPackageWithSbom = bombon.lib.${system}.passthruVendoredSbom.rust myPackage { inherit pkgs; };
```

An SBOM built from this new derivation will now include the vendored dependencies.
Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rec {
runtimeDependencies = pkgs.callPackage ./nix/runtime-dependencies.nix { };
};

transformer = pkgs.callPackage (passthruVendoredSbom.rust transformerWithoutSbom) { };
transformer = passthruVendoredSbom.rust transformerWithoutSbom { inherit pkgs; };

buildBom = pkgs.callPackage ./nix/build-bom.nix {
inherit transformer;
Expand Down
15 changes: 6 additions & 9 deletions examples/crane/flake.lock

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

4 changes: 2 additions & 2 deletions examples/crane/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "Build a cargo project without extra checks";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

crane = {
url = "github:ipetkov/crane";
Expand Down Expand Up @@ -37,7 +37,7 @@
(craneLib.buildPackage (commonArgs // {
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
}))
{ inherit (pkgs) cargo-cyclonedx; };
{ inherit pkgs; };
in
{
checks = {
Expand Down
10 changes: 5 additions & 5 deletions nix/passthru-vendored.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
# This could be done much more elegantly if `buildRustPackage` supported
# finalAttrs. When https://github.com/NixOS/nixpkgs/pull/194475 lands, we can
# most likely get rid of this.
rust = package: { cargo-cyclonedx, lib, stdenv }: package.overrideAttrs
rust = package: { pkgs }: package.overrideAttrs
(previousAttrs: {
passthru = (previousAttrs.passthru or { }) // {
bombonVendoredSbom = package.overrideAttrs (previousAttrs: {
nativeBuildInputs = (previousAttrs.nativeBuildInputs or [ ]) ++ [ cargo-cyclonedx ];
nativeBuildInputs = (previousAttrs.nativeBuildInputs or [ ]) ++ [ pkgs.cargo-cyclonedx ];
outputs = [ "out" ];
phases = [ "unpackPhase" "patchPhase" "configurePhase" "buildPhase" "installPhase" ];
buildPhase = ''
cargo cyclonedx --spec-version 1.4 --format json --target ${stdenv.hostPlatform.rust.rustcTarget}
cargo cyclonedx --spec-version 1.4 --format json --target ${pkgs.stdenv.hostPlatform.rust.rustcTarget}
''
+ lib.optionalString
+ pkgs.lib.optionalString
(builtins.hasAttr "buildNoDefaultFeatures" previousAttrs)
" --no-default-features"
+ lib.optionalString
+ pkgs.lib.optionalString
(builtins.hasAttr "buildFeatures" previousAttrs)
(" --features " + builtins.concatStringsSep "," previousAttrs.buildFeatures)
;
Expand Down
2 changes: 1 addition & 1 deletion nix/tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}:

let
rustPassthru = pkg: pkgs.callPackage (passthruVendoredSbom.rust pkg) { };
rustPassthru = pkg: passthruVendoredSbom.rust pkg { inherit pkgs; };

buildtimeOptions = { includeBuildtimeDependencies = true; };

Expand Down

0 comments on commit 35ce4ed

Please sign in to comment.