Add obsidian theming

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2024-07-12 19:34:40 +03:00
parent 124f6ab292
commit 5640075117
9 changed files with 305 additions and 124 deletions

View File

@@ -1,7 +1,12 @@
{ {
user ? throw "user argument is required", user ? throw "user argument is required",
}: }:
{ config, lib, ... }: {
config,
lib,
pkgs,
...
}:
let let
hmConfig = config.home-manager.users.${user.name}; hmConfig = config.home-manager.users.${user.name};
in in
@@ -12,6 +17,7 @@ in
xdg = { xdg = {
enable = true; enable = true;
mimeApps.enable = true; mimeApps.enable = true;
portal.extraPortals = with pkgs; [ xdg-desktop-portal-gtk ];
userDirs = { userDirs = {
enable = true; enable = true;

View File

@@ -31,13 +31,14 @@ in
success = mkColor "semantic" "success"; success = mkColor "semantic" "success";
info = mkColor "semantic" "info"; info = mkColor "semantic" "info";
red = mkColor "ansi" "red"; red = mkColor "basic" "red";
green = mkColor "ansi" "green"; orange = mkColor "basic" "orange";
yellow = mkColor "ansi" "yellow"; yellow = mkColor "basic" "yellow";
orange = mkColor "ansi" "orange"; green = mkColor "basic" "green";
blue = mkColor "ansi" "blue"; cyan = mkColor "basic" "cyan";
magenta = mkColor "ansi" "magenta"; blue = mkColor "basic" "blue";
cyan = mkColor "ansi" "cyan"; magenta = mkColor "basic" "magenta";
pink = mkColor "basic" "magenta";
keywords = mkColor "syntax" "keywords"; keywords = mkColor "syntax" "keywords";
functions = mkColor "syntax" "functions"; functions = mkColor "syntax" "functions";

View File

@@ -7,11 +7,15 @@
pkgs, pkgs,
... ...
}: }:
let
hmConfig = config.home-manager.users.${user.name};
in
{ {
home-manager.users.${user.name} = { home-manager.users.${user.name} = {
imports = [ ./options.nix ]; imports = [ ./options.nix ];
programs.obsidian = { programs = {
obsidian = {
enable = true; enable = true;
sharedSettings = { sharedSettings = {
@@ -49,6 +53,7 @@
]; ];
plugins = [ plugins = [
(import ./plugins/style-settings.nix { inherit pkgs; })
{ {
pkg = import ./plugins/minimal-settings.nix { inherit pkgs; }; pkg = import ./plugins/minimal-settings.nix { inherit pkgs; };
extraFiles."data.json".source = (pkgs.formats.json { }).generate "data.json" { extraFiles."data.json".source = (pkgs.formats.json { }).generate "data.json" {
@@ -58,17 +63,16 @@
} }
]; ];
cssSnippets = { cssSnippets = [ ./snippets/file-explorer-separators.css ];
"file-explorer-separators".source = ./snippets/file-explorer-separators.css;
themes = [ (import ./themes/minimal.nix { inherit pkgs; }) ];
};
}; };
themes = [ matugen.settings.templates = builtins.mapAttrs (name: _: {
{ input_path = ./theme.json;
enable = true; output_path = "${user.home}/${name}/.obsidian/plugins/obsidian-style-settings/data.json";
pkg = import ./themes/minimal.nix { inherit pkgs; }; }) hmConfig.programs.obsidian.vaults;
}
];
};
}; };
home.persistence."/cache${user.home}".directories = [ ".config/obsidian" ]; home.persistence."/cache${user.home}".directories = [ ".config/obsidian" ];

View File

@@ -37,14 +37,18 @@ let
"workspaces" "workspaces"
"zk-prefixer" "zk-prefixer"
]; ];
toCssName = path: lib.strings.removeSuffix ".css" (builtins.baseNameOf path);
in in
{ {
options.programs.obsidian = options.programs.obsidian =
with lib; with lib;
with types; with types;
let let
checkCssPath = path: lib.filesystem.pathIsRegularFile path && lib.strings.hasSuffix ".css" path;
cssSnippetsOptions = cssSnippetsOptions =
{ name, config, ... }: { config, ... }:
{ {
options = { options = {
enable = mkOption { enable = mkOption {
@@ -55,22 +59,24 @@ in
name = mkOption { name = mkOption {
type = str; type = str;
defaultText = literalExpression "name"; defaultText = literalExpression "lib.strings.removeSuffix \".css\" (builtins.baseNameOf source)";
description = "Name of the snippet."; description = "Name of the snippet.";
}; };
source = mkOption { source = mkOption {
type = addCheck path (path: if path != null then lib.filesystem.pathIsRegularFile path else true); type = nullOr (addCheck path checkCssPath);
description = "Path of the source file."; description = "Path of the source file.";
default = null;
}; };
text = mkOption { text = mkOption {
type = str; type = nullOr str;
description = "Text of the file."; description = "Text of the file.";
default = null;
}; };
}; };
config.name = mkDefault name; config.name = mkDefault (toCssName config.source);
}; };
pluginsExtraFilesOptions = pluginsExtraFilesOptions =
@@ -78,13 +84,15 @@ in
{ {
options = { options = {
source = mkOption { source = mkOption {
type = path; type = nullOr path;
description = "Path of the source file or directory."; description = "Path of the source file or directory.";
default = null;
}; };
text = mkOption { text = mkOption {
type = str; type = nullOr str;
description = "Text of the file."; description = "Text of the file.";
default = null;
}; };
target = mkOption { target = mkOption {
@@ -94,7 +102,7 @@ in
}; };
}; };
config.target = mkIf (config ? text) (mkDefault name); config.target = mkDefault name;
}; };
pluginsOptions = pluginsOptions =
@@ -125,11 +133,8 @@ in
options = { options = {
enable = mkOption { enable = mkOption {
type = bool; type = bool;
default = false; default = true;
description = '' description = "Whether to set the theme as active.";
Whether to set the theme as active.
Only one theme can be active at a time.
'';
}; };
pkg = mkOption { pkg = mkOption {
@@ -184,7 +189,7 @@ in
cssSnippets = mkOption { cssSnippets = mkOption {
description = "CSS snippets to install."; description = "CSS snippets to install.";
type = raw; type = raw;
default = { }; default = [ ];
}; };
plugins = mkOption { plugins = mkOption {
@@ -240,19 +245,19 @@ in
cssSnippets = mkOption { cssSnippets = mkOption {
description = "CSS snippets to install."; description = "CSS snippets to install.";
type = attrsOf (submodule cssSnippetsOptions); type = listOf (either (addCheck path checkCssPath) (submodule cssSnippetsOptions));
default = cfg.sharedSettings.cssSnippets; default = cfg.sharedSettings.cssSnippets;
}; };
plugins = mkOption { plugins = mkOption {
description = "Community plugins to install and activate."; description = "Community plugins to install and activate.";
type = listOf (submodule pluginsOptions); type = listOf (either package (submodule pluginsOptions));
default = cfg.sharedSettings.plugins; default = cfg.sharedSettings.plugins;
}; };
themes = mkOption { themes = mkOption {
description = "Themes to install."; description = "Themes to install.";
type = listOf (submodule themesOptions); type = listOf (either package (submodule themesOptions));
default = cfg.sharedSettings.themes; default = cfg.sharedSettings.themes;
}; };
}; };
@@ -269,11 +274,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);
readDir = dir: builtins.attrNames (builtins.readDir dir); toPkg = item: if item ? pkg then item.pkg else item;
isEnabled = item: if item ? enable then item.enable else true;
getCssName = item: if builtins.isAttrs item then item.name else toCssName item;
getManifest = getManifest =
pkg: item:
let let
manifest = builtins.fromJSON (builtins.readFile "${pkg}/manifest.json"); manifest = builtins.fromJSON (builtins.readFile "${toPkg item}/manifest.json");
in in
manifest.id or manifest.name; manifest.id or manifest.name;
in in
@@ -294,20 +301,18 @@ in
name = "${vault.target}/.obsidian/appearance.json"; name = "${vault.target}/.obsidian/appearance.json";
value = value =
let let
enabledSnippets = builtins.filter (snippet: snippet.enable) ( enabledCssSnippets = builtins.filter isEnabled vault.settings.cssSnippets;
builtins.attrValues vault.settings.cssSnippets activeTheme =
); lib.lists.findSingle isEnabled null (throw "Only one theme can be enabled at a time.")
activeTheme = lib.lists.findSingle ( vault.settings.themes;
theme: theme.enable
) null (throw "Only one theme can be enabled at a time.") vault.settings.themes;
in in
{ {
source = (pkgs.formats.json { }).generate "appearance.json" ( source = (pkgs.formats.json { }).generate "appearance.json" (
vault.settings.appearance vault.settings.appearance
// { // {
enabledCssSnippets = builtins.map (snippet: snippet.name) enabledSnippets; enabledCssSnippets = builtins.map getCssName enabledCssSnippets;
} }
// lib.attrsets.optionalAttrs (activeTheme != null) { cssTheme = getManifest activeTheme.pkg; } // lib.attrsets.optionalAttrs (activeTheme != null) { cssTheme = getManifest activeTheme; }
); );
}; };
}; };
@@ -327,7 +332,7 @@ in
builtins.map (plugin: { builtins.map (plugin: {
name = plugin; name = plugin;
value = builtins.elem plugin vault.settings.corePlugins; value = builtins.elem plugin vault.settings.corePlugins;
}) corePlugins }) vault.settings.corePlugins
) )
); );
}; };
@@ -337,14 +342,14 @@ in
mkCommunityPlugins = mkCommunityPlugins =
vault: vault:
let let
enabledPlugins = builtins.filter (plugin: plugin.enable) vault.settings.plugins; enabledPlugins = builtins.filter isEnabled vault.settings.plugins;
in in
[ [
{ {
name = "${vault.target}/.obsidian/community-plugins.json"; name = "${vault.target}/.obsidian/community-plugins.json";
value = { value = {
source = (pkgs.formats.json { }).generate "community-plugins.json" ( source = (pkgs.formats.json { }).generate "community-plugins.json" (
builtins.map (plugin: getManifest plugin.pkg) enabledPlugins builtins.map getManifest enabledPlugins
); );
}; };
} }
@@ -362,34 +367,42 @@ in
*/ */
++ builtins.map ( ++ builtins.map (
plugin: plugin:
let
pkg = toPkg plugin;
files = builtins.attrNames (builtins.readDir pkg);
in
builtins.map (file: { builtins.map (file: {
name = "${vault.target}/.obsidian/plugins/${getManifest plugin.pkg}/${file}"; name = "${vault.target}/.obsidian/plugins/${getManifest plugin}/${file}";
value = { value = {
source = "${plugin.pkg}/${file}"; source = "${pkg}/${file}";
}; };
}) (readDir plugin.pkg) }) files
) vault.settings.plugins ) vault.settings.plugins
++ builtins.map ( ++ builtins.map (
plugin: plugin:
builtins.map (file: { builtins.map (file: {
name = "${vault.target}/.obsidian/plugins/${getManifest plugin.pkg}/${file.target}"; name = "${vault.target}/.obsidian/plugins/${getManifest plugin}/${file.target}";
value = if file ? source then { source = file.source; } else { text = file.text; }; value = if file.source != null then { inherit (file) source; } else { inherit (file) text; };
}) (builtins.attrValues plugin.extraFiles) }) (builtins.attrValues (plugin.extraFiles or { }))
) vault.settings.plugins; ) vault.settings.plugins;
mkCssSnippets = mkCssSnippets =
vault: vault:
builtins.map (snippet: { builtins.map (snippet: {
name = "${vault.target}/.obsidian/snippets/${snippet.name}.css"; name = "${vault.target}/.obsidian/snippets/${getCssName snippet}.css";
value = if snippet ? source then { source = snippet.source; } else { text = snippet.text; }; value =
}) (builtins.attrValues vault.settings.cssSnippets); if snippet ? source || snippet ? text then
if snippet.source != null then { inherit (snippet) source; } else { inherit (snippet) text; }
else
{ source = snippet; };
}) vault.settings.cssSnippets;
mkThemes = mkThemes =
vault: vault:
builtins.map (theme: { builtins.map (theme: {
name = "${vault.target}/.obsidian/themes/${getManifest theme.pkg}"; name = "${vault.target}/.obsidian/themes/${getManifest theme}";
value = { value = {
source = theme.pkg; source = toPkg theme;
}; };
}) vault.settings.themes; }) vault.settings.themes;
in in
@@ -416,6 +429,31 @@ in
} // (lib.attrsets.optionalAttrs ((builtins.length vaults) == 1) { open = true; }); } // (lib.attrsets.optionalAttrs ((builtins.length vaults) == 1) { open = true; });
}) vaults }) vaults
); );
updateDisabled = true;
}; };
assertions = [
{
assertion = builtins.all (
vault:
builtins.all (
snippet: (!snippet ? source && !snippet ? text) || (snippet.source == null || snippet.text == null)
) vault.settings.cssSnippets
) (builtins.attrValues cfg.vaults);
message = "Only one of `source` and `text` must be set";
}
{
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.attrValues cfg.vaults);
message = "Only one of `source` and `text` must be set";
}
];
}; };
} }

View File

@@ -4,14 +4,16 @@
}: }:
let let
version = "8.0.2"; version = "8.0.2";
author = "kepano";
repo = "obsidian-minimal-settings";
css = builtins.fetchurl { css = builtins.fetchurl {
url = "https://github.com/kepano/obsidian-minimal-settings/releases/download/${version}/styles.css"; url = "https://github.com/${author}/${repo}/releases/download/${version}/styles.css";
sha256 = "sha256:07nkr3sm7dkg8hbmqn45zyaafcblbbvh2s5qlhjh2x0zmi6kmx45"; sha256 = "sha256:07nkr3sm7dkg8hbmqn45zyaafcblbbvh2s5qlhjh2x0zmi6kmx45";
}; };
js = builtins.fetchurl { js = builtins.fetchurl {
url = "https://github.com/kepano/obsidian-minimal-settings/releases/download/${version}/main.js"; url = "https://github.com/${author}/${repo}/releases/download/${version}/main.js";
sha256 = "sha256:0s935p4890mk2b15ffqxyggfcp9p60y1k1121ayni4hh1iinnkcv"; sha256 = "sha256:0s935p4890mk2b15ffqxyggfcp9p60y1k1121ayni4hh1iinnkcv";
}; };
in in
@@ -19,7 +21,7 @@ pkgs.stdenv.mkDerivation {
name = "obsidian.plugins.minimal-settings"; name = "obsidian.plugins.minimal-settings";
src = builtins.fetchurl { src = builtins.fetchurl {
url = "https://github.com/kepano/obsidian-minimal-settings/releases/download/${version}/manifest.json"; url = "https://github.com/${author}/${repo}/releases/download/${version}/manifest.json";
sha256 = "sha256:1akim1ymm3za9h3h2jy82gc7wviwxvv9kc8rqmp69v9y3h1dn10z"; sha256 = "sha256:1akim1ymm3za9h3h2jy82gc7wviwxvv9kc8rqmp69v9y3h1dn10z";
}; };

View File

@@ -0,0 +1,36 @@
{
pkgs ? import <nixpkgs> { },
...
}:
let
version = "1.0.8";
author = "mgmeyers";
repo = "obsidian-style-settings";
css = builtins.fetchurl {
url = "https://github.com/${author}/${repo}/releases/download/${version}/styles.css";
sha256 = "sha256:029kza0ja1hgw8fmknnphr65gvkanykhx9wb4ig05n8ybrg3aqdl";
};
js = builtins.fetchurl {
url = "https://github.com/${author}/${repo}/releases/download/${version}/main.js";
sha256 = "sha256:15wdwv50wfhk7h1wgl4wjk975pihsjjrzlyh9a30hjpjc15sh9xy";
};
in
pkgs.stdenv.mkDerivation {
name = "obsidian.plugins.style-settings";
src = builtins.fetchurl {
url = "https://github.com/${author}/${repo}/releases/download/${version}/manifest.json";
sha256 = "sha256:14bkhnh13cgph51c029jy95dm70cvj1yxqmchkmv1pz46ws2r7hf";
};
phases = [ "installPhase" ];
installPhase = ''
mkdir -p $out
cp $src $out/manifest.json
cp ${css} $out/styles.css
cp ${js} $out/main.js
'';
}

View File

@@ -0,0 +1,88 @@
{
"minimal-style@@base@@light": "{{colors.surface.light.hex}}",
"minimal-style@@base@@dark": "{{colors.surface.dark.hex}}",
"minimal-style@@bg1@@light": "{{colors.surface.light.hex}}",
"minimal-style@@bg1@@dark": "{{colors.surface.dark.hex}}",
"minimal-style@@bg2@@light": "{{colors.surface_container.light.hex}}",
"minimal-style@@bg2@@dark": "{{colors.surface_container.dark.hex}}",
"minimal-style@@bg3@@light": "{{colors.surface_container_highest.light.hex}}",
"minimal-style@@bg3@@dark": "{{colors.surface_container_highest.dark.hex}}",
"minimal-style@@ui1@@light": "{{colors.outline_variant.light.hex}}",
"minimal-style@@ui1@@dark": "{{colors.outline_variant.dark.hex}}",
"minimal-style@@ui2@@light": "{{colors.outline.light.hex}}",
"minimal-style@@ui2@@dark": "{{colors.outline.dark.hex}}",
"minimal-style@@ui3@@light": "{{colors.primary.light.hex}}",
"minimal-style@@ui3@@dark": "{{colors.primary.dark.hex}}",
"minimal-style@@ax1@@light": "{{colors.primary.light.hex}}",
"minimal-style@@ax1@@dark": "{{colors.primary.dark.hex}}",
"minimal-style@@ax2@@light": "{{colors.on_primary_container.light.hex}}",
"minimal-style@@ax2@@dark": "{{colors.on_primary_container.dark.hex}}",
"minimal-style@@ax3@@light": "{{colors.primary_container.light.hex}}",
"minimal-style@@ax3@@dark": "{{colors.primary_container.dark.hex}}",
"minimal-style@@sp1@@light": "{{colors.on_primary_container.light.hex}}",
"minimal-style@@sp1@@dark": "{{colors.on_primary_container.dark.hex}}",
"minimal-style@@color-red@@light": "{{colors.red.light.hex}}",
"minimal-style@@color-red@@dark": "{{colors.red.dark.hex}}",
"minimal-style@@color-orange@@light": "{{colors.orange.light.hex}}",
"minimal-style@@color-orange@@dark": "{{colors.orange.dark.hex}}",
"minimal-style@@color-yellow@@light": "{{colors.yellow.light.hex}}",
"minimal-style@@color-yellow@@dark": "{{colors.yellow.dark.hex}}",
"minimal-style@@color-green@@light": "{{colors.green.light.hex}}",
"minimal-style@@color-green@@dark": "{{colors.green.dark.hex}}",
"minimal-style@@color-cyan@@light": "{{colors.cyan.light.hex}}",
"minimal-style@@color-cyan@@dark": "{{colors.cyan.dark.hex}}",
"minimal-style@@color-blue@@light": "{{colors.blue.light.hex}}",
"minimal-style@@color-blue@@dark": "{{colors.blue.dark.hex}}",
"minimal-style@@color-purple@@light": "{{colors.magenta.light.hex}}",
"minimal-style@@color-purple@@dark": "{{colors.magenta.dark.hex}}",
"minimal-style@@color-pink@@light": "{{colors.pink.light.hex}}",
"minimal-style@@color-pink@@dark": "{{colors.pink.dark.hex}}",
"minimal-style@@blockquote-color@@light": "{{colors.on_surface_variant.light.hex}}",
"minimal-style@@blockquote-color@@dark": "{{colors.on_surface_variant.dark.hex}}",
"minimal-style@@canvas-dot-pattern@@light": "{{colors.outline_variant.light.hex}}",
"minimal-style@@canvas-dot-pattern@@dark": "{{colors.outline_variant.dark.hex}}",
"minimal-style@@tag-color@@light": "{{colors.on_primary_container.light.hex}}",
"minimal-style@@tag-color@@dark": "{{colors.on_primary_container.dark.hex}}",
"minimal-style@@tag-background@@light": "{{colors.primary_container.light.hex}}",
"minimal-style@@tag-background@@dark": "{{colors.primary_container.dark.hex}}",
"minimal-style@@tag-background-hover@@light": "{{colors.on_primary.light.hex}}",
"minimal-style@@tag-background-hover@@dark": "{{colors.on_primary.dark.hex}}",
"minimal-style@@tx1@@light": "{{colors.on_surface.light.hex}}",
"minimal-style@@tx1@@dark": "{{colors.on_surface.dark.hex}}",
"minimal-style@@tx2@@light": "{{colors.on_surface_variant.light.hex}}",
"minimal-style@@tx2@@dark": "{{colors.on_surface_variant.dark.hex}}",
"minimal-style@@tx3@@light": "{{colors.outline.light.hex}}",
"minimal-style@@tx3@@dark": "{{colors.outline.dark.hex}}",
"minimal-style@@hl1@@light": "{{colors.primary_container.light.hex}}",
"minimal-style@@hl1@@dark": "{{colors.primary_container.dark.hex}}",
"minimal-style@@text-formattin@@light": "{{colors.outline_variant.light.hex}}",
"minimal-style@@text-formattin@@dark": "{{colors.outline_variant.dark.hex}}",
"minimal-style@@code-comment@@light": "{{colors.outline.light.hex}}",
"minimal-style@@code-comment@@dark": "{{colors.outline.dark.hex}}",
"minimal-style@@code-function@@light": "{{colors.functions.light.hex}}",
"minimal-style@@code-function@@dark": "{{colors.functions.dark.hex}}",
"minimal-style@@code-keyword@@light": "{{colors.keywords.light.hex}}",
"minimal-style@@code-keyword@@dark": "{{colors.keywords.dark.hex}}",
"minimal-style@@code-important@@light": "{{colors.info.light.hex}}",
"minimal-style@@code-important@@dark": "{{colors.info.dark.hex}}",
"minimal-style@@code-property@@light": "{{colors.properties.light.hex}}",
"minimal-style@@code-property@@dark": "{{colors.properties.dark.hex}}",
"minimal-style@@code-string@@light": "{{colors.strings.light.hex}}",
"minimal-style@@code-string@@dark": "{{colors.strings.dark.hex}}",
"minimal-style@@code-tag@@light": "{{colors.properties.light.hex}}",
"minimal-style@@code-tag@@dark": "{{colors.properties.dark.hex}}",
"minimal-style@@code-value@@light": "{{colors.numbers.light.hex}}",
"minimal-style@@code-value@@dark": "{{colors.numbers.dark.hex}}",
"minimal-style@@image-radius": "{{custom.radius}}",
"minimal-style@@blockquote-border-thickness": 4,
"minimal-style@@minimal-code-scroll": true,
"minimal-style@@h1-l": true,
"minimal-style@@h2-l": true,
"minimal-style@@image-muted": 1,
"minimal-style@@active-line-on": true,
"minimal-style@@minimal-strike-lists": true,
"minimal-style@@metadata-heading-off": true,
"minimal-style@@metadata-icons-off": true,
"minimal-style@@hide-help": true,
"minimal-style@@row-hover": true
}

View File

@@ -197,7 +197,7 @@ in
}; };
}; };
ansi = { basic = {
blend = mkOption { blend = mkOption {
type = bool; type = bool;
default = true; default = true;
@@ -210,10 +210,10 @@ in
description = "The color of red."; description = "The color of red.";
}; };
green = mkOption { orange = mkOption {
type = str; type = str;
default = "#00ff00"; default = "#ff8000";
description = "The color of green."; description = "The color of orange.";
}; };
yellow = mkOption { yellow = mkOption {
@@ -222,10 +222,16 @@ in
description = "The color of yellow."; description = "The color of yellow.";
}; };
orange = mkOption { green = mkOption {
type = str; type = str;
default = "#ff8000"; default = "#00ff00";
description = "The color of orange."; description = "The color of green.";
};
cyan = mkOption {
type = str;
default = "#00ffff";
description = "The color of cyan.";
}; };
blue = mkOption { blue = mkOption {
@@ -240,10 +246,10 @@ in
description = "The color of magenta."; description = "The color of magenta.";
}; };
cyan = mkOption { pink = mkOption {
type = str; type = str;
default = "#00ffff"; default = "#ffc0cb";
description = "The color of cyan."; description = "The color of pink.";
}; };
}; };
}; };