421 lines
18 KiB
Nix
421 lines
18 KiB
Nix
# Obsidian (home-manager only): the app, one vault and its community plugins,
|
|
# configured declaratively through home-manager's programs.obsidian.
|
|
#
|
|
# The vault is ~/Documents/Notes, backed up with git to the owner's Gitea by the
|
|
# obsidian-git plugin. Everything under .obsidian/ comes from Nix and is not
|
|
# committed:
|
|
# - app.json, appearance.json, core-plugins.json, community-plugins.json, the
|
|
# core plugin files (daily-notes.json) and the Stylix CSS snippet are links
|
|
# into the store. Obsidian cannot write to them, so a setting changed in its
|
|
# settings window does not stick: change it here instead.
|
|
# - Each plugin directory holds links to the pinned release files. The
|
|
# data.json of the few plugins that get settings here is a plain file,
|
|
# merged at activation (see pluginSettings), not a link: Calendar rewrites
|
|
# its data.json every time it loads, which a link into the store would make
|
|
# fail. The other plugins create their own data.json.
|
|
# What is not in the vault and so cannot be declared: whether community plugins
|
|
# are trusted (the first time the vault opens Obsidian asks, "Turn on community
|
|
# plugins") and the spellcheck languages (Settings -> Editor), both kept in
|
|
# Obsidian's own browser storage.
|
|
#
|
|
# Colours and fonts come from Stylix (the `obsidian` target, switched on for the
|
|
# vault in theme/stylix.nix): a CSS snippet with the palette, the UI and
|
|
# monospace fonts. Only the dark/light base scheme is chosen here. A host
|
|
# importing this aspect imports `theme` too.
|
|
#
|
|
# Claude Code can read and search the vault: ai/claude-code.nix adds every
|
|
# enabled vault to its additional directories. A short CLAUDE.md in the
|
|
# vault tells it the conventions. There is no Obsidian MCP server: nixpkgs has
|
|
# none, the popular ones go through the Local REST API plugin with an API key,
|
|
# and plain file access already covers reading and searching Markdown.
|
|
{
|
|
flake.modules.homeManager.obsidian =
|
|
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
osConfig,
|
|
...
|
|
}:
|
|
let
|
|
# The attribute name must be listed in stylix.targets.obsidian.vaultNames
|
|
# (theme/stylix.nix; checked by the assertion below). The target is
|
|
# relative to $HOME: Documents is a btrfs subvolume on the data SSD.
|
|
vaultName = "Notes";
|
|
vaultTarget = "Documents/${vaultName}";
|
|
vaultDir = "${config.home.homeDirectory}/${vaultTarget}";
|
|
|
|
# Created empty on Gitea by hand; the first push by obsidian-git fills it.
|
|
remote = "gitea@git.faumaray.ru:faumaray/Notes.git";
|
|
|
|
# Community plugins: pinned GitHub release assets, none of them is in
|
|
# nixpkgs. The attribute name is the plugin id (manifest.json "id", which
|
|
# is also its directory name under .obsidian/plugins; the build checks
|
|
# it). To update one: change `version`, set its hashes to lib.fakeHash and
|
|
# copy the real ones from the build error (or
|
|
# `nix store prefetch-file <asset url>`). Not every release has a
|
|
# styles.css. Each release's minAppVersion must stay at or below the
|
|
# Obsidian in nixpkgs. Dataview's 0.5.70 release still says 0.5.68 in its
|
|
# manifest.json; that is upstream's, not a mistake here.
|
|
plugins = {
|
|
# Queries over notes: tables and lists from frontmatter and inline fields.
|
|
dataview = {
|
|
repo = "blacksmithgu/obsidian-dataview";
|
|
version = "0.5.70";
|
|
hashes = {
|
|
"main.js" = "sha256-a7HPcBCvrYMOc1dfyg4r+9MnnFYuPZ0k8tL0UWHrfQA=";
|
|
"manifest.json" = "sha256-kjXbRxEtqBuFWRx57LmuJXTl5yIHBW6XZHL5BhYoYYU=";
|
|
"styles.css" = "sha256-MwbdkDLgD5ibpyM6N/0lW8TT9DQM7mYXYulS8/aqHek=";
|
|
};
|
|
};
|
|
# Templates with logic (`<% tp.date.now() %>`), for notes made by hand.
|
|
templater-obsidian = {
|
|
repo = "SilentVoid13/Templater";
|
|
version = "2.26.0";
|
|
hashes = {
|
|
"main.js" = "sha256-Cs1Fz9s6czfivvURaZvB+BncZGRa00gN8zV51C0ty6o=";
|
|
"manifest.json" = "sha256-kcn6hRAIL/+gs9AiqsSYbjs5IpWxEm6Efq1+1yiRabg=";
|
|
"styles.css" = "sha256-Z6bdLR1t7coSh8M0yohOxBlkM/ccpHOIoL0+rBTPi18=";
|
|
};
|
|
};
|
|
# Month calendar next to the daily notes. Upstream's last release is
|
|
# from 2021 and it still works; there is no maintained drop-in.
|
|
calendar = {
|
|
repo = "liamcain/obsidian-calendar-plugin";
|
|
version = "1.5.10";
|
|
hashes = {
|
|
"main.js" = "sha256-f7M56c+f2+WoAforirhbNmtbN3f70ZPLyHKLwncR0SU=";
|
|
"manifest.json" = "sha256-8+lYEzhkhRK6oS1bRYSQ9/02eRj3vba9hhcc5Xvn0Is=";
|
|
};
|
|
};
|
|
# Tasks across the vault with due dates, recurrence and queries.
|
|
obsidian-tasks-plugin = {
|
|
repo = "obsidian-tasks-group/obsidian-tasks";
|
|
version = "8.6.0";
|
|
hashes = {
|
|
"main.js" = "sha256-UA+BBtBd20g7v+wTXKx5SAIr9rpzhtGFGyj00IeGbo8=";
|
|
"manifest.json" = "sha256-LvyI356XMkc2DUhrQgeRwmbIgkUWkZMDuUjQGS4VkSc=";
|
|
"styles.css" = "sha256-1w2OvUH8I7/V1Zhzsak+2VVLFUVGo+Y3vU4ELmLRzyM=";
|
|
};
|
|
};
|
|
# Drawings and diagrams stored as Markdown files (Excalidraw/ by default).
|
|
obsidian-excalidraw-plugin = {
|
|
repo = "zsviczian/obsidian-excalidraw-plugin";
|
|
version = "2.29.0";
|
|
hashes = {
|
|
"main.js" = "sha256-TaIISk6v59MoSE+ldCAEufuZA0bEyE/ekkuIWl7MHBc=";
|
|
"manifest.json" = "sha256-SIC4hcUGQ++EjTHOqCl3bKLpZ0c1Ou4zTXHodfedMcA=";
|
|
"styles.css" = "sha256-Fz6cFhoBxTs8FzNE4CPeTTJ/0GWOR2lhtGsOapMRfe0=";
|
|
};
|
|
};
|
|
|
|
# Code-focused set. Tables: Tab/Enter move between cells and reformat
|
|
# the table as it is edited (Markdown tables are tedious by hand).
|
|
table-editor-obsidian = {
|
|
repo = "tgrosinger/advanced-tables-obsidian";
|
|
version = "0.23.2";
|
|
hashes = {
|
|
"main.js" = "sha256-z13U3b3evvaMyZzZOog+M4lcfxI9BLxdEQbqbjOLp5E=";
|
|
"manifest.json" = "sha256-aYtPd0ReB9iH8zRQ6vUzoo4Jm3tIP2QvqIM2L/vY/+k=";
|
|
"styles.css" = "sha256-I/ow128Rf9PRYkxMLm3e2r+AmSOZawU0iV+CVOpqOfc=";
|
|
};
|
|
};
|
|
# Formatter for notes (YAML, headings, spacing), run by hand or on save.
|
|
obsidian-linter = {
|
|
repo = "platers/obsidian-linter";
|
|
version = "1.34.2";
|
|
hashes = {
|
|
"main.js" = "sha256-ova0R27tYWq6ZOlT6t2ut58h16jbB1nrsHD70CgUIYs=";
|
|
"manifest.json" = "sha256-4Cpa3FPccf7ewVhBNfvToCS1aYQ0y79socu5sSnuduA=";
|
|
"styles.css" = "sha256-rto6ZoBw3h5IZQ0WE6lr0Bjgt7OqX6vchSY1ifEZhjQ=";
|
|
};
|
|
};
|
|
# Syntax highlighting of fenced code blocks in reading and editing view
|
|
# (Shiki, 200+ languages), line numbers, line highlights, copy button.
|
|
# Chosen over Code Styler, whose last commit is from January 2025 and
|
|
# last release from February 2024; this one released in April 2026. Its
|
|
# default theme follows the Obsidian colours, so Stylix reaches it.
|
|
shiki-highlighter = {
|
|
repo = "mProjectsCode/obsidian-shiki-plugin";
|
|
version = "0.7.7";
|
|
hashes = {
|
|
"main.js" = "sha256-uCv60MqhG5GruQFMNHtKn675V1vWPXWxKbsCeqteYMA=";
|
|
"manifest.json" = "sha256-viPX7+Ea/NEvkpucdByYs+8zWTfPy6H3YrQ95sd/15E=";
|
|
"styles.css" = "sha256-zKx7aLmW251TJky3iWiFebFCtHJRQiEK9U8xHptmVSU=";
|
|
};
|
|
};
|
|
|
|
# Backup and sync of the vault with git.
|
|
obsidian-git = {
|
|
repo = "Vinzent03/obsidian-git";
|
|
version = "2.42.0";
|
|
hashes = {
|
|
"main.js" = "sha256-SW2xSLzqQWn0VeI0uwLwj4xQwxfArVr947J8CQTa8TM=";
|
|
"manifest.json" = "sha256-etmOjM4VfphGtHlBxqfLmwIrydXG0ReCKQ56ehZLRw0=";
|
|
"styles.css" = "sha256-8wrSykL+/jtwTFSPd0fShcIDj6TOkGAeaP5v1mBJQFI=";
|
|
};
|
|
};
|
|
};
|
|
|
|
# A plugin directory laid out as Obsidian wants it: the release files.
|
|
# home-manager would read manifest.json at evaluation (import from
|
|
# derivation) to learn the id unless the package says it, hence
|
|
# `manifestId`.
|
|
mkPlugin =
|
|
id:
|
|
{
|
|
repo,
|
|
version,
|
|
hashes,
|
|
}:
|
|
pkgs.runCommand "obsidian-plugin-${id}-${version}"
|
|
{
|
|
nativeBuildInputs = [ pkgs.jq ];
|
|
passthru.manifestId = id;
|
|
}
|
|
''
|
|
mkdir -p $out
|
|
${lib.concatStrings (
|
|
lib.mapAttrsToList (file: hash: ''
|
|
cp ${
|
|
pkgs.fetchurl {
|
|
url = "https://github.com/${repo}/releases/download/${version}/${file}";
|
|
inherit hash;
|
|
}
|
|
} $out/${file}
|
|
'') hashes
|
|
)}
|
|
if ! jq -e --arg id ${lib.escapeShellArg id} '.id == $id' $out/manifest.json > /dev/null; then
|
|
echo "manifest.json of ${id} ${version} has id $(jq -r .id $out/manifest.json)" >&2
|
|
exit 1
|
|
fi
|
|
'';
|
|
|
|
# Commit message of the automatic backups, and of manual commits.
|
|
commitMessage = "vault backup: {{hostname}} {{date}}, {{numFiles}} file(s)";
|
|
|
|
# data.json of the plugins whose settings are declared here (the others
|
|
# run on their defaults). Declared keys win on every switch, anything else
|
|
# the plugin keeps in the file survives. Keys are the plugin's own; check
|
|
# them against its source when updating the plugin.
|
|
pluginSettings = {
|
|
obsidian-git = {
|
|
# Pull when the vault opens. Until the first push gives the branch an
|
|
# upstream the plugin skips this (git's push.autoSetupRemote is on).
|
|
autoPullOnBoot = true;
|
|
# Every 10 minutes: commit any changes, pull (so what another device
|
|
# pushed arrives too), push what is unpushed. No empty commits.
|
|
autoSaveInterval = 10;
|
|
autoCommitMessage = commitMessage;
|
|
inherit commitMessage;
|
|
# No notice every 10 minutes saying there was nothing to commit.
|
|
disablePopupsForNoChanges = true;
|
|
};
|
|
templater-obsidian = {
|
|
# Schema version 2; without it Templater treats the file as the old
|
|
# format and migrates (rewrites) it.
|
|
data_version = 2;
|
|
templates_folder = "Templates";
|
|
};
|
|
# Weeks start on Monday (the default follows the en_US locale: Sunday).
|
|
calendar.weekStart = "monday";
|
|
};
|
|
|
|
# Files written once when the vault is created (see obsidianVault below).
|
|
# They are regular files in the repository, so a link into the store would
|
|
# be committed as one.
|
|
gitignore = pkgs.writeText "obsidian-vault-gitignore" ''
|
|
# Generated by Nix (home-manager) and the same on every machine.
|
|
.obsidian/
|
|
.trash/
|
|
|
|
# OS junk.
|
|
.DS_Store
|
|
Thumbs.db
|
|
desktop.ini
|
|
.directory
|
|
'';
|
|
|
|
# Core variables ({{title}}, {{date}}), which the Daily notes plugin fills
|
|
# in itself; Templater's `<% %>` syntax is not used here, because
|
|
# Templater triggers on new files only when that is enabled on the device
|
|
# (a per-device setting it keeps outside the vault).
|
|
dailyTemplate = pkgs.writeText "obsidian-vault-daily-template" ''
|
|
---
|
|
tags:
|
|
- daily
|
|
---
|
|
|
|
# {{title}}
|
|
|
|
## Tasks
|
|
|
|
## Notes
|
|
'';
|
|
|
|
vaultClaudeMd = pkgs.writeText "obsidian-vault-claude-md" ''
|
|
# Notes vault
|
|
|
|
Personal Obsidian vault: Markdown files, backed up to Gitea by the
|
|
obsidian-git plugin (an automatic commit every 10 minutes). Read and
|
|
search it freely; change notes only when asked.
|
|
|
|
## Layout
|
|
|
|
- `Inbox/`: new notes land here; the owner files them into topic folders.
|
|
- `Daily/YYYY-MM-DD.md`: daily notes, made from `Templates/Daily.md`.
|
|
- `Templates/`: the Templater folder and the daily note template.
|
|
- `Attachments/`: images and other files pasted into notes.
|
|
- `Excalidraw/`: drawings (`*.excalidraw.md`), not meant to be edited as text.
|
|
- Other folders are topics chosen by the owner.
|
|
|
|
## Conventions
|
|
|
|
- Links are wikilinks, `[[Note name]]`; keep file names unique so the
|
|
short form works.
|
|
- Metadata is YAML frontmatter; tags are lower case and nested with a
|
|
slash, for example `project/nixos`.
|
|
- Tasks use the Tasks plugin format: `- [ ] text 📅 2026-12-31`.
|
|
- Dataview queries live in ```` ```dataview ```` blocks; leave them as they are.
|
|
- Notes are in English or Russian; keep the language of the note.
|
|
- Make small edits. Do not reformat or rewrite whole notes.
|
|
|
|
## Never touch
|
|
|
|
- `.obsidian/`: generated by Nix and read-only; change it in the NixOS
|
|
configuration, not here.
|
|
- `.git/`: do not commit or push; obsidian-git does that.
|
|
'';
|
|
in
|
|
{
|
|
assertions = [
|
|
{
|
|
assertion = builtins.elem vaultName config.stylix.targets.obsidian.vaultNames;
|
|
message = ''
|
|
The Obsidian vault "${vaultName}" (desktop/obsidian.nix) gets its
|
|
colours and fonts from Stylix only if it is listed in
|
|
stylix.targets.obsidian.vaultNames (theme/stylix.nix).
|
|
'';
|
|
}
|
|
];
|
|
|
|
programs.obsidian = {
|
|
enable = true;
|
|
|
|
vaults.${vaultName} = {
|
|
target = vaultTarget;
|
|
|
|
settings = {
|
|
app = {
|
|
# New notes go to Inbox/ (created below; Obsidian falls back to
|
|
# the vault root while the folder is missing). Pasted files go to
|
|
# one Attachments/ folder instead of cluttering the notes.
|
|
newFileLocation = "folder";
|
|
newFileFolderPath = "Inbox";
|
|
attachmentFolderPath = "Attachments";
|
|
# Renaming or moving a note rewrites the links to it, without asking.
|
|
alwaysUpdateLinks = true;
|
|
# Vim keybindings in the editor: the owner lives in Neovim. Set
|
|
# to false for the plain editor.
|
|
vimMode = true;
|
|
readableLineLength = true;
|
|
# The spellcheck languages (en, ru) are a per-device setting in
|
|
# Settings -> Editor; they cannot be declared.
|
|
spellcheck = true;
|
|
};
|
|
|
|
# Stylix adds the fonts and the colour snippet; this picks the base
|
|
# scheme the snippet is written for (it follows the Stylix polarity).
|
|
appearance.theme = if osConfig.stylix.polarity == "dark" then "obsidian" else "moonstone";
|
|
|
|
# Core plugins: navigation (files, search, quick switcher, backlinks,
|
|
# outgoing links, outline, graph, bookmarks, tags, page preview),
|
|
# editing (properties, note composer, command palette, status bar,
|
|
# word count), daily notes, canvas and file recovery. The core
|
|
# Templates plugin is off: Templater replaces it.
|
|
corePlugins = [
|
|
"file-explorer"
|
|
"global-search"
|
|
"switcher"
|
|
"backlink"
|
|
"outgoing-link"
|
|
"outline"
|
|
"graph"
|
|
"bookmarks"
|
|
"tag-pane"
|
|
"page-preview"
|
|
"properties"
|
|
"note-composer"
|
|
"command-palette"
|
|
"editor-status"
|
|
"word-count"
|
|
"canvas"
|
|
"file-recovery"
|
|
{
|
|
name = "daily-notes";
|
|
settings = {
|
|
folder = "Daily";
|
|
format = "YYYY-MM-DD";
|
|
template = "Templates/Daily";
|
|
};
|
|
}
|
|
];
|
|
|
|
communityPlugins = lib.mapAttrsToList mkPlugin plugins;
|
|
};
|
|
};
|
|
};
|
|
|
|
# data.json of the plugins: see pluginSettings. After linkGeneration, which
|
|
# creates the plugin directories.
|
|
home.activation.obsidianPluginSettings = lib.hm.dag.entryAfter [ "linkGeneration" ] (
|
|
lib.concatStringsSep "\n" (
|
|
lib.mapAttrsToList (
|
|
id: settings:
|
|
lib.hm.generators.mkImpureConfigMerger {
|
|
inherit pkgs;
|
|
format = "json";
|
|
empty = "{}";
|
|
jqOperation = "$dynamic * $static";
|
|
path = "${vaultDir}/.obsidian/plugins/${id}/data.json";
|
|
staticSettings = (pkgs.formats.json { }).generate "obsidian-${id}-data.json" settings;
|
|
verboseMsg = "Merging the Obsidian ${id} settings into its data.json";
|
|
}
|
|
) pluginSettings
|
|
)
|
|
);
|
|
|
|
# The vault as a git repository, once. The existence of .git marks it as
|
|
# done: an existing repository (or one cloned there beforehand) is never
|
|
# touched, nor are its remotes. Files are written before `git init`, so a
|
|
# switch that fails half way is finished by the next one. Never pushes.
|
|
# On a second machine the vault already exists on Gitea: instead of
|
|
# waiting for this, clone it into place first (git clone), or run
|
|
# `git fetch && git checkout -f -B main origin/main` in the new vault to
|
|
# replace the files written here.
|
|
home.activation.obsidianVault = lib.hm.dag.entryAfter [ "linkGeneration" ] ''
|
|
vault="$HOME/${vaultTarget}"
|
|
|
|
if [ ! -e "$vault/.git" ]; then
|
|
# A folder that is missing makes the Daily notes plugin refuse to
|
|
# create today's note and new notes fall back to the vault root; git
|
|
# keeps empty folders only with a file in them.
|
|
run mkdir -p "$vault/Inbox" "$vault/Daily" "$vault/Templates"
|
|
run touch "$vault/Inbox/.gitkeep" "$vault/Daily/.gitkeep"
|
|
|
|
obsidian_seed() {
|
|
if [ ! -e "$2" ]; then
|
|
run install -m 0644 "$1" "$2"
|
|
fi
|
|
}
|
|
obsidian_seed ${gitignore} "$vault/.gitignore"
|
|
obsidian_seed ${vaultClaudeMd} "$vault/CLAUDE.md"
|
|
obsidian_seed ${dailyTemplate} "$vault/Templates/Daily.md"
|
|
|
|
run ${lib.getExe pkgs.git} -C "$vault" init --quiet -b main
|
|
run ${lib.getExe pkgs.git} -C "$vault" remote add origin ${lib.escapeShellArg remote}
|
|
fi
|
|
'';
|
|
};
|
|
}
|