Add more personal obsidian configs

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2024-07-23 19:07:59 +01:00
parent 2c1da71951
commit 01684dca93
17 changed files with 641 additions and 112 deletions

View File

@@ -79,33 +79,30 @@ in
config.name = mkDefault (toCssName config.source);
};
pluginsExtraFilesOptions =
{ name, config, ... }:
corePluginsOptions =
{ config, ... }:
{
options = {
source = mkOption {
type = nullOr path;
description = "Path of the source file or directory.";
default = null;
enable = mkOption {
type = bool;
default = true;
description = "Whether to enable the plugin.";
};
text = mkOption {
type = nullOr str;
description = "Text of the file.";
default = null;
name = mkOption {
type = enum corePlugins;
description = "The plugin.";
};
target = mkOption {
type = str;
defaultText = literalExpression "name";
description = "Path to target relative to the plugin directory.";
options = mkOption {
type = attrsOf anything;
description = "Plugin options to include.";
default = { };
};
};
config.target = mkDefault name;
};
pluginsOptions =
communityPluginsOptions =
{ config, ... }:
{
options = {
@@ -120,9 +117,9 @@ in
description = "The plugin package.";
};
extraFiles = mkOption {
type = attrsOf (submodule pluginsExtraFilesOptions);
description = "Additional files to include in the plugin directory.";
options = mkOption {
type = attrsOf anything;
description = "Options to include in the plugin's `data.json`.";
default = { };
};
};
@@ -162,6 +159,31 @@ in
};
};
extraFilesOptions =
{ name, config, ... }:
{
options = {
source = mkOption {
type = nullOr path;
description = "Path of the source file or directory.";
default = null;
};
text = mkOption {
type = nullOr str;
description = "Text of the file.";
default = null;
};
target = mkOption {
type = str;
defaultText = literalExpression "name";
description = "Path to target relative to the vault's directory.";
};
};
config.target = mkDefault name;
};
in
{
enable = mkEnableOption "obsidian";
@@ -205,14 +227,14 @@ in
];
};
cssSnippets = mkOption {
description = "CSS snippets to install.";
communityPlugins = mkOption {
description = "Community plugins to install and activate.";
type = raw;
default = [ ];
};
plugins = mkOption {
description = "Community plugins to install and activate.";
cssSnippets = mkOption {
description = "CSS snippets to install.";
type = raw;
default = [ ];
};
@@ -228,6 +250,12 @@ in
type = raw;
default = { };
};
extraFiles = mkOption {
description = "Extra files to link to the vault directory.";
type = raw;
default = { };
};
};
vaults = mkOption {
@@ -264,22 +292,22 @@ in
corePlugins = mkOption {
description = "Core plugins to activate.";
type = listOf (enum corePlugins);
type = listOf (either (enum corePlugins) (submodule corePluginsOptions));
default = cfg.sharedSettings.corePlugins;
};
communityPlugins = mkOption {
description = "Community plugins to install and activate.";
type = listOf (either package (submodule communityPluginsOptions));
default = cfg.sharedSettings.communityPlugins;
};
cssSnippets = mkOption {
description = "CSS snippets to install.";
type = listOf (either (addCheck path checkCssPath) (submodule cssSnippetsOptions));
default = cfg.sharedSettings.cssSnippets;
};
plugins = mkOption {
description = "Community plugins to install and activate.";
type = listOf (either package (submodule pluginsOptions));
default = cfg.sharedSettings.plugins;
};
themes = mkOption {
description = "Themes to install.";
type = listOf (either package (submodule themesOptions));
@@ -291,6 +319,12 @@ in
type = attrsOf (listOf (submodule hotkeysOptions));
default = cfg.sharedSettings.hotkeys;
};
extraFiles = mkOption {
description = "Extra files to link to the vault directory.";
type = attrsOf (submodule extraFilesOptions);
default = cfg.sharedSettings.extraFiles;
};
};
};
@@ -305,8 +339,10 @@ in
config =
let
vaults = builtins.filter (vault: vault.enable == true) (builtins.attrValues cfg.vaults);
toName = item: if item ? name then item.name else item;
toPkg = item: if item ? pkg then item.pkg else item;
isEnabled = item: if item ? enable then item.enable else true;
hasOptions = item: item ? options;
getCssName = item: if builtins.isAttrs item then item.name else toCssName item;
getManifest =
item:
@@ -348,39 +384,48 @@ in
};
};
mkCorePlugins = vault: [
{
name = "${vault.target}/.obsidian/core-plugins.json";
mkCorePlugins =
vault:
[
{
name = "${vault.target}/.obsidian/core-plugins.json";
value = {
source = (pkgs.formats.json { }).generate "core-plugins.json" (
builtins.map toName vault.settings.corePlugins
);
};
}
{
name = "${vault.target}/.obsidian/core-plugins-migration.json";
value = {
source = (pkgs.formats.json { }).generate "core-plugins-migration.json" (
builtins.listToAttrs (
builtins.map (name: {
inherit name;
value = builtins.any (
plugin: name == (toName plugin) && isEnabled plugin
) vault.settings.corePlugins;
}) corePlugins
)
);
};
}
]
++ builtins.map (plugin: {
name = "${vault.target}/.obsidian/${plugin.name}.json";
value = {
source = (pkgs.formats.json { }).generate "core-plugins.json" vault.settings.corePlugins;
source = (pkgs.formats.json { }).generate "${plugin.name}.json" plugin.options;
};
}
{
name = "${vault.target}/.obsidian/core-plugins-migration.json";
value = {
source = (pkgs.formats.json { }).generate "core-plugins-migration.json" (
builtins.listToAttrs (
builtins.map (plugin: {
name = plugin;
value = builtins.elem plugin vault.settings.corePlugins;
}) vault.settings.corePlugins
)
);
};
}
];
}) (builtins.filter hasOptions vault.settings.corePlugins);
mkCommunityPlugins =
vault:
let
enabledPlugins = builtins.filter isEnabled vault.settings.plugins;
in
[
{
name = "${vault.target}/.obsidian/community-plugins.json";
value = {
source = (pkgs.formats.json { }).generate "community-plugins.json" (
builtins.map getManifest enabledPlugins
builtins.map getManifest (builtins.filter isEnabled vault.settings.communityPlugins)
);
};
}
@@ -391,14 +436,13 @@ in
source = toPkg plugin;
recursive = true;
};
}) vault.settings.plugins
++ builtins.map (
plugin:
builtins.map (file: {
name = "${vault.target}/.obsidian/plugins/${getManifest plugin}/${file.target}";
value = if file.source != null then { inherit (file) source; } else { inherit (file) text; };
}) (builtins.attrValues (plugin.extraFiles or { }))
) vault.settings.plugins;
}) vault.settings.communityPlugins
++ builtins.map (plugin: {
name = "${vault.target}/.obsidian/plugins/${getManifest plugin}/data.json";
value = {
source = (pkgs.formats.json { }).generate "data.json" plugin.options;
};
}) (builtins.filter hasOptions vault.settings.communityPlugins);
mkCssSnippets =
vault:
@@ -426,6 +470,13 @@ in
source = (pkgs.formats.json { }).generate "hotkeys.json" vault.settings.hotkeys;
};
};
mkExtraFiles =
vault:
builtins.map (file: {
name = "${vault.target}/.obsidian/${file.target}";
value = if file.source != null then { inherit (file) source; } else { inherit (file) text; };
}) (builtins.attrValues vault.settings.extraFiles);
in
builtins.listToAttrs (
lib.lists.flatten (
@@ -437,6 +488,7 @@ in
(mkCssSnippets vault)
(mkThemes vault)
(mkHotkeys vault)
(mkExtraFiles vault)
]) vaults
)
);
@@ -467,12 +519,9 @@ in
{
assertion = builtins.all (
vault:
builtins.all (
plugin:
builtins.all (file: file.source == null || file.text == null) (
builtins.attrValues (plugin.extraFiles or { })
)
) vault.settings.plugins
builtins.all (file: file.source == null || file.text == null) (
builtins.attrValues vault.settings.extraFiles
)
) (builtins.attrValues cfg.vaults);
message = "Only one of `source` and `text` must be set";
}