diff --git a/modules/programs/aliae.nix b/modules/programs/aliae.nix index ba351b243..42450bf3d 100644 --- a/modules/programs/aliae.nix +++ b/modules/programs/aliae.nix @@ -6,6 +6,7 @@ }: let inherit (lib) + types mkIf mkEnableOption mkPackageOption @@ -31,6 +32,19 @@ in enableZshIntegration = mkZshIntegrationOption { inherit config; }; enableFishIntegration = mkFishIntegrationOption { inherit config; }; enableNushellIntegration = mkNushellIntegrationOption { inherit config; }; + configLocation = mkOption { + type = types.str; + default = "${config.home.homeDirectory}/.aliae.yaml"; + defaultText = lib.literalExpression "\${config.home.homeDirectory}/.aliae.yaml"; + example = "/Users/aliae/configs/aliae.yaml"; + description = '' + Path where aliae should look for its config file. This doesn't override + where Home-Manager places the generated config file. Changing this option + could prevent aliae from using the settings defined in your Home-Manager + configuration. + ''; + }; + settings = mkOption { inherit (yamlFormat) type; default = { }; @@ -62,10 +76,23 @@ in }; config = mkIf cfg.enable { + assertions = [ + { + assertion = + (cfg.settings != { } && cfg.configLocation != null) + -> lib.hasPrefix config.home.homeDirectory cfg.configLocation; + message = "The option `programs.aliae.configLocation` must point to a file inside user's home directory when `programs.aliae.settings` is set."; + } + ]; + home.packages = mkIf (cfg.package != null) [ cfg.package ]; - home.file.".aliae.yaml" = mkIf (cfg.settings != { }) { - source = yamlFormat.generate "aliae.yaml" cfg.settings; - }; + home.sessionVariables = mkIf (cfg.configLocation != null) { ALIAE_CONFIG = cfg.configLocation; }; + home.file."${lib.removePrefix config.home.homeDirectory cfg.configLocation}" = + mkIf (cfg.settings != { } && lib.hasPrefix config.home.homeDirectory cfg.configLocation) + { + source = yamlFormat.generate "aliae.yaml" cfg.settings; + }; + programs.bash.initExtra = mkIf cfg.enableBashIntegration ''eval "$(aliae init bash)"''; programs.zsh.initContent = mkIf cfg.enableZshIntegration ''eval "$(aliae init zsh)"''; programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration "aliae init fish | source"; diff --git a/tests/modules/programs/aliae/asserts.nix b/tests/modules/programs/aliae/asserts.nix new file mode 100644 index 000000000..56ff484c3 --- /dev/null +++ b/tests/modules/programs/aliae/asserts.nix @@ -0,0 +1,30 @@ +{ + programs.aliae = { + enable = true; + configLocation = "/another/path/aliae.yaml"; + settings = { + alias = [ + { + name = "a"; + value = "aliae"; + } + { + name = "hello-world"; + value = ''echo "hello world"''; + type = "function"; + } + ]; + + env = [ + { + name = "EDITOR"; + value = "code-insiders --wait"; + } + ]; + }; + }; + + test.asserts.assertions.expected = [ + "The option `programs.aliae.configLocation` must point to a file inside user's home directory when `programs.aliae.settings` is set." + ]; +} diff --git a/tests/modules/programs/aliae/config-location-no-settings.nix b/tests/modules/programs/aliae/config-location-no-settings.nix new file mode 100644 index 000000000..83af6a66b --- /dev/null +++ b/tests/modules/programs/aliae/config-location-no-settings.nix @@ -0,0 +1,6 @@ +{ + programs.aliae = { + enable = true; + configLocation = "/another/path/aliae.yaml"; + }; +} diff --git a/tests/modules/programs/aliae/default.nix b/tests/modules/programs/aliae/default.nix index c937f12ef..564986fb3 100644 --- a/tests/modules/programs/aliae/default.nix +++ b/tests/modules/programs/aliae/default.nix @@ -1 +1,5 @@ -{ aliae-settings = ./settings.nix; } +{ + aliae-settings = ./settings.nix; + aliae-asserts = ./asserts.nix; + aliae-config-location-no-settings = ./config-location-no-settings.nix; +}