Skip to content
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

lib/generators.nix: broaden toINI usage #46303

Closed
wants to merge 1 commit into from
Closed

Conversation

teto
Copy link
Member

@teto teto commented Sep 7, 2018

Motivation for this change

In home-manager, we generate configurations for different programs, like mbsync with this kind of config

IMAPAccount gmail
CertificateFile "/etc/ssl/certs/ca-certificates.crt"
Host "imap.gmail.com"
SSLType "IMAPS"

or with toml like (like in the MUA alot)

I would like to reuse the toINI function in nixpkgs to generate these config via overriding
mkSectionName and mkKeyValue but overriding mkSectionName doesn't get rid of the [ ] as I would like to to generate the previous example.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

Copy link
Member

@Profpatsch Profpatsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That use case should be completely covered by toKeyValue, no?

@matthewbauer
Copy link
Member

Yeah the brackets are what make it an INI, IIUC.

@teto
Copy link
Member Author

teto commented Sep 8, 2018

The patch doesn't really change the behavior of toINI, it just makes it possible to abuse (=override) mkSectionName to generate non-INI files.

To take the home-manager example, we have this user attribute set:

"IMAPAccount gmail" = {
CertificateFile = "/etc/ssl/certs/ca-certificates.crt"
Host = "imap.gmail.com"
SSLType = "IMAPS"
}

that thanks to this change I can serialize to the string in first post. Maybe it's confusing just for the sake of code reuse but as the change was simple I thought I would try. I can understand if you prefer to close.

@infinisil
Copy link
Member

If you need a different generator, then make a different generator. INI is a specific format, one with these brackets, see https://en.wikipedia.org/wiki/INI_file . This change would even break backwards compatibility:

generators.toINI { mkSectionName = name: "section.${name}"; } { foo.bar = 1; }

currently evaluates to "[section.foo]\nbar=1\n", but with this change would evaluate to "section.foo\nbar=1\n".

@teto teto closed this Sep 8, 2018
@teto teto deleted the toINI branch January 21, 2020 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants