From 1efaa93393d69cc1b595be021221b38a1c9c5afb Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 6 Nov 2023 16:29:44 +0100 Subject: [PATCH 1/4] Include derivation output paths in the JSON we upload to the server --- src/mixed-flake.nix | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/mixed-flake.nix b/src/mixed-flake.nix index b46bfda..624003c 100644 --- a/src/mixed-flake.nix +++ b/src/mixed-flake.nix @@ -68,6 +68,23 @@ forSystems = attrs.forSystems or null; shortDescription = attrs.shortDescription or null; what = attrs.what or null; + derivation = + if attrs ? derivation + then builtins.unsafeDiscardStringContext attrs.derivation.drvPath + else null; + outputs = + if attrs ? derivation + then + builtins.listToAttrs ( + builtins.map (outputName: + { + name = outputName; + value = attrs.derivation.${outputName}.outPath; + } + ) attrs.derivation.outputs + ) + else + null; #evalChecks = attrs.evalChecks or {}; } else From 55b4facc111065cbb71c3f321272a03def5b1a89 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 6 Nov 2023 16:50:07 +0100 Subject: [PATCH 2/4] Make registering store paths optional (disabled by default) This is disabled by default because 1) it might fail (e.g. if the flake uses IFD); and 2) it may be slower (since it requires evaluating the drvPath/outPaths of every flake output). --- action.yaml | 4 ++++ src/cli/mod.rs | 8 +++++++- src/flake_info.rs | 22 +++++++++++++++++----- src/mixed-flake.nix | 43 +++++++++++++++++++++++++------------------ 4 files changed, 53 insertions(+), 24 deletions(-) diff --git a/action.yaml b/action.yaml index 123833a..38bbc97 100644 --- a/action.yaml +++ b/action.yaml @@ -94,6 +94,9 @@ inputs: flakehub-push-url: description: A URL pointing to a `flakehub-push` binary. Overrides all other `flakehub-push-*` options. required: false + include-output-paths: + description: Whether to register the output paths of each flake output with FlakeHub. + required: false # https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-docker-container-actions runs: @@ -119,6 +122,7 @@ runs: FLAKEHUB_PUSH_EXTRA_TAGS: ${{ inputs.extra-tags }} FLAKEHUB_PUSH_SPDX_EXPRESSION: ${{ inputs.spdx-expression }} FLAKEHUB_PUSH_ERROR_ON_CONFLICT: ${{ inputs.error-on-conflict }} + FLAKEHUB_PUSH_INCLUDE_OUTPUT_PATHS: ${{ inputs.include-output-paths }} # Also GITHUB_REPOSITORY, GITHUB_REF_NAME, GITHUB_TOKEN, ACTIONS_ID_TOKEN_REQUEST_TOKEN, ACTIONS_ID_TOKEN_REQUEST_URL run: | if [ "${RUNNER_OS}" == "Linux" ]; then diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 8b1aa9b..60125c0 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -101,6 +101,9 @@ pub(crate) struct FlakeHubPushCli { #[clap(flatten)] pub instrumentation: instrumentation::Instrumentation, + + #[clap(long, env = "FLAKEHUB_PUSH_INCLUDE_OUTPUT_PATHS", value_parser = EmptyBoolParser, default_value_t = false)] + pub(crate) include_output_paths: bool, } #[derive(Clone, Debug)] @@ -275,6 +278,7 @@ impl FlakeHubPushCli { spdx_expression, extra_tags, error_on_conflict, + include_output_paths, } = self; let mut extra_labels: Vec<_> = extra_labels.into_iter().filter(|v| !v.is_empty()).collect(); @@ -457,6 +461,7 @@ impl FlakeHubPushCli { extra_labels, spdx_expression.0, error_on_conflict, + include_output_paths, ) .await?; @@ -493,6 +498,7 @@ async fn push_new_release( extra_labels: Vec, spdx_expression: Option, error_if_release_conflicts: bool, + include_output_paths: bool, ) -> color_eyre::Result<()> { let span = tracing::Span::current(); span.record("upload_name", tracing::field::display(upload_name.clone())); @@ -552,7 +558,7 @@ async fn push_new_release( .pointer("/resolved/dir") .and_then(serde_json::Value::as_str); - let flake_outputs = get_flake_outputs(flake_locked_url).await?; + let flake_outputs = get_flake_outputs(flake_locked_url, include_output_paths).await?; tracing::debug!("Got flake outputs: {:?}", flake_outputs); let source = match flake_metadata_value_resolved_dir { diff --git a/src/flake_info.rs b/src/flake_info.rs index a36729a..b662aa2 100644 --- a/src/flake_info.rs +++ b/src/flake_info.rs @@ -132,16 +132,28 @@ pub(crate) async fn get_flake_metadata(directory: &Path) -> color_eyre::Result color_eyre::Result { +pub(crate) async fn get_flake_outputs( + flake_url: &str, + include_output_paths: bool, +) -> color_eyre::Result { let tempdir = tempfile::Builder::new() .prefix("flakehub_push_outputs") .tempdir() .wrap_err("Creating tempdir")?; - let flake_contents = include_str!("mixed-flake.nix").replace( - FLAKE_URL_PLACEHOLDER_UUID, - &flake_url.escape_default().to_string(), - ); + let flake_contents = include_str!("mixed-flake.nix") + .replace( + FLAKE_URL_PLACEHOLDER_UUID, + &flake_url.escape_default().to_string(), + ) + .replace( + "@INCLUDE_OUTPUT_PATHS@", + if include_output_paths { + "true" + } else { + "false" + }, + ); let mut flake = tokio::fs::File::create(tempdir.path().join("flake.nix")).await?; flake.write_all(flake_contents.as_bytes()).await?; diff --git a/src/mixed-flake.nix b/src/mixed-flake.nix index 624003c..c669d33 100644 --- a/src/mixed-flake.nix +++ b/src/mixed-flake.nix @@ -2,6 +2,8 @@ inputs.flake.url = "c9026fc0-ced9-48e0-aa3c-fc86c4c86df1"; outputs = inputs: { + includeOutputPaths = @INCLUDE_OUTPUT_PATHS@; + contents = let getFlakeOutputs = flake: @@ -68,25 +70,30 @@ forSystems = attrs.forSystems or null; shortDescription = attrs.shortDescription or null; what = attrs.what or null; - derivation = - if attrs ? derivation - then builtins.unsafeDiscardStringContext attrs.derivation.drvPath - else null; - outputs = - if attrs ? derivation - then - builtins.listToAttrs ( - builtins.map (outputName: - { - name = outputName; - value = attrs.derivation.${outputName}.outPath; - } - ) attrs.derivation.outputs - ) - else - null; #evalChecks = attrs.evalChecks or {}; - } + } // ( + if inputs.self.includeOutputPaths then + { + derivation = + if attrs ? derivation + then builtins.unsafeDiscardStringContext attrs.derivation.drvPath + else null; + outputs = + if attrs ? derivation + then + builtins.listToAttrs ( + builtins.map (outputName: + { + name = outputName; + value = attrs.derivation.${outputName}.outPath; + } + ) attrs.derivation.outputs + ) + else + null; + } + else + { }) else { }; in From f741758411169fb6e95facb9b7aad21bafcdf3c5 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 6 Nov 2023 17:02:57 +0100 Subject: [PATCH 3/4] Fix formatting --- src/flake_info.rs | 2 +- src/mixed-flake.nix | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/flake_info.rs b/src/flake_info.rs index b662aa2..bcaf3be 100644 --- a/src/flake_info.rs +++ b/src/flake_info.rs @@ -147,7 +147,7 @@ pub(crate) async fn get_flake_outputs( &flake_url.escape_default().to_string(), ) .replace( - "@INCLUDE_OUTPUT_PATHS@", + "INCLUDE_OUTPUT_PATHS", if include_output_paths { "true" } else { diff --git a/src/mixed-flake.nix b/src/mixed-flake.nix index c669d33..9c3ca73 100644 --- a/src/mixed-flake.nix +++ b/src/mixed-flake.nix @@ -2,7 +2,7 @@ inputs.flake.url = "c9026fc0-ced9-48e0-aa3c-fc86c4c86df1"; outputs = inputs: { - includeOutputPaths = @INCLUDE_OUTPUT_PATHS@; + includeOutputPaths = INCLUDE_OUTPUT_PATHS; contents = let @@ -81,19 +81,23 @@ outputs = if attrs ? derivation then - builtins.listToAttrs ( - builtins.map (outputName: - { - name = outputName; - value = attrs.derivation.${outputName}.outPath; - } - ) attrs.derivation.outputs - ) + builtins.listToAttrs + ( + builtins.map + (outputName: + { + name = outputName; + value = attrs.derivation.${outputName}.outPath; + } + ) + attrs.derivation.outputs + ) else null; } else - { }) + { } + ) else { }; in From e20706fdd48d2b7099ac5eaf576d8ab3941b52c7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 17 Nov 2023 16:06:07 +0100 Subject: [PATCH 4/4] Move include-output-paths --- action.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yaml b/action.yaml index 38bbc97..e1c1691 100644 --- a/action.yaml +++ b/action.yaml @@ -75,6 +75,9 @@ inputs: description: Whether to error if a release for the same version has already been uploaded. required: false default: false + include-output-paths: + description: Whether to register the output paths of each flake output with FlakeHub. + required: false flakehub-push-binary: description: Run a version of the `flakehub-push` binary from somewhere already on disk. Conflicts with all other `flakehub-push-*` options. @@ -94,9 +97,6 @@ inputs: flakehub-push-url: description: A URL pointing to a `flakehub-push` binary. Overrides all other `flakehub-push-*` options. required: false - include-output-paths: - description: Whether to register the output paths of each flake output with FlakeHub. - required: false # https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-docker-container-actions runs: