From b550d074fbcd31ac90012596c4d3f5b775dcaddd Mon Sep 17 00:00:00 2001 From: Silmar Date: Mon, 11 Sep 2023 15:50:12 -0300 Subject: [PATCH] zk: add module --- modules/lib/maintainers.nix | 6 +++ modules/misc/news.nix | 7 ++++ modules/modules.nix | 1 + modules/programs/zk.nix | 52 +++++++++++++++++++++++++ tests/default.nix | 1 + tests/modules/programs/zk/default.nix | 1 + tests/modules/programs/zk/expected.toml | 15 +++++++ tests/modules/programs/zk/zk.nix | 30 ++++++++++++++ 8 files changed, 113 insertions(+) create mode 100644 modules/programs/zk.nix create mode 100644 tests/modules/programs/zk/default.nix create mode 100644 tests/modules/programs/zk/expected.toml create mode 100644 tests/modules/programs/zk/zk.nix diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index f3cb3276..f55fa0bf 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -205,6 +205,12 @@ fingerprint = "F0E0 0311 126A CD72 4392 25E6 68BF 2EAE 6D91 CAFF"; }]; }; + silmarp = { + name = "Silmar Pereira da Silva Junior"; + email = "silmarjr2@gmail.com"; + github = "silmarp"; + githubID = 67292496; + }; fendse = { email = "46252070+Fendse@users.noreply.github.com"; github = "Fendse"; diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 4f955e39..8d681658 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1422,6 +1422,13 @@ in { A new module is available: 'wayland.windowManager.river'. ''; } + + { + time = "2024-03-08T22:20:04+00:00"; + message = '' + A new module is available: 'programs.zk' + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 08a539de..16206cc1 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -247,6 +247,7 @@ let ./programs/z-lua.nix ./programs/zathura.nix ./programs/zellij.nix + ./programs/zk.nix ./programs/zoxide.nix ./programs/zplug.nix ./programs/zsh.nix diff --git a/modules/programs/zk.nix b/modules/programs/zk.nix new file mode 100644 index 00000000..d4abfe27 --- /dev/null +++ b/modules/programs/zk.nix @@ -0,0 +1,52 @@ +{ config, lib, pkgs, ... }: + +let + + cfg = config.programs.zk; + tomlFormat = pkgs.formats.toml { }; + +in { + meta.maintainers = [ lib.hm.maintainers.silmarp ]; + + options.programs.zk = { + enable = lib.mkEnableOption "zk"; + + package = lib.mkPackageOption pkgs "zk" { }; + + settings = lib.mkOption { + type = tomlFormat.type; + default = { }; + example = lib.literalExpression '' + { + note = { + language = "en"; + default-title = "Untitled"; + filename = "{{id}}-{{slug title}}"; + extension = "md"; + template = "default.md"; + id-charset = "alphanum"; + id-length = 4; + id-case = "lower"; + }; + extra = { + author = "Mickaël"; + }; + } + ''; + description = '' + Configuration written to {file}`$XDG_CONFIG_HOME/zk/config.toml`. + + See for + available options and documentation. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile."zk/config.toml" = lib.mkIf (cfg.settings != { }) { + source = tomlFormat.generate "config.toml" cfg.settings; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 97fa3fbb..1e14df0c 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -153,6 +153,7 @@ in import nmtSrc { ./modules/programs/wezterm ./modules/programs/yazi ./modules/programs/zellij + ./modules/programs/zk ./modules/programs/zplug ./modules/programs/zsh ./modules/services/syncthing/common diff --git a/tests/modules/programs/zk/default.nix b/tests/modules/programs/zk/default.nix new file mode 100644 index 00000000..5c3288d9 --- /dev/null +++ b/tests/modules/programs/zk/default.nix @@ -0,0 +1 @@ +{ zk = ./zk.nix; } diff --git a/tests/modules/programs/zk/expected.toml b/tests/modules/programs/zk/expected.toml new file mode 100644 index 00000000..688349e8 --- /dev/null +++ b/tests/modules/programs/zk/expected.toml @@ -0,0 +1,15 @@ +[extra] +author = "Mickaël" + +[note] +default-title = "Untitled" +extension = "md" +filename = "{{id}}-{{slug title}}" +id-case = "lower" +id-charset = "alphanum" +id-length = 4 +language = "en" +template = "default.md" + +[notebook] +dir = "~/notebook" diff --git a/tests/modules/programs/zk/zk.nix b/tests/modules/programs/zk/zk.nix new file mode 100644 index 00000000..8907d167 --- /dev/null +++ b/tests/modules/programs/zk/zk.nix @@ -0,0 +1,30 @@ +{ ... }: + +{ + programs.zk = { + enable = true; + settings = { + extra = { author = "Mickaël"; }; + + note = { + default-title = "Untitled"; + extension = "md"; + filename = "{{id}}-{{slug title}}"; + id-case = "lower"; + id-charset = "alphanum"; + id-length = 4; + template = "default.md"; + language = "en"; + }; + + notebook = { dir = "~/notebook"; }; + }; + }; + + test.stubs.zk = { }; + + nmt.script = '' + assertFileExists home-files/.config/zk/config.toml + assertFileContent home-files/.config/zk/config.toml ${./expected.toml} + ''; +}