Skip to main content

anodizer_core/config/publishers/
nix.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use super::super::{Amd64Variant, StringOrBool, deserialize_string_or_bool_opt};
5use super::{CommitAuthorConfig, RepositoryConfig};
6
7// ---------------------------------------------------------------------------
8// NixConfig
9// ---------------------------------------------------------------------------
10
11#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
12#[serde(default, deny_unknown_fields)]
13pub struct NixConfig {
14    /// Override the derivation name (default: crate name).
15    pub name: Option<String>,
16    /// Path for the .nix file in the repository (default: `pkgs/<name>/default.nix`).
17    pub path: Option<String>,
18    /// Unified repository config with branch, token, PR, git SSH support.
19    pub repository: Option<RepositoryConfig>,
20    /// Commit author with optional signing.
21    pub commit_author: Option<CommitAuthorConfig>,
22    /// Custom commit message template.
23    pub commit_msg_template: Option<String>,
24    /// Build IDs filter: only include artifacts whose `id` is in this list.
25    pub ids: Option<Vec<String>>,
26    /// Custom URL template for download URLs (overrides release URL).
27    pub url_template: Option<String>,
28    /// Skip publishing. `"true"` always skips; `"auto"` skips for prereleases.
29    /// Accepts bool or template string.
30    #[serde(deserialize_with = "deserialize_string_or_bool_opt", default)]
31    pub skip_upload: Option<StringOrBool>,
32    /// Skip this Nix config. Accepts bool or template string
33    /// (e.g. `"{{ if .IsSnapshot }}true{{ endif }}"` for conditional skip).
34    /// Distinct from `skip_upload` so users can model both intents — disable
35    /// means "don't generate at all", skip_upload means "generate but don't
36    /// push". Without this field, `nix: { skip: true }` was silently
37    /// dropped by the serde unknown-field default.
38    #[serde(deserialize_with = "deserialize_string_or_bool_opt", default)]
39    pub skip: Option<StringOrBool>,
40    /// Custom install commands (replaces auto-generated binary install).
41    pub install: Option<String>,
42    /// Additional install commands appended after the main install.
43    pub extra_install: Option<String>,
44    /// Post-install commands (postInstall phase).
45    pub post_install: Option<String>,
46    /// Short description of the Nix derivation.
47    pub description: Option<String>,
48    /// Project homepage URL.
49    pub homepage: Option<String>,
50    /// License for the derivation's `meta.license`. Accepts a nix
51    /// `lib.licenses` attribute (e.g. `mit`, `asl20`) or an SPDX expression
52    /// (e.g. `MIT`, `Apache-2.0`, `MIT OR Apache-2.0`). A known single id maps
53    /// to `lib.licenses.<attr>`; an `OR`/`AND` list of known ids maps to
54    /// `with lib.licenses; [ … ]`. An unknown id or an unparseable compound
55    /// (e.g. a `WITH` exception) degrades to a quoted-string `license` in
56    /// `meta` — never rejected, never an invalid attr-path. When unset, the
57    /// license is derived from the crate's `Cargo.toml [package].license`.
58    pub license: Option<String>,
59    /// nixpkgs maintainer handles (from `lib.maintainers`) rendered as
60    /// `maintainers = with lib.maintainers; [ alice bob ];` in the
61    /// derivation's `meta`. These are nixpkgs *handles* (e.g. `globin`,
62    /// `zowoq`), NOT `Name <email>` author strings — a nixpkgs review
63    /// rejects a derivation whose `meta.maintainers` is absent. When unset
64    /// the derivation still emits `maintainers = [ ];` (an empty-but-present
65    /// list is valid and clears the "field absent" rejection); a user fills
66    /// in their handle. Each entry is rendered verbatim as a Nix identifier,
67    /// so values must be valid `lib.maintainers` attribute names.
68    pub maintainers: Option<Vec<String>>,
69    /// URL for `meta.changelog`. When unset, anodizer derives
70    /// `<host>/<owner>/<repo>/releases/tag/<tag>` from the crate's `release`
71    /// repository and the release tag (matching what ripgrep/fd set in
72    /// nixpkgs). Set this to override (e.g. a `…/blob/<tag>/CHANGELOG.md`
73    /// URL). Templated. Omitted only when no release repo is configured and
74    /// no explicit value is given.
75    pub changelog: Option<String>,
76    /// Long-form description for `meta.longDescription`, rendered as a
77    /// multi-line `longDescription = '' … '';` block. Optional; omitted when
78    /// unset. Templated.
79    pub long_description: Option<String>,
80    /// Nix package dependencies with optional OS filtering.
81    pub dependencies: Option<Vec<NixDependency>>,
82    /// Nix formatter to run on the generated file: "alejandra" or "nixfmt".
83    pub formatter: Option<String>,
84    /// amd64 microarchitecture variant filter (`v1` / `v2` / `v3` / `v4`).
85    /// Only artifacts matching this variant are included. Default: `v1`.
86    /// Typed as [`Amd64Variant`], so any value outside `v1`..`v4` is
87    /// rejected when the config is parsed.
88    pub amd64_variant: Option<Amd64Variant>,
89    /// Value for `meta.mainProgram` in the generated Nix derivation.
90    /// When set, the rendered derivation includes
91    /// `mainProgram = "<value>";` inside the `meta` block, telling Nix
92    /// which binary `nix run` should execute when the derivation
93    /// contains multiple executables. Templated: supports
94    /// `{{ Version }}` etc. Omitted when unset.
95    pub main_program: Option<String>,
96    /// Override whether this publisher failing should fail the overall release.
97    ///
98    /// Default: `false` — a failure here is logged but does not abort the release.
99    /// Set to `true` to fail the release on any error.
100    #[serde(default, skip_serializing_if = "Option::is_none")]
101    pub required: Option<bool>,
102    /// Template-conditional gate: when the rendered result is falsy
103    /// (`"false"` / `"0"` / `"no"` / empty), the Nix publisher is
104    /// skipped. Render failure hard-errors. Config key: `nix[].if:`.
105    #[serde(rename = "if")]
106    pub if_condition: Option<String>,
107    /// When `true`, a triggered rollback leaves this publisher's work in
108    /// place rather than attempting to undo it. Default `false`.
109    pub retain_on_rollback: Option<bool>,
110}
111
112/// Nix package dependency with optional OS restriction.
113#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
114#[serde(default, deny_unknown_fields)]
115pub struct NixDependency {
116    /// Nix attribute path for the dependency (e.g., "openssl", "pkgs.libgit2").
117    pub name: String,
118    /// OS restriction: "linux", "darwin", or empty for all.
119    pub os: Option<String>,
120}