-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for COSMIC applets
Introduces a new system for managing COSMIC applets declaratively: - Add mkCosmicApplet function for creating applet modules - Implement app-list as first applet module - Add applets support to the module system - Fix string interpolation in applications config - Add enum and tuple enum examples to options This allows users to configure COSMIC applets through home-manager, starting with the App Tray applet.
- Loading branch information
1 parent
4face56
commit b26b896
Showing
6 changed files
with
179 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
{ lib, ... }: | ||
{ | ||
mkCosmicApplet = | ||
{ | ||
configurationVersion, | ||
extraConfig ? _cfg: { }, | ||
extraOptions ? { }, | ||
hasSettings ? true, | ||
identifier, | ||
imports ? [ ], | ||
isBuiltin ? true, | ||
maintainers, | ||
name, | ||
originalName ? name, | ||
package ? if isBuiltin then null else package, | ||
settingsDescription ? "Configuration entries for ${originalName} applet.", | ||
settingsOptions ? { }, | ||
settingsExample ? null, | ||
}@args: | ||
let | ||
module = | ||
{ config, pkgs, ... }: | ||
let | ||
cfg = config.wayland.desktopManager.cosmic.applets.${name}; | ||
in | ||
{ | ||
options.wayland.desktopManager.cosmic.applets.${name} = | ||
lib.optionalAttrs (!isBuiltin) { | ||
enable = lib.mkEnableOption "${originalName} applet"; | ||
package = lib.mkPackageOption pkgs package { | ||
extraDescription = "Set to `null` if you don't want to install the package."; | ||
nullable = true; | ||
}; | ||
} | ||
// lib.optionalAttrs hasSettings { | ||
settings = lib.cosmic.options.mkSettingsOption { | ||
description = settingsDescription; | ||
example = settingsExample; | ||
options = settingsOptions; | ||
}; | ||
} | ||
// extraOptions; | ||
|
||
config = | ||
let | ||
anySettingsSet = | ||
(lib.pipe cfg.settings [ | ||
builtins.attrValues | ||
(builtins.filter (x: x != null)) | ||
builtins.length | ||
]) > 0; | ||
enabled = if isBuiltin then anySettingsSet else cfg.enable; | ||
in | ||
lib.mkIf enabled ( | ||
lib.mkMerge [ | ||
{ | ||
assertions = [ | ||
{ | ||
assertion = enabled -> config.wayland.desktopManager.cosmic.enable; | ||
message = "COSMIC Desktop declarative configuration must be enabled to use ${originalName} applet module."; | ||
} | ||
]; | ||
} | ||
|
||
(lib.optionalAttrs (!isBuiltin) { | ||
home.packages = lib.optionals (cfg.package != null) [ cfg.package ]; | ||
}) | ||
|
||
(lib.optionalAttrs hasSettings { | ||
wayland.desktopManager.cosmic = { | ||
configFile.${identifier} = { | ||
entries = cfg.settings; | ||
version = configurationVersion; | ||
}; | ||
}; | ||
}) | ||
|
||
(lib.optionalAttrs (args ? extraConfig) ( | ||
lib.cosmic.modules.applyExtraConfig { inherit cfg extraConfig; } | ||
)) | ||
] | ||
); | ||
|
||
meta.maintainers = maintainers; | ||
}; | ||
in | ||
{ | ||
imports = imports ++ [ module ]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ lib, ... }: | ||
let | ||
inherit (lib.cosmic.options) mkNullOrOption; | ||
in | ||
lib.cosmic.applets.mkCosmicApplet { | ||
name = "app-list"; | ||
original = "App Tray"; | ||
identifier = "com.system76.CosmicAppList"; | ||
configurationVersion = 1; | ||
|
||
settingsOptions = { | ||
enable_drag_source = mkNullOrOption { | ||
type = lib.types.bool; | ||
example = true; | ||
description = '' | ||
Whether to enable dragging applications from the application list. | ||
''; | ||
}; | ||
|
||
favorites = mkNullOrOption { | ||
type = with lib.types; listOf str; | ||
example = [ | ||
"firefox" | ||
"com.system76.CosmicFiles" | ||
"com.system76.CosmicEdit" | ||
"com.system76.CosmicTerm" | ||
"com.system76.CosmicSettings" | ||
]; | ||
description = '' | ||
A list of applications to always be shown in the application list. | ||
''; | ||
}; | ||
|
||
filter_top_levels = mkNullOrOption { | ||
type = | ||
with lib.types; | ||
ronOptionalOf (ronEnum [ | ||
"ActiveWorkspace" | ||
"ConfiguredOutput" | ||
]); | ||
example = { | ||
__type = "optional"; | ||
value = { | ||
__type = "enum"; | ||
variant = "ActiveWorkspace"; | ||
}; | ||
}; | ||
description = '' | ||
The top level filter to use for the application list. | ||
''; | ||
}; | ||
}; | ||
|
||
settingsExample = { | ||
enable_drag_source = true; | ||
favorites = [ | ||
"firefox" | ||
"com.system76.CosmicFiles" | ||
"com.system76.CosmicEdit" | ||
"com.system76.CosmicTerm" | ||
"com.system76.CosmicSettings" | ||
]; | ||
filter_top_levels = { | ||
__type = "optional"; | ||
value = { | ||
__type = "enum"; | ||
variant = "ActiveWorkspace"; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters