Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for COSMIC applets #7

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions lib/applets.nix
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 ];
};
}
2 changes: 1 addition & 1 deletion lib/applications.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

(lib.optionalAttrs hasSettings {
wayland.desktopManager.cosmic = {
configFile."${identifier}" = {
configFile.${identifier} = {
entries = cfg.settings;
version = configurationVersion;
};
Expand Down
1 change: 1 addition & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ lib, ... }:
{
applets = import ./applets.nix { inherit lib; };
applications = import ./applications.nix { inherit lib; };
generators = import ./generators.nix { inherit lib; };
modules = import ./modules.nix { inherit lib; };
Expand Down
11 changes: 10 additions & 1 deletion lib/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,21 @@
1
];
};
named_struct = {
namedStruct = {
__name = "NamedStruct";
value = {
key = "value";
};
};
enum = {
__type = "enum";
variant = "ActiveWorkspace";
};
tupleEnum = {
__type = "enum";
variant = "TupleEnum";
value = [ "foobar" ];
};
}
else
example;
Expand Down
73 changes: 73 additions & 0 deletions modules/applets/by-name/app-list/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{ lib, ... }:
let
inherit (lib.cosmic.options) mkNullOrOption;
in
lib.cosmic.applets.mkCosmicApplet {
name = "app-list";
originalName = "App Tray";
identifier = "com.system76.CosmicAppList";
configurationVersion = 1;

maintainers = [ lib.maintainers.HeitorAugustoLN ];

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";
};
};
};
}
7 changes: 6 additions & 1 deletion modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
;
modules =
let
appletsByName = ./applets/by-name;
appsByName = ./apps/by-name;
in
[
Expand All @@ -23,7 +24,11 @@
++ lib.foldlAttrs (
prev: name: type:
prev ++ lib.optional (type == "directory") (appsByName + "/${name}")
) [ ] (builtins.readDir appsByName);
) [ ] (builtins.readDir appsByName)
++ lib.foldlAttrs (
prev: name: type:
prev ++ lib.optional (type == "directory") (appletsByName + "/${name}")
) [ ] (builtins.readDir appletsByName);
};

options.wayland.desktopManager.cosmic.enable =
Expand Down
Loading