Add obsidian plugins

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2024-07-11 20:34:46 +03:00
parent e21c8ff99f
commit 60f12e7aa5
3 changed files with 90 additions and 3 deletions

View File

@@ -48,6 +48,8 @@
"tag-pane" "tag-pane"
]; ];
plugins = [ (import ./plugins/minimal-settings.nix { inherit pkgs; }) ];
cssSnippets = [ cssSnippets = [
./snippets/editor-monospace.css ./snippets/editor-monospace.css
./snippets/file-explorer-separators.css ./snippets/file-explorer-separators.css

View File

@@ -84,6 +84,12 @@ in
]; ];
}; };
plugins = mkOption {
description = "Community plugins to activate.";
type = raw;
default = [ ];
};
cssSnippets = mkOption { cssSnippets = mkOption {
description = "CSS snippets to install."; description = "CSS snippets to install.";
type = raw; type = raw;
@@ -135,6 +141,12 @@ in
default = cfg.sharedSettings.corePlugins; default = cfg.sharedSettings.corePlugins;
}; };
plugins = mkOption {
description = "Community plugins to activate.";
type = listOf package;
default = cfg.sharedSettings.plugins;
};
cssSnippets = mkOption { cssSnippets = mkOption {
description = "CSS snippets to install."; description = "CSS snippets to install.";
type = listOf path; type = listOf path;
@@ -160,7 +172,13 @@ in
config = config =
let let
vaults = builtins.filter (vault: vault.enable == true) (builtins.attrValues cfg.vaults); vaults = builtins.filter (vault: vault.enable == true) (builtins.attrValues cfg.vaults);
getThemeName = theme: (builtins.fromJSON (builtins.readFile "${theme}/manifest.json")).name; getManifestId =
pkg:
let
manifest = builtins.fromJSON (builtins.readFile "${pkg}/manifest.json");
in
manifest.id or manifest.name;
readDir = dir: builtins.attrNames (builtins.readDir dir);
in in
lib.mkIf cfg.enable { lib.mkIf cfg.enable {
home = { home = {
@@ -185,7 +203,7 @@ in
) vault.settings.cssSnippets; ) vault.settings.cssSnippets;
} }
// lib.attrsets.optionalAttrs (vault.settings.theme != null) { // lib.attrsets.optionalAttrs (vault.settings.theme != null) {
cssTheme = getThemeName vault.settings.theme; cssTheme = getManifestId vault.settings.theme;
} }
); );
}; };
@@ -211,6 +229,38 @@ in
}; };
} }
]; ];
mkCommunityPlugins =
vault:
[
{
name = "${vault.target}/.obsidian/community-plugins.json";
value = {
source = (pkgs.formats.json { }).generate "community-plugins.json" (
builtins.map getManifestId vault.settings.plugins
);
};
}
]
/*
We can't do the following since plugins often write files in their directories,
and symlinking the entire folder does not give us write permissions.
builtins.map (plugin: {
name = "${vault.target}/.obsidian/plugins/${getManifestId plugin}";
value = { source = plugin; };
}) vault.settings.plugins;
This is why we do a double loop over plugins and their files.
*/
++ builtins.map (
plugin:
builtins.map (file: {
name = "${vault.target}/.obsidian/plugins/${getManifestId plugin}/${file}";
value = {
source = "${plugin}/${file}";
};
}) (readDir plugin)
) vault.settings.plugins;
mkCssSnippets = mkCssSnippets =
vault: vault:
builtins.map (snippet: { builtins.map (snippet: {
@@ -222,7 +272,7 @@ in
mkTheme = mkTheme =
vault: vault:
lib.attrsets.optionalAttrs (vault.settings.theme != null) { lib.attrsets.optionalAttrs (vault.settings.theme != null) {
name = "${vault.target}/.obsidian/themes/${getThemeName vault.settings.theme}"; name = "${vault.target}/.obsidian/themes/${getManifestId vault.settings.theme}";
value = { value = {
source = vault.settings.theme; source = vault.settings.theme;
}; };
@@ -234,6 +284,7 @@ in
(mkApp vault) (mkApp vault)
(mkAppearance vault) (mkAppearance vault)
(mkCorePlugins vault) (mkCorePlugins vault)
(mkCommunityPlugins vault)
(mkCssSnippets vault) (mkCssSnippets vault)
(mkTheme vault) (mkTheme vault)
]) vaults ]) vaults

View File

@@ -0,0 +1,34 @@
{
pkgs ? import <nixpkgs> { },
...
}:
let
version = "8.0.2";
css = builtins.fetchurl {
url = "https://github.com/kepano/obsidian-minimal-settings/releases/download/${version}/styles.css";
sha256 = "sha256:07nkr3sm7dkg8hbmqn45zyaafcblbbvh2s5qlhjh2x0zmi6kmx45";
};
js = builtins.fetchurl {
url = "https://github.com/kepano/obsidian-minimal-settings/releases/download/${version}/main.js";
sha256 = "sha256:0s935p4890mk2b15ffqxyggfcp9p60y1k1121ayni4hh1iinnkcv";
};
in
pkgs.stdenv.mkDerivation {
name = "obsidian.plugins.minimal-settings";
src = builtins.fetchurl {
url = "https://github.com/kepano/obsidian-minimal-settings/releases/download/${version}/manifest.json";
sha256 = "sha256:1akim1ymm3za9h3h2jy82gc7wviwxvv9kc8rqmp69v9y3h1dn10z";
};
phases = [ "installPhase" ];
installPhase = ''
mkdir -p $out
cp $src $out/manifest.json
cp ${css} $out/styles.css
cp ${js} $out/main.js
'';
}