1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46:05 +01:00

aliae: add configLocation option

This commit is contained in:
Aguirre Matteo 2025-10-03 16:09:00 -03:00 committed by Austin Horstman
parent bd92e8ee4a
commit 2126d13d7f
4 changed files with 71 additions and 4 deletions

View file

@ -6,6 +6,7 @@
}: }:
let let
inherit (lib) inherit (lib)
types
mkIf mkIf
mkEnableOption mkEnableOption
mkPackageOption mkPackageOption
@ -31,6 +32,19 @@ in
enableZshIntegration = mkZshIntegrationOption { inherit config; }; enableZshIntegration = mkZshIntegrationOption { inherit config; };
enableFishIntegration = mkFishIntegrationOption { inherit config; }; enableFishIntegration = mkFishIntegrationOption { inherit config; };
enableNushellIntegration = mkNushellIntegrationOption { 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 { settings = mkOption {
inherit (yamlFormat) type; inherit (yamlFormat) type;
default = { }; default = { };
@ -62,10 +76,23 @@ in
}; };
config = mkIf cfg.enable { 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.packages = mkIf (cfg.package != null) [ cfg.package ];
home.file.".aliae.yaml" = mkIf (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; source = yamlFormat.generate "aliae.yaml" cfg.settings;
}; };
programs.bash.initExtra = mkIf cfg.enableBashIntegration ''eval "$(aliae init bash)"''; programs.bash.initExtra = mkIf cfg.enableBashIntegration ''eval "$(aliae init bash)"'';
programs.zsh.initContent = mkIf cfg.enableZshIntegration ''eval "$(aliae init zsh)"''; programs.zsh.initContent = mkIf cfg.enableZshIntegration ''eval "$(aliae init zsh)"'';
programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration "aliae init fish | source"; programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration "aliae init fish | source";

View file

@ -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."
];
}

View file

@ -0,0 +1,6 @@
{
programs.aliae = {
enable = true;
configLocation = "/another/path/aliae.yaml";
};
}

View file

@ -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;
}