git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #167162 from hercules-ci/formats-javaProperties-fixups

Inline docs for javaProperties and formats test runner

commitd990baa309f6c8cc46f07760266e3bdad3fd0301 authorRobert Hensing <roberth@users.noreply.github.com> dateMon 4 Apr 2022, 14:06 (5 years ago) parent0af35dfdcca8f5
2 files changed+29−1
pkgs/pkgs-lib/formats/java-properties/default.nix+24 pkgs/pkgs-lib/tests/formats.nix+5−1
pkgs/pkgs-lib/formats/java-properties/default.nix+24
@@ -1,6 +1,30 @@
11{ lib, pkgs }:
22{
33 javaProperties = { comment ? "Generated with Nix" }: {
4+
5+ # Design note:
6+ # A nested representation of inevitably leads to bad UX:
7+ # 1. keys like "a.b" must be disallowed, or
8+ # the addition of options in a freeformType module
9+ # become breaking changes
10+ # 2. adding a value for "a" after "a"."b" was already
11+ # defined leads to a somewhat hard to understand
12+ # Nix error, because that's not something you can
13+ # do with attrset syntax. Workaround: "a"."", but
14+ # that's too little too late. Another workaround:
15+ # mkMerge [ { a = ...; } { a.b = ...; } ].
16+ #
17+ # Choosing a non-nested representation does mean that
18+ # we sacrifice the ability to override at the (conceptual)
19+ # hierarchical levels, _if_ an application exhibits those.
20+ #
21+ # Some apps just use periods instead of spaces in an odd
22+ # mix of attempted categorization and natural language,
23+ # with no meaningful hierarchy.
24+ #
25+ # We _can_ choose to support hierarchical config files
26+ # via nested attrsets, but the module author should
27+ # make sure that problem (2) does not occur.
428 type = lib.types.attrsOf lib.types.str;
529
630 generate = name: value:
pkgs/pkgs-lib/tests/formats.nix+5−1
@@ -9,7 +9,11 @@ let
99 let
1010 formatSet = format args;
1111 config = formatSet.type.merge [] (imap1 (n: def: {
12− value = def;
12+ # We check the input values, so that
13+ # - we don't write nonsensical tests that will impede progress
14+ # - the test author has a slightly more realistic view of the
15+ # final format during development.
16+ value = lib.throwIfNot (formatSet.type.check def) (builtins.trace def "definition does not pass the type's check function") def;
1317 file = "def${toString n}";
1418 }) [ def ]);
1519 in formatSet.generate "test-format-file" config;