From 2126d13d7f0049b2731e586f8e611eb8f775bcd3 Mon Sep 17 00:00:00 2001 From: Aguirre Matteo Date: Fri, 3 Oct 2025 16:09:00 -0300 Subject: [PATCH] aliae: add configLocation option --- modules/programs/aliae.nix | 33 +++++++++++++++++-- tests/modules/programs/aliae/asserts.nix | 30 +++++++++++++++++ .../aliae/config-location-no-settings.nix | 6 ++++ tests/modules/programs/aliae/default.nix | 6 +++- 4 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 tests/modules/programs/aliae/asserts.nix create mode 100644 tests/modules/programs/aliae/config-location-no-settings.nix diff --git a/modules/programs/aliae.nix b/modules/programs/aliae.nix index ba351b24..42450bf3 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 00000000..56ff484c --- /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 00000000..83af6a66 --- /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 c937f12e..564986fb 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; +}