From 650a38ebe819d439ece41b5a1c510b3244896265 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Sun, 29 Jun 2025 17:17:51 -0500 Subject: [PATCH] ashell: support yaml and toml config Signed-off-by: Austin Horstman --- modules/programs/ashell.nix | 29 ++++++++++++--- .../ashell/basic-toml-config-expected.toml | 8 ++++ .../programs/ashell/basic-toml-config.nix | 34 +++++++++++++++++ .../ashell/basic-yaml-config-expected.yml | 11 ++++++ .../programs/ashell/basic-yaml-config.nix | 34 +++++++++++++++++ .../ashell/camelcase-migration-expected.toml | 13 +++++++ .../programs/ashell/camelcase-migration.nix | 37 +++++++++++++++++++ tests/modules/programs/ashell/default.nix | 9 +++++ .../programs/ashell/empty-settings.nix | 13 +++++++ .../ashell/systemd-service-expected.service | 11 ++++++ .../programs/ashell/systemd-service.nix | 33 +++++++++++++++++ 11 files changed, 226 insertions(+), 6 deletions(-) create mode 100644 tests/modules/programs/ashell/basic-toml-config-expected.toml create mode 100644 tests/modules/programs/ashell/basic-toml-config.nix create mode 100644 tests/modules/programs/ashell/basic-yaml-config-expected.yml create mode 100644 tests/modules/programs/ashell/basic-yaml-config.nix create mode 100644 tests/modules/programs/ashell/camelcase-migration-expected.toml create mode 100644 tests/modules/programs/ashell/camelcase-migration.nix create mode 100644 tests/modules/programs/ashell/default.nix create mode 100644 tests/modules/programs/ashell/empty-settings.nix create mode 100644 tests/modules/programs/ashell/systemd-service-expected.service create mode 100644 tests/modules/programs/ashell/systemd-service.nix diff --git a/modules/programs/ashell.nix b/modules/programs/ashell.nix index ac0a79586..309e76420 100644 --- a/modules/programs/ashell.nix +++ b/modules/programs/ashell.nix @@ -6,7 +6,23 @@ }: let cfg = config.programs.ashell; - settingsFormat = pkgs.formats.toml { }; + tomlFormat = pkgs.formats.toml { }; + yamlFormat = pkgs.formats.yaml { }; + + packageVersion = if cfg.package != null then lib.getVersion cfg.package else "0.5.0"; + isTomlConfig = lib.versionAtLeast packageVersion "0.5.0"; + settingsFormat = if isTomlConfig then tomlFormat else yamlFormat; + configFileName = if isTomlConfig then "ashell/config.toml" else "ashell.yml"; + + # Create migration function for camelCase to snake_case conversion + migrateSettings = lib.hm.deprecations.remapAttrsRecursive { + pred = lib.hm.strings.isCamelCase; + transform = lib.hm.strings.toSnakeCase; + }; + + # Apply migration only for TOML config (ashell >= 0.5.0) + processedSettings = + if isTomlConfig then migrateSettings "programs.ashell.settings" cfg.settings else cfg.settings; in { meta.maintainers = [ lib.maintainers.justdeeevin ]; @@ -17,7 +33,7 @@ in package = lib.mkPackageOption pkgs "ashell" { nullable = true; }; settings = lib.mkOption { - type = settingsFormat.type; + inherit (settingsFormat) type; default = { }; example = { modules = { @@ -35,9 +51,10 @@ in workspaces.visibilityMode = "MonitorSpecific"; }; description = '' - Ashell configuration written to {file}`$XDG_CONFIG_HOME/ashell/config.toml`. + Ashell configuration written to {file}`$XDG_CONFIG_HOME/ashell/config.toml` (0.5.0+) + or {file}`$XDG_CONFIG_HOME/ashell/config.yaml` (<0.5.0). For available settings see - . + . ''; }; @@ -69,8 +86,8 @@ in ]; home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - xdg.configFile."ashell/config.toml" = lib.mkIf (cfg.settings != { }) { - source = settingsFormat.generate "ashell-config" cfg.settings; + xdg.configFile."${configFileName}" = lib.mkIf (cfg.settings != { }) { + source = settingsFormat.generate "ashell-config" processedSettings; }; } (lib.mkIf cfg.systemd.enable { diff --git a/tests/modules/programs/ashell/basic-toml-config-expected.toml b/tests/modules/programs/ashell/basic-toml-config-expected.toml new file mode 100644 index 000000000..6ec17dabc --- /dev/null +++ b/tests/modules/programs/ashell/basic-toml-config-expected.toml @@ -0,0 +1,8 @@ +[modules] +center = ["Window Title"] +left = ["Workspaces"] +right = ["SystemInfo", "Clock"] + +[workspaces] +show_empty = true +visibility_mode = "MonitorSpecific" diff --git a/tests/modules/programs/ashell/basic-toml-config.nix b/tests/modules/programs/ashell/basic-toml-config.nix new file mode 100644 index 000000000..0ceb31b70 --- /dev/null +++ b/tests/modules/programs/ashell/basic-toml-config.nix @@ -0,0 +1,34 @@ +{ pkgs, ... }: + +let + ashellPackage = pkgs.runCommand "ashell-0.5.0" { } '' + mkdir -p $out/bin + echo '#!/bin/sh' > $out/bin/ashell + chmod +x $out/bin/ashell + ''; +in +{ + programs.ashell = { + enable = true; + package = ashellPackage; + settings = { + modules = { + left = [ "Workspaces" ]; + center = [ "Window Title" ]; + right = [ + "SystemInfo" + "Clock" + ]; + }; + workspaces = { + visibility_mode = "MonitorSpecific"; + show_empty = true; + }; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/ashell/config.toml + assertFileContent home-files/.config/ashell/config.toml ${./basic-toml-config-expected.toml} + ''; +} diff --git a/tests/modules/programs/ashell/basic-yaml-config-expected.yml b/tests/modules/programs/ashell/basic-yaml-config-expected.yml new file mode 100644 index 000000000..0ffe03522 --- /dev/null +++ b/tests/modules/programs/ashell/basic-yaml-config-expected.yml @@ -0,0 +1,11 @@ +modules: + center: + - Window Title + left: + - Workspaces + right: + - SystemInfo + - Clock +workspaces: + showEmpty: true + visibilityMode: MonitorSpecific diff --git a/tests/modules/programs/ashell/basic-yaml-config.nix b/tests/modules/programs/ashell/basic-yaml-config.nix new file mode 100644 index 000000000..0ae1bb85b --- /dev/null +++ b/tests/modules/programs/ashell/basic-yaml-config.nix @@ -0,0 +1,34 @@ +{ pkgs, ... }: + +let + ashellPackage = pkgs.runCommand "ashell-0.4.1" { } '' + mkdir -p $out/bin + echo '#!/bin/sh' > $out/bin/ashell + chmod +x $out/bin/ashell + ''; +in +{ + programs.ashell = { + enable = true; + package = ashellPackage; + settings = { + modules = { + left = [ "Workspaces" ]; + center = [ "Window Title" ]; + right = [ + "SystemInfo" + "Clock" + ]; + }; + workspaces = { + visibilityMode = "MonitorSpecific"; + showEmpty = true; + }; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/ashell.yml + assertFileContent home-files/.config/ashell.yml ${./basic-yaml-config-expected.yml} + ''; +} diff --git a/tests/modules/programs/ashell/camelcase-migration-expected.toml b/tests/modules/programs/ashell/camelcase-migration-expected.toml new file mode 100644 index 000000000..41f2940b1 --- /dev/null +++ b/tests/modules/programs/ashell/camelcase-migration-expected.toml @@ -0,0 +1,13 @@ +[modules] +center = ["WindowTitle"] +left = ["Workspaces"] +right = ["SystemInfo"] + +[system_info] +refresh_rate = 1000 +show_cpu = true +show_memory = true + +[workspaces] +show_empty = true +visibility_mode = "MonitorSpecific" diff --git a/tests/modules/programs/ashell/camelcase-migration.nix b/tests/modules/programs/ashell/camelcase-migration.nix new file mode 100644 index 000000000..ce1f49f90 --- /dev/null +++ b/tests/modules/programs/ashell/camelcase-migration.nix @@ -0,0 +1,37 @@ +{ pkgs, ... }: +let + ashellPackage = pkgs.runCommand "ashell-0.5.0" { } '' + mkdir -p $out/bin + echo '#!/bin/sh' > $out/bin/ashell + chmod +x $out/bin/ashell + ''; +in +{ + programs.ashell = { + enable = true; + package = ashellPackage; + settings = { + modules = { + left = [ "Workspaces" ]; + center = [ "WindowTitle" ]; + right = [ "SystemInfo" ]; + }; + workspaces = { + visibilityMode = "MonitorSpecific"; + showEmpty = true; + }; + systemInfo = { + refreshRate = 1000; + showCpu = true; + showMemory = true; + }; + }; + }; + + test.asserts.warnings.enable = true; + + nmt.script = '' + assertFileExists home-files/.config/ashell/config.toml + assertFileContent home-files/.config/ashell/config.toml ${./camelcase-migration-expected.toml} + ''; +} diff --git a/tests/modules/programs/ashell/default.nix b/tests/modules/programs/ashell/default.nix new file mode 100644 index 000000000..c57fe5409 --- /dev/null +++ b/tests/modules/programs/ashell/default.nix @@ -0,0 +1,9 @@ +{ lib, pkgs, ... }: + +lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { + ashell-basic-toml = ./basic-toml-config.nix; + ashell-basic-yaml = ./basic-yaml-config.nix; + ashell-camelcase-migration = ./camelcase-migration.nix; + ashell-empty-settings = ./empty-settings.nix; + ashell-systemd-service = ./systemd-service.nix; +} diff --git a/tests/modules/programs/ashell/empty-settings.nix b/tests/modules/programs/ashell/empty-settings.nix new file mode 100644 index 000000000..4a2bcbed1 --- /dev/null +++ b/tests/modules/programs/ashell/empty-settings.nix @@ -0,0 +1,13 @@ +{ ... }: + +{ + programs.ashell = { + enable = true; + settings = { }; + }; + + nmt.script = '' + assertPathNotExists home-files/.config/ashell/config.toml + assertPathNotExists home-files/.config/ashell.yml + ''; +} diff --git a/tests/modules/programs/ashell/systemd-service-expected.service b/tests/modules/programs/ashell/systemd-service-expected.service new file mode 100644 index 000000000..f3077990b --- /dev/null +++ b/tests/modules/programs/ashell/systemd-service-expected.service @@ -0,0 +1,11 @@ +[Install] +WantedBy=hyprland-session.target + +[Service] +ExecStart=@ashell-0.5.0@/bin/ashell +Restart=on-failure + +[Unit] +After=hyprland-session.target +Description=ashell status bar +Documentation=https://github.com/MalpenZibo/ashell/tree/0.4.1 diff --git a/tests/modules/programs/ashell/systemd-service.nix b/tests/modules/programs/ashell/systemd-service.nix new file mode 100644 index 000000000..db07d399a --- /dev/null +++ b/tests/modules/programs/ashell/systemd-service.nix @@ -0,0 +1,33 @@ +{ pkgs, ... }: + +let + ashellPackage = pkgs.runCommand "ashell-0.5.0" { } '' + mkdir -p $out/bin + echo '#!/bin/sh' > $out/bin/ashell + chmod +x $out/bin/ashell + ''; +in +{ + programs.ashell = { + enable = true; + package = ashellPackage; + settings = { + modules = { + left = [ "Workspaces" ]; + }; + }; + systemd = { + enable = true; + target = "hyprland-session.target"; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/ashell/config.toml + assertFileExists home-files/.config/systemd/user/ashell.service + # Check that the service file contains the expected content + assertFileRegex home-files/.config/systemd/user/ashell.service "ExecStart=.*ashell-0.5.0.*/bin/ashell" + assertFileRegex home-files/.config/systemd/user/ashell.service "WantedBy=hyprland-session.target" + assertFileRegex home-files/.config/systemd/user/ashell.service "Description=ashell status bar" + ''; +}