Skip to content

Commit

Permalink
Merge branch 'master' into nixos-module-configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Erin van der Veen authored Apr 16, 2024
2 parents 05c8ebb + 7a4a775 commit c0bbc08
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [#38](https://github.com/tweag/genealogos/pull/38) display nixtract's status information when running
- [#44](https://github.com/tweag/genealogos/pull/44) adds two functions to the `Backend` trait to set options
- [#48](https://github.com/tweag/genealogos/pull/48) [#49](https://github.com/tweag/genealogos/pull/49) added a NixOS module to our flake
- [#50](https://github.com/tweag/genealogos/pull/50) included the frontend in rocket behind the `frontend` feature flag

### Changed
- [#41](https://github.com/tweag/genealogos/pull/41) reworked the Genealogos fronend, paving the way for supporting other bom formats
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</p>

The Genealogos project is a tool that takes output from Nix evaluation tools and produces BOM files.
Currently, it takes input from [nixtract][nixtract] and produces json output compliant with the [CycloneDX][cyclonedx] 1.3 or 1.4 specification.<!-- TODO: 1.5 -->
Currently, it takes input from [nixtract][nixtract-url] and produces json output compliant with the [CycloneDX][cyclonedx-url] 1.3 or 1.4 specification.<!-- TODO: 1.5 -->
Output from Genealogos can be used by various other tools to perform further analysis.

Note Nix is mainly just suitable for Software, and so the BOM output by Genealogos is nearly always an SBOM.
Expand Down Expand Up @@ -142,6 +142,9 @@ Changing this default can be done using the settings button in the top of the we

The Web UI currently only supports analyzing from a flake ref and attribute path, analyzing from a trace file is not yet supported.

The frontend can be opened by opening the `index.html`file in your favourite web browser.
Alternatively, if the `genealogos-api` was built with the `frontend` feature-flag, the frontend can be accessed at the root of wherever the api is hosted (e.g. `http://localhost:8000/`).

### NixOS Module
The flake in this project provides a NixOS Module to host Genealogos.
Once the module has been added to your NixOS configuration, Genealogos can be enabled with:
Expand Down Expand Up @@ -192,6 +195,8 @@ GitHub: [https://github.com/tweag/genealogos](https://github.com/tweag/genealogo
[discord-url]: https://discord.gg/fFymRGGRDG
[tweag-logo]: ./assets/tweag.png
[tweag-url]: https://tweag.io
[nixtract-url]: https://github.com/tweag/nixtract
[cyclonedx-url]: https://cyclonedx.org/

[screenshot]: ./assets/screenshot.png
[genealogos-logo]: ./assets/genealogos.png
5 changes: 5 additions & 0 deletions genealogos-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ urlencoding.workspace = true
pretty_assertions.workspace = true

[features]
default = [ "frontend" ]

# This feature should be enabled when running tests in a Nix environment.
# It disables all tests that require a working internet connection.
nix = []

# Enabling this feature makes Genealogos server a gui frontend at IP:PORT/
frontend = []
21 changes: 20 additions & 1 deletion genealogos-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use genealogos::args::BomArg;
use genealogos::backend::Backend;
use genealogos::bom::Bom;
use rocket::http::Status;
use rocket::response::status;
use rocket::response::{content, status};
use rocket::serde::json::Json;
use rocket::tokio::sync::Mutex;
use rocket::Request;
Expand All @@ -22,6 +22,24 @@ fn handle_errors(req: &Request) -> status::Custom<String> {
)
}

#[rocket::get("/")]
#[cfg(feature = "frontend")]
fn index() -> status::Custom<content::RawHtml<&'static str>> {
status::Custom(
Status::Ok,
content::RawHtml(include_str!("../../genealogos-frontend/index.html")),
)
}

#[rocket::get("/")]
#[cfg(not(feature = "frontend"))]
fn index() -> status::Custom<content::RawHtml<&'static str>> {
status::Custom(
Status::Ok,
content::RawHtml("<h1>Genealogos is running</h1>"),
)
}

#[rocket::get("/analyze?<installable>&<bom_format>")]
fn analyze(installable: &str, bom_format: Option<BomArg>) -> Result<messages::AnalyzeResponse> {
let start_time = std::time::Instant::now();
Expand Down Expand Up @@ -63,6 +81,7 @@ fn rocket() -> _ {
));
})
}))
.mount("/", rocket::routes![index])
.mount("/api", rocket::routes![analyze])
.register("/api", rocket::catchers![handle_errors])
.mount(
Expand Down
5 changes: 3 additions & 2 deletions genealogos-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ use genealogos::backend::{Backend, BackendHandle};
#[command(author, version, about)]
struct Args {
/// Path to the input nixtract file
#[arg(short, long, required_unless_present = "installable")]
#[arg(short, long, required_unless_present = "installable", group = "input")]
file: Option<path::PathBuf>,

/// Nix installable (e.g. `nixpkgs#hello`)
#[arg(required_unless_present = "file")]
#[arg(required_unless_present = "file", group = "input")]
installable: Option<String>,

/// Optional path to the output CycloneDX file (default: stdout)
#[arg(long, short)]
output_file: Option<path::PathBuf>,

/// Backend to use for Nix evaluation tracing
Expand Down
2 changes: 1 addition & 1 deletion genealogos-frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ <h5 class="modal-title">Settings</h5>
// Create a temporary anchor element
const anchor = document.createElement("a");
anchor.href = URL.createObjectURL(blob);
anchor.download = `${installable}.sbom.json`;
anchor.download = `${decodeURIComponent(latestInstallable)}.sbom.json`;

// Programmatically click the anchor element to trigger the download
anchor.click();
Expand Down
10 changes: 8 additions & 2 deletions nix/crane.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
let
common-crane-args = {
pname = "genealogos";
src = crane-lib.cleanCargoSource (crane-lib.path ../.);

# We need to also include the frontend .html file for the include_str macro in the api
src = pkgs.lib.cleanSourceWith {
src = crane-lib.path ../.;
filter = path: type: (crane-lib.filterCargoSources path type) || (builtins.match ".*/genealogos-frontend/index.html" path != null);
};

strictDeps = true;

cargoArtifacts = cargo-artifacts;
Expand Down Expand Up @@ -71,7 +77,7 @@ rec {

packages =
rust-packages // {
default = packages.genealogos;
default = packages.genealogos-cli;

workspace = crane-lib.buildPackage workspace;

Expand Down
4 changes: 2 additions & 2 deletions scripts/update-fixture-output-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ for input_file in ./genealogos/tests/fixtures/nixtract/trace-files/*.in; do
output_file_1_4=${input_file%.in}.1_4.out
# output_file_1_5=${input_file%.in}.1_5.out
echo "Updating: $output_file_1_4"
GENEALOGOS_DETERMINISTIC=1 genealogos --file "$input_file" "$output_file_1_4" --bom cyclonedx_1.4_json
GENEALOGOS_DETERMINISTIC=1 genealogos --file "$input_file" -o "$output_file_1_4" --bom cyclonedx_1.4_json
# TODO: Update to 1.5
# echo "Updating: $output_file_1_5"
# GENEALOGOS_DETERMINISTIC=1 genealogos --file "$input_file" "$output_file_1_5" --cyclonedx-version 1.5
Expand All @@ -21,7 +21,7 @@ for input_file in ./genealogos/tests/fixtures/nixtract/flakes/*.in; do
flake_ref=$(jq -r .flake_ref < "$input_file")
attribute_path=$(jq -r .attribute_path < "$input_file")
echo "Updating: $output_file_1_4"
GENEALOGOS_DETERMINISTIC=1 genealogos --flake-ref "$flake_ref" --attribute-path "$attribute_path" "$output_file_1_4" --bom cyclonedx_1.4_json
GENEALOGOS_DETERMINISTIC=1 genealogos --flake-ref "$flake_ref" --attribute-path "$attribute_path" -o "$output_file_1_4" --bom cyclonedx_1.4_json
# echo "Updating: $output_file_1_5"
# GENEALOGOS_DETERMINISTIC=1 genealogos --flake-ref "$flake_ref" --attribute-path "$attribute_path" "$output_file_1_5" --cyclonedx-version 1.5
done

0 comments on commit c0bbc08

Please sign in to comment.