-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
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
nuget-to-nix: Generated file not formatted #358025
Comments
Related discussion at: #325053 |
@corngood any apprehensions about converting the output of About the points you were worried about:
|
I just think it's the wrong way to fix the I think it would be better to just make |
The thing is that we're generating nix code without even needing it, all of our data is completely static and doesn't actually need to be nix, it's pretty much a data file the same way the SDK info files are JSON. The standard for lockfile generation is to use whatever the language uses, or in the absence of it, JSON or YAML afaik. |
I don't see "avoiding formatting" as the reason to choose JSON. I see auto-formatting as the prompt to have this discussion in the first place; but the reason to choose JSON is that it is a more appropriate language. Even if JSON was also going to be auto-formatted, it would still be the better language. However, as things stand now there is little motivation to have data files auto-formatted, so hopefully that's a non-issue. |
I just don't really see what we gain from switching. We'll have to break things and/or deal with compatibility. Performance is a potential benefit, but I haven't benchmarked it, and the only discussion I can find about it is here: https://discourse.nixos.org/t/parser-performance-json-vs-nix/20237/3 |
What we gain is using the right tool for the job, data is not meant to be stored as code. That's my stance on it at least. In practice we don't actually gain anything, but keeping it like this just because of sunken cost while other nixpkgs builders were either correct from the start or have fixed this already feels like we are falling for the sunken cost fallacy. |
I read the discussions on this topic and updated the issue description with some summary of the discussions for people who may land on this issue in the future. |
In #361579 I have a change to run nixfmt by default after nuget-to-nix. i.e.
I know there are objections to that doing that, but to me the most pressing problem is described above:
It's tedious having to dig through the check logs to make sure it's only failing on a deps file. I would still prefer "Exempt generated files from nixfmt-check" as a short term solution, but that doesn't seem to be going anywhere. I'm also not strongly against the idea of "Generate JSON (or alike) instead of Nix", but I don't see a simple way to do it without breaking compatibility, or maintaining some ugly hacks. |
Short term solution
I agree this is a reasonable short term solution. Especially if you don't want to wait for someone to implement json lock files. Anyone with objections should be reassured by it being temporary, while anyone running into CI failures will have an immediate solution. Excluding auto-generated files from formatting
I don't see this as a viable "short-term" solution, since it is higher effort than #361563 and likely no less effort than converting the nuget lock files to json. It's also seemingly unpopular with the formatting team, who consider it an unnecessary complexity. JSON lock files
@SuperSandro2000 seemed ok with this being a breaking change, on the provision that all in-tree lockfiles are updated within a single commit:
Personally I'd prefer to have it be a non-breaking change, to support out-of-tree users, but I appreciate that adds complexity. However, I'm not convinced it needs anything too hacky, especially if we can trust the file extension to indicate whether the lockfile is json or nix. Were you thinking of any specific parts of the implementation, that may end up being ugly? I don't think it should be necessary to have a backwards-compatible updater though? Does the updater even get used out-of-tree? At the most, perhaps auto-removing Proposed backwards-compatibility importingI'm imagining a backwards-compatible import could look like: fetchNuGet: lockfile:
let
# Detect filetype, using filename suffix
isJson = lib.hasSuffix ".json" lockfile;
# Select import vs importJSON
import' = if isJson then lib.importJSON else import;
# Load the data, by applying fetchNuGet
load =
fnOrList:
# Legacy impl: pass fetchNuGet as a fn arg
if builtins.isFunction fnOrList then
fnOrList { inherit fetchNuGet; }
# New impl: map over list, applying fetchNuGet
else builtins.map fetchNuGet fnOrList;
in
load (import' lockfile); |
This is what I was mostly worried about. I've definitely broken people's out-of-tree stuff before with changes to nuget-to-nix, and there have been issues here and there about it. That being said, I'm sure we could make it result in a clear error with a simple fix (change |
I think we could use @MattSturgeon's solution to keep it backwards compatible, since in practice all we'll do is pass every element of the JSON array to We could add a trace/warning of deprecation on the nix file for a while until we eventually remove it in another release. Doing what Matt suggested was my idea initially to avoid any breaking changes in-tree and off-tree. |
Perhaps I assume most of the implementation could be shared or reused, but having the new tool use a different name might make deprecation and migration easier? I guess this still has potential for breaking changes for out-of-tree users of Maybe |
I think we could just rename
I think we instead could add a flag to the script |
One possible approach would be to detect if a With something like This would only cover updating, rather than attempting to create the initial lockfile having declared |
I guess we could do this easily enough with @nugetToJson@/bin/nuget-to-json "${NUGET_PACKAGES%/}" > deps.json
if [ -f "$(dirname "$1")/deps.nix" ]; then
(
echo -e "# This file was automatically generated by passthru.fetch-deps.\n# Please dont edit it manually, your changes might get overwritten!\n"
@nugetToNix@/bin/nuget-to-nix --convert-from deps.json
) > deps.nix
mv deps.nix "$(dirname "$1")/deps.nix"
else
mv deps.json "$1"
fi
That is wrong, we've explicitly made changes so that you can bootstrap a package using |
My mistake, I missed this line when skim-reading:
But my main point was that detecting a sibling file would only work if one already exists; i.e. a Either way, I don't think it's too important for initialising a new package to also support .nix files. If someone tries to use If the |
I'd consider this a non-issue, if someone really needs to initialize their new package with a
I think it does, but can't remember, what I usually do is EDIT: It used to, but we changed it to not error on that so that people can bootstrap it even when the file doesn't exist. |
Ah, well sibling detection would actually work in that scenario. But I agree, new packages are a non-issue. |
Describe the bug
The file generated by nuget-to-nix is not formatted. This leads to an error when a generated file is included in a PR and checked by the nixfmt-check step in GitHub Actions.
Some of the ideas that people proposed:
For details of the pros and cons of those approaches, read the discussions below here and in #325053.
For people who are packaging dotnet applications and meet with nixfmt-check failing: before a long-term solution is decided, temporarily we just merge PR with the check failing anyway (#360598 (comment)). There is no need to run
nixfmt
in the updater script.Notify maintainers
@NixOS/dotnet
Note for maintainers: Please tag this issue in your PR.
Add a 👍 reaction to issues you find important.
The text was updated successfully, but these errors were encountered: