Skip to content

Commit

Permalink
feat(lib): add RON type constructors for option definitions
Browse files Browse the repository at this point in the history
Add `ron` helper function to provide type-safe constructors for RON data structures.
This will serve as a foundation for improving how users can define their COSMIC
desktop options in a more ergonomic way.
  • Loading branch information
HeitorAugustoLN committed Jan 8, 2025
1 parent d283378 commit 68958ad
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{ lib, ... }:
let
generators = import ./generators.nix { inherit lib; };
in
{
inherit generators;

applets = import ./applets.nix { inherit lib; };
applications = import ./applications.nix { inherit lib; };
generators = import ./generators.nix { inherit lib; };
modules = import ./modules.nix { inherit lib; };
options = import ./options.nix { inherit lib; };
utils = import ./utils.nix { inherit lib; };

inherit (generators) ron;
}
45 changes: 45 additions & 0 deletions lib/generators.nix
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,49 @@
.${type} or (throw "lib.cosmic.generators.toRON: ${type} is not supported.");
in
toRON';

ron =
type: value:
{
char = {
__type = "char";
inherit value;
};
enum =
if builtins.isAttrs value then
if
builtins.attrNames value == [
"value"
"variant"
]
then
{
__type = "enum";
inherit (value) value variant;
}
else
throw "lib.cosmic.ron: enum type must receive a string or an attribute set with value and variant keys value"
else
{
__type = "enum";
inherit value;
};
map = {
__type = "map";
inherit value;
};
optional = {
__type = "optional";
inherit value;
};
raw = {
__type = "raw";
inherit value;
};
tuple = {
__type = "tuple";
inherit value;
};
}
.${type} or (throw "lib.cosmic.ron: ${type} is not supported.");
}

0 comments on commit 68958ad

Please sign in to comment.