-
-
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
Open
fk29g
wants to merge
4
commits into
nix-community:master
Choose a base branch
from
fk29g:add-module-sqlite
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+200
−0
Open
sqlite: add module #7981
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| time = "2025-10-12T16:29:08+00:00"; | ||
| condition = true; | ||
| message = '' | ||
| A new module is available: `programs.sqlite`. | ||
| ''; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| { | ||
| lib, | ||
| config, | ||
| pkgs, | ||
| ... | ||
| }: | ||
|
|
||
| let | ||
| cfg = config.programs.sqlite; | ||
| defaultColSeparator = "|"; | ||
| defaultPrompt = "sqlite> "; | ||
| in | ||
| { | ||
| meta.maintainers = [ lib.hm.maintainers.fk29g ]; | ||
|
|
||
| options.programs.sqlite = { | ||
| enable = lib.mkEnableOption "sqlite"; | ||
|
|
||
| package = lib.mkPackageOption pkgs "sqlite-interactive" { | ||
| nullable = true; | ||
| example = [ "sqlite" ]; | ||
| }; | ||
|
|
||
| mode = lib.mkOption { | ||
| type = lib.types.nullOr ( | ||
| lib.types.enum [ | ||
| "ascii" | ||
| "box" | ||
| "column" | ||
| "csv" | ||
| "html" | ||
| "insert" | ||
| "json" | ||
| "line" | ||
| "list" | ||
| "markdown" | ||
| "qbox" | ||
| "quote" | ||
| "table" | ||
| "tabs" | ||
| "tcl" | ||
| ] | ||
| ); | ||
| default = null; | ||
| description = '' | ||
| Output format for query results. | ||
|
|
||
| If set to `null`, SQLite uses "list". | ||
| ''; | ||
| }; | ||
|
|
||
| separator = { | ||
| column = lib.mkOption { | ||
| type = lib.types.nullOr lib.types.str; | ||
| default = null; | ||
| example = " | "; | ||
| description = '' | ||
| Column separator. | ||
|
|
||
| If set to `null`, SQLite uses "${defaultColSeparator}". | ||
| ''; | ||
| }; | ||
|
|
||
| row = lib.mkOption { | ||
| type = lib.types.nullOr lib.types.str; | ||
| default = null; | ||
| example = "\\n\\n"; | ||
| description = '' | ||
| Row separator. | ||
|
|
||
| If set to `null`, SQLite uses "\n". | ||
| ''; | ||
| }; | ||
| }; | ||
|
|
||
| prompt = { | ||
| main = lib.mkOption { | ||
| type = lib.types.nullOr lib.types.str; | ||
| default = null; | ||
| example = "❯ "; | ||
| description = '' | ||
| Main shell prompt. | ||
|
|
||
| If set to `null`, SQLite uses `${defaultPrompt}`. | ||
| ''; | ||
| }; | ||
|
|
||
| continue = lib.mkOption { | ||
| type = lib.types.nullOr lib.types.str; | ||
| default = null; | ||
| description = '' | ||
| Shell prompt for continuing lines of multi-line queries. | ||
|
|
||
| If set to `null`, SQLite uses ` ...> `. | ||
| ''; | ||
| }; | ||
| }; | ||
|
|
||
| extraConfig = lib.mkOption { | ||
| type = lib.types.lines; | ||
| default = ""; | ||
| description = '' | ||
| Extra lines added to {file}`sqliterc`. | ||
| ''; | ||
| }; | ||
| }; | ||
|
|
||
| config = lib.mkIf cfg.enable { | ||
| home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; | ||
|
|
||
| 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)) | ||
| ] | ||
| ); | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .mode box | ||
| .separator " | " "\n\n" | ||
| .prompt "> " "..> " | ||
| .help |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| programs.sqlite = { | ||
| enable = true; | ||
| mode = "box"; | ||
| separator = { | ||
| column = " | "; | ||
| row = "\\n\\n"; | ||
| }; | ||
| prompt = { | ||
| main = "> "; | ||
| continue = "..> "; | ||
| }; | ||
| extraConfig = '' | ||
| .help | ||
| ''; | ||
| }; | ||
|
|
||
| nmt.script = | ||
| let | ||
| configFile = "home-files/.config/sqlite3/sqliterc"; | ||
| in | ||
| '' | ||
| assertFileExists "${configFile}" | ||
| assertFileContent "${configFile}" ${./basic-configuration-expected} | ||
| ''; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| sqlite-basic-configuration = ./basic-configuration.nix; | ||
| sqlite-empty-settings = ./empty-settings.nix; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| programs.sqlite.enable = false; | ||
|
|
||
| nmt.script = '' | ||
| assertPathNotExists home-files/.config/sqlite | ||
| ''; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 valueor 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.