Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add package list metadata to Terraform build output via nvd #460

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

oneingan
Copy link

@oneingan oneingan commented Feb 5, 2025

Changes

This PR enhances the Nix build script to:

  1. Run nvd list on the derivation output to collect installed packages.
  2. Format the package list as a JSON-compatible string for Terraform compatibility.
  3. Return a flat JSON object with out (build path) and packages (serialized JSON array).

Example Output:

{
  "out": "/nix/store/...-nixos-system",
  "packages": "[{\"name\":\"acl\",\"versions\":\"2.3.2 x2\"},...]"
}

Notes

  • Requires nvd installed, but if not returns an empty list
  • Maintains backward compatibility – existing users see no breaking changes.

@oneingan oneingan changed the title feat: Add package list metadata to build output via nvd feat: Add package list metadata to Terraform build output via nvd Feb 5, 2025
@@ -39,5 +39,20 @@ else
# inject `special_args` into nixos config's `specialArgs`
# shellcheck disable=SC2086
out=$(nix build --no-link --json ${options} --expr "${nix_expr}" "${config_attribute}")
output_path=$(echo "$out" | jq -r '.[].outputs.out')
packages_json=$(nvd list --selected --root "$output_path" | awk '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add some conditional if nvd is not present?

if command -v nvd; then
fi

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we don't enable pipefail but I think we should

@@ -1,6 +1,7 @@
resource "null_resource" "nixos-rebuild" {
triggers = {
store_path = var.nixos_system
packages_list = var.nixos_system_packages
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not quite getting, why we need this trigger? Is the store_path not enough?

Copy link
Author

@oneingan oneingan Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken, you need it for package_list diff to be displayed during the plan, though I could be wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Actually the terraform option description is a bit misleading in this case, which was also the initial source of my confusion. Could you change that and also add to nixos-rebuild.md how to wire things up i.e. use nix-build output and feed it into the nixos-rebuild module?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants