Skip to content

Commit

Permalink
Merge pull request #48 from tweag/nixos-module
Browse files Browse the repository at this point in the history
NixOS module
  • Loading branch information
Erin van der Veen authored Apr 12, 2024
2 parents 5996837 + ac83618 commit 8af8853
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 94 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [#36](https://github.com/tweag/genealogos/pull/36) include nixtract's new narinfo information
- [#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) added a NixOS module to our flake

### Changed
- [#41](https://github.com/tweag/genealogos/pull/41) reworked the Genealogos fronend, paving the way for supporting other bom formats
Expand Down
38 changes: 19 additions & 19 deletions Cargo.lock

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

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ 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.

### 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:

```nix
services.genealogos.enable = true;
```

For further options see `./nix/genealogos-module.nix`.

## Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

Expand Down
91 changes: 16 additions & 75 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,90 +25,31 @@
cyclonedx = pkgs.callPackage ./nix/cyclonedx.nix { };
nixtract-cli = nixtract.defaultPackage.${system};

# Here we start the crane stuff
common-crane-args = {
pname = "genealogos";
src = crane-lib.cleanCargoSource (crane-lib.path ./.);
strictDeps = true;

cargoArtifacts = cargo-artifacts;

# Genealogos uses the reqwest crate to query for narinfo on the substituters.
# reqwest depends on openssl.
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [ openssl ];
};

cargo-artifacts = crane-lib.buildDepsOnly common-crane-args;

workspace = (common-crane-args // {
cargoBuildCommand = "${pkgs.cargo-hack}/bin/cargo-hack hack build --profile release";
cargoTestCommand = "${pkgs.cargo-hack}/bin/cargo-hack hack test --profile release";
});

# Crane buildPackage arguments for every crate
crates = {
genealogos = (common-crane-args // {
cargoExtraArgs = "-p genealogos";
});
genealogos-cli = (common-crane-args // {
pname = "genealogos-cli";
cargoExtraArgs = "-p genealogos-cli";
passthru.exePath = "/bin/genealogos";
});
genealogos-api = (common-crane-args // {
pname = "genealogos-api";
cargoExtraArgs = "-p genealogos-api";
});
crane-outputs = import ./nix/crane.nix {
inherit pkgs crane-lib nixtract-cli cyclonedx;
};
rust-packages =
builtins.mapAttrs (_: crane-lib.buildPackage) crates;
in
rec {
checks =
# Builds
rust-packages
# Clippy
// builtins.mapAttrs
(_: args: crane-lib.cargoClippy (args // {
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}))
crates
# Doc
// builtins.mapAttrs (_: crane-lib.cargoDoc) crates
# fmt
// builtins.mapAttrs (_: crane-lib.cargoFmt) crates;

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

workspace = crane-lib.buildPackage workspace;

update-fixture-output-files = pkgs.writeShellApplication {
name = "update-fixture-output-files";
runtimeInputs = [ (packages.genealogos-cli.overrideAttrs (_: { doCheck = false; })) pkgs.jq ];
text = builtins.readFile ./scripts/update-fixture-output-files.sh;
};
update-fixture-input-files = pkgs.writeShellApplication {
name = "update-fixture-input-files";
runtimeInputs = [ nixtract-cli ];
text = builtins.readFile ./scripts/update-fixture-input-files.sh;
};
verify-fixture-files = pkgs.writeShellApplication {
name = "verify-fixture-files";
runtimeInputs = [ cyclonedx ];
text = builtins.readFile ./scripts/verify-fixture-files.sh;
};
inherit (crane-outputs) checks packages;
overlays.default = import ./nix/overlays.nix {
inherit crane-lib;
};
nixosModules.default = import ./nix/genealogos-module.nix { inherit (crane-outputs.packages) genealogos-api; };
nixosConfigurations.genealogos-test = nixpkgs.lib.nixosSystem
{
inherit system;
modules = [
./nix/configuration.nix
nixosModules.default
];
};

apps.default = utils.lib.mkApp {
drv = packages.genealogos-cli;
drv = crane-outputs.packages.genealogos-cli;
};


devShells.default = crane-lib.devShell {
inherit checks;
inherit (crane-outputs) checks;

packages = with pkgs; [
rust-analyzer
Expand Down
26 changes: 26 additions & 0 deletions nix/configuration.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{ ... }:

{
virtualisation.vmVariant = {
virtualisation = {
memorySize = 2048; # Use 2048MiB memory.
cores = 3;
forwardPorts = [
{
from = "host";
guest.port = 8000;
host.port = 8000;
}
];
};
};

users.users.alice = {
isNormalUser = true;
extraGroups = [ "wheel" ];
password = "genealogos";
};

services.genealogos.enable = true;
}

94 changes: 94 additions & 0 deletions nix/crane.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# This file contains everything related to building our packages with crane.
# It returns a few things; the build packages and the checks
{ pkgs
, crane-lib
, nixtract-cli ? null
, cyclonedx ? null
}:
let
common-crane-args = {
pname = "genealogos";
src = crane-lib.cleanCargoSource (crane-lib.path ../.);
strictDeps = true;

cargoArtifacts = cargo-artifacts;

# Genealogos uses the reqwest crate to query for narinfo on the substituters.
# reqwest depends on openssl.
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [ openssl ];
};

cargo-artifacts = crane-lib.buildDepsOnly common-crane-args;

workspace = (common-crane-args // {
cargoBuildCommand = "${pkgs.cargo-hack}/bin/cargo-hack hack build --profile release";
cargoTestCommand = "${pkgs.cargo-hack}/bin/cargo-hack hack test --profile release";
});

# Crane buildPackage arguments for every crate
crates = {
genealogos = (common-crane-args // {
cargoExtraArgs = "-p genealogos";
});
genealogos-cli = (common-crane-args // {
pname = "genealogos-cli";
cargoExtraArgs = "-p genealogos-cli";
passthru.exePath = "/bin/genealogos";
nativeBuildInputs = common-crane-args.nativeBuildInputs ++ [ pkgs.makeWrapper ];
preFixup = ''
wrapProgram $out/bin/genealogos \
--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.nix ]}
'';
});
genealogos-api = (common-crane-args // {
pname = "genealogos-api";
cargoExtraArgs = "-p genealogos-api";
nativeBuildInputs = common-crane-args.nativeBuildInputs ++ [ pkgs.makeWrapper ];
preFixup = ''
wrapProgram $out/bin/genealogos-api \
--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.nix ]}
'';
});
};
rust-packages =
builtins.mapAttrs (_: crane-lib.buildPackage) crates;
in
rec {
checks =
# Builds
rust-packages
# Clippy
// builtins.mapAttrs
(_: args: crane-lib.cargoClippy (args // {
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}))
crates
# Doc
// builtins.mapAttrs (_: crane-lib.cargoDoc) crates
# fmt
// builtins.mapAttrs (_: crane-lib.cargoFmt) crates;

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

workspace = crane-lib.buildPackage workspace;

update-fixture-output-files = pkgs.writeShellApplication {
name = "update-fixture-output-files";
runtimeInputs = [ (packages.genealogos-cli.overrideAttrs (_: { doCheck = false; })) pkgs.jq ];
text = builtins.readFile ../scripts/update-fixture-output-files.sh;
};
update-fixture-input-files = pkgs.writeShellApplication {
name = "update-fixture-input-files";
runtimeInputs = [ nixtract-cli ];
text = builtins.readFile ../scripts/update-fixture-input-files.sh;
};
verify-fixture-files = pkgs.writeShellApplication {
name = "verify-fixture-files";
runtimeInputs = [ cyclonedx ];
text = builtins.readFile ../scripts/verify-fixture-files.sh;
};
};
}
Loading

0 comments on commit 8af8853

Please sign in to comment.