-
Notifications
You must be signed in to change notification settings - Fork 354
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
Creating files #142
Creating files #142
Conversation
Questions:
Would better make sure our design is extensible since the number of output formats isn't defined?
If we resolve all other types to On other side, should we change type of |
That's a good point, how can we make the design extensible without sacrificing the simplicity of the user api?
What would reject the config of two files in such case?
For some files you would want to append, for some you would want to override. Not sure. |
🤷
{
files."devcontainer.json".json = { name = "myenv"; };
files."devcontainer.json".ini = { "*" = { end_of_line = "lf"; }; };
} If both resolve to |
@bew once told me that we could add only text option and user does whatever to convert into the text. I don't agree, but is good seen things through a different lens |
Nice! This can really come in handy! I'm interested whether this should be inside enterShell or whether some kind of setup script should be introduced. Mostly because these files are 'conflict-prone'. What should happen upon conflicts? Should it error? Should it warn? Should it silently overwrite? If erroring/warning, should it not load the shell? How can you make sure it reattempts to apply the files? An approach I took on my devenv config is to have a |
I'm favoring of overwriting, as we need to set a single source of truth. Ideally, files should add header banner 'This files was created by X Y Z do not edit it', but isn't always viable (JSON, no comments), Other problem would be updates, we can't diff existing files with previous generation to check if changes are updates or someone edited it directly. Any change would'be a conflict. But we should not add any option that creates files by default, only when enabled. ie: Devenv shouldn't control gitignore file, unless someone configure it to do. #178
The only problem of this is to have files out of sync more often, ie:
In steps above, user forgot to run setup, deploying stage with old conf file. |
My thinking is that conflicts should be resolved at Nix level, if you define two of the same files. Otherwise Nix assumes it's the source of truth what should be the latest version of the declared file: it will override. I'm thinking to split I'm not sure creating files will slow things down that much given that everyone has an SSD these days. But for slower operations we might consider some command to run things manually. |
|
||
let | ||
types = lib.types; | ||
ini = pkgs.formats.ini { }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For editorconfig, you'll need https://github.com/nix-community/nixpkgs.lib/blob/master/lib/generators.nix#L164
I'd say there should be an option to disable auto-creation and provide a command\script which could be used to recreate the files manually. A script which checks that all files are in expected state would also be useful for running checks in CI. |
An idea of how disabling of auto-creation could be implemented: For manual execution we could add |
Personally I think the default should be not to merge as auto-merging could lead to surprising bugs. But we could let users choose with options like (pseudocode): {
options.merge.enable = { type = bool; default = false; };
options.merge.strategy = { type = optionType; default = lines; };
} And then set |
@domenkozar as mentioned on the bottom of this post I believe it would be beneficial to have this implemented in a "platform" agnostic way, so that anyone can re-use this regardless if they use I'm happy to work on this if we can agree on an interface. |
I don't think it's possible for options to depend on the config - that creates an infinity error.
I agree, if we can unite the design goals :) |
Sure! @hugosenari do you have any further comments apart from the feedback you’ve provided here so far? |
e82dccf
to
2cae5ec
Compare
if someone wants to pick this up that would be great! |
Just today I ran into a use-case for this. I'll have a look cherry-picking this PR and bringing it up-to-date 👍 |
I've created #1590 against the latest main. Mostly in line with this PR. Feedback is welcome. |
The idea is that you can create files like:
And running
devenv shell
would print:TODO