From afe96e7433c513bf82375d41473c57d1f66b4e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Reynier?= Date: Wed, 2 Feb 2022 09:55:08 +0100 Subject: [PATCH] pubs: add module Note, the pubs configuration file uses ConfigObj syntax, which is similar to the INI files syntax but with extra functionalities like nested sections. This prevents it from using Nix's INI format generator. Here is an example of pubs configuration that cannot be generated using Nix's INI format generator: [plugins] [[git]] manual=False For this reason, we opted for a stringly-typed configuration since the use of a structured `settings` option would require a custom parser. --- .github/CODEOWNERS | 3 + modules/lib/maintainers.nix | 6 ++ modules/misc/news.nix | 7 +++ modules/modules.nix | 1 + modules/programs/pubs.nix | 60 +++++++++++++++++++ tests/default.nix | 1 + tests/modules/programs/pubs/default.nix | 1 + .../pubs-example-settings-expected-pubsrc | 19 ++++++ .../programs/pubs/pubs-example-settings.nix | 36 +++++++++++ 9 files changed, 134 insertions(+) create mode 100644 modules/programs/pubs.nix create mode 100644 tests/modules/programs/pubs/default.nix create mode 100644 tests/modules/programs/pubs/pubs-example-settings-expected-pubsrc create mode 100644 tests/modules/programs/pubs/pubs-example-settings.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index fb7ca984..9ffb82ed 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -201,6 +201,9 @@ /modules/programs/powerline-go.nix @DamienCassou +/modules/programs/pubs.nix @loicreynier +/tests/modules/programs/pubs @loicreynier + /modules/programs/rbw.nix @ambroisie /tests/modules/programs/rbw @ambroisie diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 5789c62a..37486e84 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -83,6 +83,12 @@ github = "kubukoz"; githubId = 894884; }; + loicreynier = { + name = "Loïc Reynier"; + email = "loic@loireynier.fr"; + github = "loicreynier"; + githubId = 88983487; + }; matrss = { name = "Matthias Riße"; email = "matrss@users.noreply.github.com"; diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 6efdcae8..d45b2c32 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -2449,6 +2449,13 @@ in A new module is available: 'programs.just'. ''; } + + { + time = "2022-03-06T09:40:17+00:00"; + message = '' + A new module is available: 'programs.pubs'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 8450fcf6..ff8fd622 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -130,6 +130,7 @@ let ./programs/pidgin.nix ./programs/piston-cli.nix ./programs/powerline-go.nix + ./programs/pubs.nix ./programs/qutebrowser.nix ./programs/rbw.nix ./programs/readline.nix diff --git a/modules/programs/pubs.nix b/modules/programs/pubs.nix new file mode 100644 index 00000000..5a597dea --- /dev/null +++ b/modules/programs/pubs.nix @@ -0,0 +1,60 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.pubs; + +in { + meta.maintainers = [ hm.maintainers.loicreynier ]; + + options.programs.pubs = { + enable = mkEnableOption "pubs"; + + package = mkOption { + type = types.package; + default = pkgs.pubs; + defaultText = literalExpression "pkgs.pubs"; + description = "The package to use for the pubs script."; + }; + + extraConfig = mkOption { + type = types.lines; + default = ""; + example = literalExpression '' + ''' + [main] + pubsdir = ''${config.home.homeDirectory}/.pubs + docsdir = ''${config.home.homeDirectory}/.pubs/doc + doc_add = link + open_cmd = xdg-open + + [plugins] + active = git,alias + + [[alias]] + + [[[la]]] + command = list -a + description = lists papers in lexicographic order + + [[git]] + quiet = True + manual = False + force_color = False + '''''; + description = '' + Configuration using syntax written to + $HOME/.pubsrc. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + home.file.".pubsrc" = + mkIf (cfg.extraConfig != "") { text = cfg.extraConfig; }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 7287bc41..35cbe1d9 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -86,6 +86,7 @@ import nmt { ./modules/programs/pandoc ./modules/programs/pet ./modules/programs/powerline-go + ./modules/programs/pubs ./modules/programs/qutebrowser ./modules/programs/readline ./modules/programs/sagemath diff --git a/tests/modules/programs/pubs/default.nix b/tests/modules/programs/pubs/default.nix new file mode 100644 index 00000000..db68bb11 --- /dev/null +++ b/tests/modules/programs/pubs/default.nix @@ -0,0 +1 @@ +{ pubs-example-settings = ./pubs-example-settings.nix; } diff --git a/tests/modules/programs/pubs/pubs-example-settings-expected-pubsrc b/tests/modules/programs/pubs/pubs-example-settings-expected-pubsrc new file mode 100644 index 00000000..ba1fa88f --- /dev/null +++ b/tests/modules/programs/pubs/pubs-example-settings-expected-pubsrc @@ -0,0 +1,19 @@ +[main] +pubsdir = ~/.pubs +docsdir = ~/.pubs/doc +doc_add = link +open_cmd = xdg-open + +[plugins] +active = git,alias + +[[alias]] + +[[[la]]] +command = list -a +description = lists papers in lexicographic order + +[[git]] +quiet = True +manual = False +force_color = False diff --git a/tests/modules/programs/pubs/pubs-example-settings.nix b/tests/modules/programs/pubs/pubs-example-settings.nix new file mode 100644 index 00000000..59f22800 --- /dev/null +++ b/tests/modules/programs/pubs/pubs-example-settings.nix @@ -0,0 +1,36 @@ +{ config, lib, pkgs, ... }: + +{ + programs.pubs = { + enable = true; + + extraConfig = '' + [main] + pubsdir = ~/.pubs + docsdir = ~/.pubs/doc + doc_add = link + open_cmd = xdg-open + + [plugins] + active = git,alias + + [[alias]] + + [[[la]]] + command = list -a + description = lists papers in lexicographic order + + [[git]] + quiet = True + manual = False + force_color = False + ''; + }; + + test.stubs.pubs = { }; + + nmt.script = '' + assertFileContent \ + home-files/.pubsrc ${./pubs-example-settings-expected-pubsrc} + ''; +}