-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
sqlite: add module #7981
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
base: master
Are you sure you want to change the base?
sqlite: add module #7981
Conversation
|
Can you squash/fixup the last 2 commits into their relevant commit |
b57e7eb to
46835a4
Compare
| xdg.configFile."sqlite3/sqliterc".text = lib.concatStringsSep "\n" ( | ||
| lib.filter (x: x != "") [ | ||
| (lib.optionalString (cfg.mode != null) ".mode ${cfg.mode}") | ||
| (lib.optionalString ( | ||
| cfg.separator.column != null && cfg.separator.row != null | ||
| ) ".separator \"${cfg.separator.column}\" \"${cfg.separator.row}\"") | ||
| (lib.optionalString ( | ||
| cfg.separator.column != null && cfg.separator.row == null | ||
| ) ".separator \"${cfg.separator.column}\"") | ||
| (lib.optionalString ( | ||
| cfg.separator.column == null && cfg.separator.row != null | ||
| ) ".separator \"${defaultColSeparator}\" \"${cfg.separator.row}\"") | ||
| (lib.optionalString ( | ||
| cfg.prompt.main != null && cfg.prompt.continue != null | ||
| ) ".prompt \"${cfg.prompt.main}\" \"${cfg.prompt.continue}\"") | ||
| (lib.optionalString ( | ||
| cfg.prompt.main != null && cfg.prompt.continue == null | ||
| ) ".prompt \"${cfg.prompt.main}\"") | ||
| (lib.optionalString ( | ||
| cfg.prompt.main == null && cfg.prompt.continue != null | ||
| ) ".prompt \"${defaultPrompt}\" \"${cfg.prompt.continue}\"") | ||
| (lib.optionalString (cfg.extraConfig != "") (cfg.extraConfig)) | ||
| ] | ||
| ); |
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.
I worry about this being too restrictive and also dismissive of configuration. This contains a lot of conditional logic when it seems like the file is a basic syntax of .<option> key value or something? Maybe we can make/use a generator that allows more freeform configuration?
If not interested in a generator, I think it'd make more sense to create warnings/assertions when combining mutually exclusive options instead of just silently choosing which to apply.
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.
In any case, it should probably have an escape hatch of some sort. This is not a fancy looking declarative configuration, it's just a script that gets run upon running sqlite. It can include arbitrary SQL in addition to the . commands. It's pretty common to use it to enable foreign key constraints for example.
|
I worry about this being too restrictive and also dismissive of
configuration. This contains a lot of conditional logic
Yeah, I don't really like this part as well. It's just the best I could
come up with with my limited knowledge of the language as I'm still
quite new to nix.
when it seems like the file is a basic syntax of `.<option> key value`
or something?
That's the thing, `sqliterc` is basically just a list of commands to
automatically run when entering a sqlite shell. Specifically, the
separator syntax looks like this:
`.separator <col> <row>` where <col> and <row> are strings
Meaning, to change just the row separator, you'd still need to give a
column separator too, even if you wanted to keep the default one. Same
for the prompt.
I think it'd make more sense to create warnings/assertions when
combining mutually exclusive options instead of just silently choosing
which to apply.
Not sure which mutually exclusive options you're referring to. I don't
think there are any. The awkward conditionals are there because of what
I explained in the previous paragraph.
There's probably a cleaner way to handle this, though. Writing a
generator might be helpful, but I'm not sure where to start looking to
learn how to write one.
|
modules/programs/sqlite.nix
Outdated
| options.programs.sqlite = { | ||
| enable = lib.mkEnableOption "sqlite"; | ||
|
|
||
| package = lib.mkPackageOption pkgs "sqlite" { nullable = true; }; |
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.
Assuming this is intended for interactive use?
| package = lib.mkPackageOption pkgs "sqlite" { nullable = true; }; | |
| package = lib.mkPackageOption pkgs "sqlite-interactive" { | |
| nullable = true; | |
| example = [ "sqlite" ]; | |
| }; |
Add tests for an empty and decently realistic example configuration.
|
Assuming this is intended for interactive use?
It is, yeah. Thanks for the suggestion.
|
46835a4 to
3878dd8
Compare
|
In any case, it should probably have an escape hatch of some sort.
Doesn't it already have that via the `extraConfig` option?
|
Description
Adds a module for configuring SQLite.
Checklist
Change is backwards compatible.
Code formatted with
nix fmtornix-shell -p treefmt nixfmt deadnix keep-sorted --run treefmt.Code tested through
nix run .#tests -- test-allornix-shell --pure tests -A run.all.Test cases updated/added. See example.
Commit messages are formatted like
See CONTRIBUTING for more information and recent commit messages for examples.
If this PR adds a new module