From 709ab63d5adb0abb9ce00a9629efa4f0db404eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20=C3=98stermark?= Date: Wed, 12 Nov 2025 19:55:42 +0100 Subject: [PATCH 1/3] preserve env var yaml tags for recyclarr config --- nixarr/recyclarr/default.nix | 46 +++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/nixarr/recyclarr/default.nix b/nixarr/recyclarr/default.nix index d65da17..d69fc9a 100644 --- a/nixarr/recyclarr/default.nix +++ b/nixarr/recyclarr/default.nix @@ -8,7 +8,51 @@ with lib; let cfg = config.nixarr.recyclarr; globals = config.util-nixarr.globals; nixarr = config.nixarr; - format = pkgs.formats.yaml {}; + yamlGenerator = {preserved-tags ? []}: let + selectors = + pkgs.lib.strings.concatStringsSep "/" + (builtins.map (x: '' + with((.. | select(kind == "scalar") | select(test("^!${x} .*"))); . = sub("!${x} ", "") | . tag="!${x}") + '')) + preserved-tags; + in { + generate = name: value: + pkgs.callPackage ( + { + runCommand, + yq-go, + }: + runCommand name + { + nativeBuildInputs = [yq-go]; + value = builtins.toJSON value; + passAsFile = ["value"]; + preferLocalBuild = true; + } + '' + yq '${selectors}' "$valuePath" -o yaml > $out + '' + ) {}; + type = let + baseType = pkgs.lib.types.oneOf [ + pkgs.lib.types.bool + pkgs.lib.types.int + pkgs.lib.types.float + pkgs.lib.types.float + (pkgs.lib.types.attrsOf valueType) + (pkgs.lib.types.listOf valueType) + ]; + valueType = + (pkgs.lib.types.nullOr baseType) + // { + description = "Yaml value"; + }; + in + valueType; + }; + format = yamlGenerator { + preserved-tags = ["env_var"]; + }; # Generate configuration file from Nix attribute set if provided generatedConfigFile = format.generate "recyclarr-config.yml" cfg.configuration; From 9a4dc02b2024700e86e9bbf55f904d7ce2045591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20=C3=98stermark?= Date: Wed, 12 Nov 2025 20:10:17 +0100 Subject: [PATCH 2/3] fix minor mistake --- nixarr/recyclarr/default.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nixarr/recyclarr/default.nix b/nixarr/recyclarr/default.nix index d69fc9a..248635c 100644 --- a/nixarr/recyclarr/default.nix +++ b/nixarr/recyclarr/default.nix @@ -11,10 +11,12 @@ with lib; let yamlGenerator = {preserved-tags ? []}: let selectors = pkgs.lib.strings.concatStringsSep "/" - (builtins.map (x: '' - with((.. | select(kind == "scalar") | select(test("^!${x} .*"))); . = sub("!${x} ", "") | . tag="!${x}") - '')) - preserved-tags; + (builtins.map ( + x: '' + with((.. | select(kind == "scalar") | select(test("^!${x} .*"))); . = sub("!${x} ", "") | . tag="!${x}") + '' + ) + preserved-tags); in { generate = name: value: pkgs.callPackage ( From 74307df8e3e78be893e8dd69bc59b5e94fb8b47e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20=C3=98stermark?= Date: Thu, 13 Nov 2025 11:30:23 +0100 Subject: [PATCH 3/3] comments descriping the unreadable yaml generation --- nixarr/recyclarr/default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nixarr/recyclarr/default.nix b/nixarr/recyclarr/default.nix index 248635c..b21372c 100644 --- a/nixarr/recyclarr/default.nix +++ b/nixarr/recyclarr/default.nix @@ -8,10 +8,14 @@ with lib; let cfg = config.nixarr.recyclarr; globals = config.util-nixarr.globals; nixarr = config.nixarr; + # This is a carbon copy of the yaml implementation in nixpkgs https://github.com/NixOS/nixpkgs/blob/fde6c4aec177afa2d0248b1c5983e2a72a231442/pkgs/pkgs-lib/formats.nix#L210-L231 + # except we've replaced json2yaml for yq-go to allow it to parse custom yaml tags + # ideally this would some day be upstreamed, see https://github.com/NixOS/nix/issues/4910 and https://github.com/rasmus-kirk/nixarr/issues/91 yamlGenerator = {preserved-tags ? []}: let selectors = - pkgs.lib.strings.concatStringsSep "/" + pkgs.lib.strings.concatStringsSep "|" (builtins.map ( + # this is yq for "for all the scalers, if they match this regex, do a regex substitution and set the tag" x: '' with((.. | select(kind == "scalar") | select(test("^!${x} .*"))); . = sub("!${x} ", "") | . tag="!${x}") ''