NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.3k stars 13.54k forks source link

nixos: modules using type = pkgs.formats.<foo> have odd type descriptions #199863

Open bjornfor opened 1 year ago

bjornfor commented 1 year ago

Describe the bug

Here, an example from man configuration.nix:

       services.adguardhome.settings
           [...]
           Type: YAML value

           Default: { }

Looking at Type: YAML value above, I'd expect to pass a string, but it really does take a Nix attrset (which then gets converted to YAML internally).

Expected behavior

I guess I'd like for the type documentation to say it's a Nix value of some sort. Maybe Nix value, internally converted to <type>?

sjau commented 1 year ago

Can you give me an example of what you're supposed to enter there? I'd like to provide:

users:
  - name: myUser
    password: $myPasswordHash

but I can't figure it out. I tried:

        settings = {
            users = {
                name = "myUser";
                password = "$myPasswordHash";
            };

but it did not like that.

bjornfor commented 1 year ago

@sjau: The dash indicates a list element, and your Nix value is an attrset. Try this:

settings = {
  users = [
    { name = "myUser"; password = "pass"; }
  ];
};

Useful for playing around with Nix/YAML conversion:

$ cat $(nix-build -E '((import <nixpkgs> {}).formats.yaml {}).generate "foo" { users = [ { name = "myUser"; password = "pass"; } ]; }')
users:
- name: myUser
  password: pass
wesley800 commented 1 year ago

To be more specific, services.adguardhome.settings actually compiles to JSON rather than YAML, which adds to the confusion of the type annotation.

sjau commented 1 year ago

@sjau: The dash indicates a list element, and your Nix value is an attrset. Try this:

Yeah, this works, just used:

        settings = {
            bind_port = 3000;
            users = [ {
                name = "myUser";
                password = "$myHashedPassword";
            } ];
        };
eclairevoyant commented 3 months ago

actually compiles to JSON rather than YAML

JSON is YAML :)

wesley800 commented 3 months ago

JSON is YAML :)

Exactly. The only difference is that it makes the document, module code and user configuration show three seperate format, to one's first glance.