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",
}:
{ config, lib, ... }:
{
config,
lib,
pkgs,
...
}:
let
hmConfig = config.home-manager.users.${user.name};
in
@@ -12,6 +17,7 @@ in
xdg = {
enable = true;
mimeApps.enable = true;
portal.extraPortals = with pkgs; [ xdg-desktop-portal-gtk ];
userDirs = {
enable = true;

View File

@@ -20,10 +20,10 @@ color6 {{colors.cyan.default.hex}}
color7 {{colors.on_surface.default.hex}}
color8 {{colors.outline_variant.default.hex}}
color9 {{ colors.red.default.hex | set_lightness: 5.0 }}
color10 {{ colors.green.default.hex | set_lightness: 5.0 }}
color11 {{ colors.yellow.default.hex | set_lightness: 5.0 }}
color12 {{ colors.blue.default.hex | set_lightness: 5.0 }}
color13 {{ colors.magenta.default.hex | set_lightness: 5.0 }}
color14 {{ colors.cyan.default.hex | set_lightness: 5.0 }}
color9 {{colors.red.default.hex | set_lightness: 5.0}}
color10 {{colors.green.default.hex | set_lightness: 5.0}}
color11 {{colors.yellow.default.hex | set_lightness: 5.0}}
color12 {{colors.blue.default.hex | set_lightness: 5.0}}
color13 {{colors.magenta.default.hex | set_lightness: 5.0}}
color14 {{colors.cyan.default.hex | set_lightness: 5.0}}
color15 {{colors.on_surface_variant.default.hex}}

View File

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

View File

@@ -7,68 +7,72 @@
pkgs,
...
}:
let
hmConfig = config.home-manager.users.${user.name};
in
{
home-manager.users.${user.name} = {
imports = [ ./options.nix ];
programs.obsidian = {
enable = true;
programs = {
obsidian = {
enable = true;
sharedSettings = {
app = {
defaultViewMode = "preview";
livePreview = false;
readableLineLength = false;
showLineNumber = true;
tabSize = 2;
promptDelete = false;
trashOption = "local";
alwaysUpdateLinks = true;
newFileLocation = "folder";
newFileFolderPath = "inbox";
newLinkFormat = "absolute";
showUnsupportedFiles = true;
attachmentFolderPath = "./assets";
sharedSettings = {
app = {
defaultViewMode = "preview";
livePreview = false;
readableLineLength = false;
showLineNumber = true;
tabSize = 2;
promptDelete = false;
trashOption = "local";
alwaysUpdateLinks = true;
newFileLocation = "folder";
newFileFolderPath = "inbox";
newLinkFormat = "absolute";
showUnsupportedFiles = true;
attachmentFolderPath = "./assets";
};
corePlugins = [
"bookmarks"
"canvas"
"command-palette"
"editor-status"
"file-explorer"
"global-search"
"graph"
"note-composer"
"outgoing-link"
"outline"
"page-preview"
"slash-command"
"switcher"
"tag-pane"
];
plugins = [
(import ./plugins/style-settings.nix { inherit pkgs; })
{
pkg = import ./plugins/minimal-settings.nix { inherit pkgs; };
extraFiles."data.json".source = (pkgs.formats.json { }).generate "data.json" {
labeledNav = true;
editorFont = "var(--font-monospace)";
};
}
];
cssSnippets = [ ./snippets/file-explorer-separators.css ];
themes = [ (import ./themes/minimal.nix { inherit pkgs; }) ];
};
corePlugins = [
"bookmarks"
"canvas"
"command-palette"
"editor-status"
"file-explorer"
"global-search"
"graph"
"note-composer"
"outgoing-link"
"outline"
"page-preview"
"slash-command"
"switcher"
"tag-pane"
];
plugins = [
{
pkg = import ./plugins/minimal-settings.nix { inherit pkgs; };
extraFiles."data.json".source = (pkgs.formats.json { }).generate "data.json" {
labeledNav = true;
editorFont = "var(--font-monospace)";
};
}
];
cssSnippets = {
"file-explorer-separators".source = ./snippets/file-explorer-separators.css;
};
themes = [
{
enable = true;
pkg = import ./themes/minimal.nix { inherit pkgs; };
}
];
};
matugen.settings.templates = builtins.mapAttrs (name: _: {
input_path = ./theme.json;
output_path = "${user.home}/${name}/.obsidian/plugins/obsidian-style-settings/data.json";
}) hmConfig.programs.obsidian.vaults;
};
home.persistence."/cache${user.home}".directories = [ ".config/obsidian" ];

View File

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

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