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

pkgs-lib: allow paths in TOML, YAML and JSON #103920

Merged
merged 1 commit into from Jun 28, 2021

Conversation

lopsided98
Copy link
Contributor

Motivation for this change

Without this PR, #98025 broke my config because I include a certificate as a path.

Paths to get automatically added to the store, as if they were interpolated. The INI generator currently chokes on paths, so it is not supported for now.

cc @infinisil

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • 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 nixpkgs-review --run "nixpkgs-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)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@stale
Copy link

stale bot commented Jun 4, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 4, 2021
@lopsided98
Copy link
Contributor Author

I'm still using this patch to make my config work.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 21, 2021
@infinisil
Copy link
Member

Looking good, but can you extend the test cases in pkgs/pkgs-lib/tests/formats.nix with this?

Paths get automatically added to the store. The INI generator currently chokes
on paths, so it is not supported for now.
@lopsided98
Copy link
Contributor Author

Ok, done.

@infinisil
Copy link
Member

Nice, thanks!

@infinisil infinisil merged commit 9bd0578 into NixOS:master Jun 28, 2021
@lopsided98 lopsided98 deleted the formats-path branch June 28, 2021 20:22
@puckipedia
Copy link
Contributor

puckipedia commented Sep 3, 2021

I believe this caused a weird conflict in my config:

I have a configuration which uses pkgs.types.yaml, and ends up merging two files like this:

{
   services.foo.config.bar = [ "/var/lib/foo" "/var/lib/bar" ];
  # another file..
   services.foo.config.bar = [ "/var/lib/baz" "/var/lib/quux" ];
}

This breaks due to types.path believing anything that is coercible to a string and starts with a / when coerced is a path. This includes: paths, strings, null, int, float, bool, lists of the previous, or having an outPath or a __toString. This works when there's only one definition (as merge doesn't actually cast the object to a path), but even so, it is quite obvious that a path type is not the right type for the entire option, as it breaks the behavior of lists being mergable.

An easy solution to this is to reorder the entries, to prefer (listOf ...) over path, but that seems a bit fragile.

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

3 participants