1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-03 07:31:03 +01:00

ashell: support yaml and toml config

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman 2025-06-29 17:17:51 -05:00
parent f62e9a8114
commit 650a38ebe8
11 changed files with 226 additions and 6 deletions

View file

@ -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
<https://github.com/MalpenZibo/ashell/tree/0.5.0?tab=readme-ov-file#configuration>.
<https://github.com/MalpenZibo/ashell?tab=readme-ov-file#configuration>.
'';
};
@ -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 {

View file

@ -0,0 +1,8 @@
[modules]
center = ["Window Title"]
left = ["Workspaces"]
right = ["SystemInfo", "Clock"]
[workspaces]
show_empty = true
visibility_mode = "MonitorSpecific"

View file

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

View file

@ -0,0 +1,11 @@
modules:
center:
- Window Title
left:
- Workspaces
right:
- SystemInfo
- Clock
workspaces:
showEmpty: true
visibilityMode: MonitorSpecific

View file

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

View file

@ -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"

View file

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

View file

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

View file

@ -0,0 +1,13 @@
{ ... }:
{
programs.ashell = {
enable = true;
settings = { };
};
nmt.script = ''
assertPathNotExists home-files/.config/ashell/config.toml
assertPathNotExists home-files/.config/ashell.yml
'';
}

View file

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

View file

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