diff --git a/modules/programs/sketchybar.nix b/modules/programs/sketchybar.nix index 71952701..7df44b62 100644 --- a/modules/programs/sketchybar.nix +++ b/modules/programs/sketchybar.nix @@ -45,12 +45,11 @@ in }; config = mkOption { - type = with types; nullOr (either lines path); - default = ""; + type = types.nullOr (lib.hm.types.sourceFileOrLines ".config/sketchybar" "sketchybarrc"); + default = null; example = literalExpression '' - # Bash example - #!/usr/bin/env bash - + # String example - inline configuration + ''' # Define colors export COLOR_BLACK="0xff181926" export COLOR_WHITE="0xffcad3f5" @@ -75,12 +74,28 @@ in # Update the bar sketchybar --update + ''' + + # Or directory example - for complex configurations + # { + # source = ./path/to/sketchybar-config; + # recursive = true; + # } ''; description = '' - The complete sketchybar configuration content. - This should be written in the language specified by configType (bash or lua). + The sketchybar configuration. Can be specified as: - The appropriate shebang will be automatically added. + 1. A string containing the configuration content directly + 2. An attribute set with 'source' pointing to a directory containing + the full configuration, and optionally 'recursive = true' to + recursively copy all files + 3. An attribute set with 'text' containing inline configuration + + When using a string or 'text', the appropriate shebang will be + automatically added based on configType (bash or lua). + + When using a directory source, it should contain a file named + "sketchybarrc" which serves as the main entry point. ''; }; @@ -222,26 +237,6 @@ in home.packages = [ cfg.finalPackage ]; - xdg.configFile."sketchybar/sketchybarrc".source = lib.mkIf (cfg.config != "") ( - pkgs.writeTextFile { - name = "sketchybarrc"; - text = - if cfg.configType == "lua" then - '' - #!/usr/bin/env lua - -- Generated by home-manager - ${cfg.config} - '' - else - '' - #!/usr/bin/env bash - # Generated by home-manager - ${cfg.config} - ''; - executable = true; - } - ); - launchd.agents.sketchybar = { enable = cfg.service.enable; config = { @@ -253,5 +248,38 @@ in StandardOutPath = cfg.service.outLogFile; }; }; + + xdg.configFile = lib.mkIf (cfg.config != null) ( + if cfg.config.source != null && cfg.config.recursive then + { + "sketchybar" = { + inherit (cfg.config) source recursive; + }; + } + else if cfg.config.source != null then + { + "sketchybar/sketchybarrc".source = cfg.config.source; + } + else + { + "sketchybar/sketchybarrc".source = pkgs.writeTextFile { + name = "sketchybarrc"; + text = + if cfg.configType == "lua" then + '' + #!/usr/bin/env lua + -- Generated by home-manager + ${cfg.config.text} + '' + else + '' + #!/usr/bin/env bash + # Generated by home-manager + ${cfg.config.text} + ''; + executable = true; + }; + } + ); }; } diff --git a/tests/modules/programs/sketchybar/default.nix b/tests/modules/programs/sketchybar/default.nix index 0b77ac43..64efb79a 100644 --- a/tests/modules/programs/sketchybar/default.nix +++ b/tests/modules/programs/sketchybar/default.nix @@ -1,6 +1,7 @@ { - sketchybar = ./sketchybar.nix; # Bash configuration with validation - sketchybar-lua-config = ./sketchybar-lua-config.nix; # Lua configuration with validation - sketchybar-invalid-lua-config = ./sketchybar-invalid-lua-config.nix; # Tests error on missing sbarLua - sketchybar-service-integration = ./sketchybar-service-integration.nix; # Service integration with validation + sketchybar = ./sketchybar.nix; + sketchybar-directory-config = ./sketchybar-directory-config.nix; + sketchybar-invalid-lua-config = ./sketchybar-invalid-lua-config.nix; + sketchybar-lua-config = ./sketchybar-lua-config.nix; + sketchybar-service-integration = ./sketchybar-service-integration.nix; } diff --git a/tests/modules/programs/sketchybar/sketchybar-directory-config.nix b/tests/modules/programs/sketchybar/sketchybar-directory-config.nix new file mode 100644 index 00000000..b1a64818 --- /dev/null +++ b/tests/modules/programs/sketchybar/sketchybar-directory-config.nix @@ -0,0 +1,62 @@ +{ config, pkgs, ... }: + +let + # Create a mock directory structure for testing + configDir = pkgs.runCommand "sketchybar-config" { } '' + mkdir -p $out/plugins + cat > $out/sketchybarrc < $out/plugins/battery.sh < $out/plugins/clock.sh <ProcessType Interactive Program - /@sketchybar@/bin/sketchybar + /nix/store/00000000000000000000000000000000-sketchybar/bin/sketchybar RunAtLoad StandardErrorPath diff --git a/tests/modules/programs/sketchybar/sketchybar-service-integration.nix b/tests/modules/programs/sketchybar/sketchybar-service-integration.nix index c4de01c7..9c7bfb12 100644 --- a/tests/modules/programs/sketchybar/sketchybar-service-integration.nix +++ b/tests/modules/programs/sketchybar/sketchybar-service-integration.nix @@ -38,7 +38,6 @@ in sketchybar --update ''; - # Enable the integrated service service = { enable = true; errorLogFile = "/home/hm-user/Library/Logs/sketchybar/sketchybar.err.log"; @@ -46,16 +45,12 @@ in }; }; - # Change home directory for the test home.homeDirectory = "/home/hm-user"; - # Validate the generated config files nmt.script = '' - # Verify config file exists assertFileExists home-files/.config/sketchybar/sketchybarrc - # Verify service file exists and matches expected content - serviceFile=LaunchAgents/org.nix-community.home.sketchybar.plist + serviceFile=$(normalizeStorePaths LaunchAgents/org.nix-community.home.sketchybar.plist) assertFileExists "$serviceFile" assertFileContent "$serviceFile" ${./sketchybar-service-expected.plist} '';