diff --git a/modules/programs/sheldon.nix b/modules/programs/sheldon.nix new file mode 100644 index 00000000..f1055514 --- /dev/null +++ b/modules/programs/sheldon.nix @@ -0,0 +1,63 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + inherit (lib) + hm + mkEnableOption + mkIf + mkOption + ; + cfg = config.programs.sheldon; + tomlFormat = pkgs.formats.toml { }; +in +{ + meta.maintainers = with hm.maintainers; [ + Kyure-A + mainrs + elanora96 + ]; + + options.programs.sheldon = { + enable = mkEnableOption "sheldon"; + + package = lib.mkPackageOption pkgs "sheldon" { }; + + settings = mkOption { + inherit (tomlFormat) type; + default = { }; + description = ""; + example = lib.literalExpression ""; + }; + + enableZshIntegration = hm.shell.mkZshIntegrationOption { inherit config; }; + + enableBashIntegration = hm.shell.mkBashIntegrationOption { inherit config; }; + + enableFishIntegration = hm.shell.mkFishIntegrationOption { inherit config; }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile."sheldon/plugins.toml" = mkIf (cfg.settings != { }) { + source = tomlFormat.generate "sheldon-config" cfg.settings; + }; + + programs.bash.initExtra = mkIf cfg.enableBashIntegration '' + eval "$(sheldon source)" + ''; + + programs.zsh.initExtra = mkIf cfg.enableZshIntegration '' + eval "$(sheldon source)" + ''; + + programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration '' + eval "$(sheldon source)" + ''; + }; +} diff --git a/tests/modules/programs/sheldon/default.nix b/tests/modules/programs/sheldon/default.nix new file mode 100644 index 00000000..31001ab7 --- /dev/null +++ b/tests/modules/programs/sheldon/default.nix @@ -0,0 +1,25 @@ +{ + config = { + programs.sheldon = { + enable = true; + settings = { + shell = "zsh"; + plugins = { + zsh-syntax-highlighting = { + github = "zsh-users/zsh-syntax-highlighting"; + apply = [ "defer" ]; + }; + }; + templates = { + defer = '' + {{ hooks | get: "pre" | nl }}{% for file in files %}zsh-defer source "{{ file }}" + {% endfor %}{{ hooks | get: "post" | nl }}''; + }; + }; + }; + }; + + test.stubs.sheldon = { }; + + nmt.script = "assertFileContent home-files/.config/sheldon/plugins.toml ${./plugins.toml}"; +} diff --git a/tests/modules/programs/sheldon/plugins.toml b/tests/modules/programs/sheldon/plugins.toml new file mode 100644 index 00000000..f40b27cf --- /dev/null +++ b/tests/modules/programs/sheldon/plugins.toml @@ -0,0 +1,7 @@ +shell = "zsh" +[plugins.zsh-syntax-highlighting] +apply = ["defer"] +github = "zsh-users/zsh-syntax-highlighting" + +[templates] +defer = "{{ hooks | get: \"pre\" | nl }}{% for file in files %}zsh-defer source \"{{ file }}\"\n{% endfor %}{{ hooks | get: \"post\" | nl }}"