NixOS / nixpkgs

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

`pkgs.formats.hocon` emits `include` statements without a new-line #329448

Open wucke13 opened 1 month ago

wucke13 commented 1 month ago

Describe the bug

When combining _include with normal attributes (which is valid in hocon), then the resulting hocon file is not parseable by scala's hocon parser.

Steps To Reproduce

Welcome to Nix 2.18.2. Type :? for help.

nix-repl> :lf nixpkgs/nixos-unstable
Added 15 variables.

nix-repl> hocon = legacyPackages.x86_64-linux.formats.hocon { }

nix-repl> :b hocon.generate "test" { _includes = [(hocon.lib.mkInclude "my_include")]; other_attr = 13; }

This derivation produced the following outputs:
  out -> /nix/store/nv0brxny5qk9wjd5z6781hx8fj4g6r36-test

where /nix/store/nv0brxny5qk9wjd5z6781hx8fj4g6r36-test looks like this:

{
  include "my_include""other_attr" = 13
}

Expected behavior

{
  include "my_include"
  "other_attr" = 13
}

Additional context

I'm trying to extend this config file with custom values coming from a module, by generating something akin this:

include "application.conf"
play.http.server.port=80

Notify maintainers

@h7x4

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.31, NixOS, 24.05 (Uakari), 24.05.20240524.d12251e`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.2`
 - channels(root): `""`
 - nixpkgs: `/etc/nix/inputs/nixpkgs`

Add a :+1: reaction to issues you find important.

h7x4 commented 1 month ago

I think this is a result of trying to make the generator output as minified output as allowed by the java hocon spec. But if it's not parsable by scala, then I support fixing it up.

wucke13 commented 1 month ago

If minified is a goal, one could also omit the outer most braces btw.