Skip to content

Commit

Permalink
refactor: simplify cosmic entry type system and fix config conditionals
Browse files Browse the repository at this point in the history
- Remove complex cosmicEntry type definition in favor of direct cosmicEntryValue
- Fix configuration conditionals to properly use cfg.enable
- Make cosmic-ctl package installation conditional on config
  • Loading branch information
HeitorAugustoLN committed Dec 18, 2024
1 parent dee2beb commit 959f7b9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 67 deletions.
66 changes: 1 addition & 65 deletions lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,70 +10,6 @@
(attrsOf anything)
]);

cosmicEntry = lib.types.submodule (
{ config, ... }:
{
options = {
value = lib.mkOption {
type = lib.types.cosmicEntryValue;
example = true;
description = ''
The value stored in the entry.
'';
};
__type = lib.mkOption {
type =
with lib.types;
nullOr (enum [
"raw"
"option"
"char"
"map"
"tuple"
]);
default = null;
example = "raw";
description = ''
Internal type classification for cosmic entries.
When `null`, the entry is treated as a simple value.
Must not be used together with `__name`.
The following types are supported:
- `raw`: The value is stored as-is.
- `option`: The value is stored as an optional value. (e.g. `Some(value)` or `None`).
- `char`: The value is stored as a single character. (e.g. `'a'`).
- `map`: The value is stored as a map. (e.g. `{ "key" = "value"; }`).
- `tuple`: The value is stored as a tuple. (e.g. `(1, 2, 3)`).
'';
};
__name = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "Config";
description = ''
Identifier for named struct entries.
When set, provides a label for the entry in structured data.
Must not be used together with `__type`.
'';
};
};

config = {
_module.check = lib.mkIf (config.__type != null && config.__name != null) (
throw "Cannot specify both type and name in cosmicEntry"
);
};
}
);

coercedCosmicEntry =
with lib.types;
coercedTo cosmicEntryValue (value: { inherit value; }) cosmicEntry;

cosmicComponent = lib.types.submodule {
options = {
version = lib.mkOption {
Expand All @@ -86,7 +22,7 @@
};

entries = lib.mkOption {
type = with lib.types; attrsOf coercedCosmicEntry;
type = with lib.types; attrsOf cosmicEntryValue;
default = { };
example = {
autotile = true;
Expand Down
5 changes: 3 additions & 2 deletions modules/files.nix
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
lib.mapAttrsToList (component: details: {
inherit component;
inherit (details) version;

operation = "write";
xdg_directory = xdgDirectory;
entries = builtins.mapAttrs (
Expand Down Expand Up @@ -261,7 +262,7 @@
];

home = {
activation = lib.mkIf config.wayland.desktopManager.cosmic.enable {
activation = lib.mkIf cfg.enable {
configure-cosmic = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
run ${lib.getExe cosmic-ctl} apply ${json}
'';
Expand All @@ -277,7 +278,7 @@
);
};

packages = [ cosmic-ctl ];
packages = lib.optionals cfg.enable [ cosmic-ctl ];
};
};
}

0 comments on commit 959f7b9

Please sign in to comment.