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
pkgs-lib/formats: support top level INI keys #118925
Conversation
lib/generators: support top level keys in toINI Many packages using INI as their configuration format allow top-level keys that don't belong to a section before the first section, for example gmnisrv and foot. However lib.generators.toINI and pkgs.formats.ini don't support this currently. This commit introduces support for this. All keys in the attribute set passed are considered as top-level entries if they are not attribute sets (that is don't represent a section). Introducing a switch for turning this behavior on or off doesn't seem necessary as there is no valid representation for such values in the input attribute set for the use case without top-level attributes. Now such things are possible: ```nix lib.generators.toINI {} { foo = 13; bar = { baz = 12; hello = "world"; }; } == '' foo=13 [bar] baz=12 hello=world '' ``` Thanks to Ben Sima for cleaning up and porting a snippet I had for proper nixpkgs! Co-authored-by: Ben Sima <ben@bsima.me>
See the discussion in #107491 |
Oh yeah, that hadn't crossed my mind yet. Pretty unfortunate. Under the assumptions that a) we can check beforehand if such a collision could occur (in the service's documentation) and b) in practice these collisions are somewhat rare, I would propose the following solution: We make it configurable to turn this feature on and off and add the option to bind it to a special section (whose name is configurable) instead in case there may be collisions. By default, this would be turned off. This would ensure that:
The downside of this is of course that it would have an unusual interface for users in case the global section is named instead of top-level due to possible collisions. Essentially we would choose convenience (in a lot of cases) over consistency (with a few cases). What do you think? I'm happy to implement either solution pretty much. |
Hm, a lot of fancy encodings have been proposed, but I kinda didn’t see the most obvious one: Add a
|
That proposal isn't confusing 👍 Most others have been confusing. |
I marked this as stale due to inactivity. → More info |
As discussed in NixOS#118925 (comment), this is the best way of adding global sections to `toINI` without employing heuristics (i.e. checking whether something is an attrset).
As discussed in NixOS/nixpkgs#118925 (comment), this is the best way of adding global sections to `toINI` without employing heuristics (i.e. checking whether something is an attrset).
As discussed in NixOS/nixpkgs#118925 (comment), this is the best way of adding global sections to `toINI` without employing heuristics (i.e. checking whether something is an attrset).
See #164088, although it still lacks a pkgs-lib |
@sternenseemann I attempted a |
As discussed in NixOS/nixpkgs#118925 (comment), this is the best way of adding global sections to `toINI` without employing heuristics (i.e. checking whether something is an attrset).
As discussed in NixOS/nixpkgs#118925 (comment), this is the best way of adding global sections to `toINI` without employing heuristics (i.e. checking whether something is an attrset).
lib/generators: support top level keys in toINI
Many packages using INI as their configuration format allow top-level
keys that don't belong to a section before the first section, for
example gmnisrv and foot. However lib.generators.toINI and
pkgs.formats.ini don't support this currently. This commit introduces
support for this.
All keys in the attribute set passed are considered as top-level entries
if they are not attribute sets (that is don't represent a section).
Introducing a switch for turning this behavior on or off doesn't seem
necessary as there is no valid representation for such values in the
input attribute set for the use case without top-level attributes.
Now such things are possible:
Thanks to Ben Sima for cleaning up and porting a snippet I had for
proper nixpkgs!
Motivation for this change
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)