diff --git a/modules/programs/andcli.nix b/modules/programs/andcli.nix new file mode 100644 index 000000000..e0a34f27f --- /dev/null +++ b/modules/programs/andcli.nix @@ -0,0 +1,53 @@ +{ + lib, + pkgs, + config, + ... +}: +let + inherit (lib) + mkIf + mkEnableOption + mkPackageOption + mkOption + ; + + cfg = config.programs.andcli; + yamlFormat = pkgs.formats.yaml { }; +in +{ + meta.maintainers = with lib.hm.maintainers; [ aguirre-matteo ]; + options.programs.andcli = { + enable = mkEnableOption "andcli"; + package = mkPackageOption pkgs "andcli" { nullable = true; }; + settings = mkOption { + inherit (yamlFormat) type; + default = { }; + example = { + options = { + show_usernames = false; + show_tokens = true; + }; + }; + description = '' + Configuration settings for andcli. All the details can be found here: + + ''; + }; + }; + + config = + let + configPath = + if pkgs.stdenv.hostPlatform.isDarwin then + "Library/Application Support/andcli" + else + "${lib.removePrefix config.home.homeDirectory config.xdg.configHome}/andcli"; + in + mkIf cfg.enable { + home.packages = mkIf (cfg.package != null) [ cfg.package ]; + home.file."${configPath}/config.yaml" = mkIf (cfg.settings != { }) { + source = yamlFormat.generate "andcli-config.yaml" cfg.settings; + }; + }; +} diff --git a/tests/modules/programs/andcli/config.yaml b/tests/modules/programs/andcli/config.yaml new file mode 100644 index 000000000..7ed466fcc --- /dev/null +++ b/tests/modules/programs/andcli/config.yaml @@ -0,0 +1,3 @@ +options: + show_tokens: true + show_usernames: false diff --git a/tests/modules/programs/andcli/default.nix b/tests/modules/programs/andcli/default.nix new file mode 100644 index 000000000..f8704f34c --- /dev/null +++ b/tests/modules/programs/andcli/default.nix @@ -0,0 +1 @@ +{ andcli-settings = ./settings.nix; } diff --git a/tests/modules/programs/andcli/settings.nix b/tests/modules/programs/andcli/settings.nix new file mode 100644 index 000000000..a057d9872 --- /dev/null +++ b/tests/modules/programs/andcli/settings.nix @@ -0,0 +1,32 @@ +{ + lib, + pkgs, + config, + ... +}: + +{ + programs.andcli = { + enable = true; + settings = { + options = { + show_usernames = false; + show_tokens = true; + }; + }; + }; + + nmt.script = + let + configPath = + if pkgs.stdenv.hostPlatform.isDarwin then + "Library/Application Support/andcli" + else + "${lib.removePrefix config.home.homeDirectory config.xdg.configHome}/andcli"; + in + '' + assertFileExists "home-files/${configPath}/config.yaml" + assertFileContent "home-files/${configPath}/config.yaml" \ + ${./config.yaml} + ''; +}