aboutsummaryrefslogtreecommitdiffstats
path: root/modules/office/calcurse
diff options
context:
space:
mode:
authorArpit Chakladar <arpitchakladar+git@gmail.com>2026-09-02 16:49:38 +0530
committerArpit Chakladar <arpitchakladar+git@gmail.com>2026-09-02 16:49:38 +0530
commitd5506ca50709f0b786d8ca8329f7cdbb7df9142e (patch)
treed2e351bcfe441443aa66bdf5d68f4d4df240705f /modules/office/calcurse
parent2fdefe79b1ddc31241c22a7f88ae931ddc4180f3 (diff)
downloadhome-manager-config-d5506ca50709f0b786d8ca8329f7cdbb7df9142e.tar.gz
home-manager-config-d5506ca50709f0b786d8ca8329f7cdbb7df9142e.zip
feat(office/calcurse): calcurse-sync can now be setup in home-manager
Diffstat (limited to 'modules/office/calcurse')
-rw-r--r--modules/office/calcurse/calcurse-sync.sh46
-rw-r--r--modules/office/calcurse/default.nix110
2 files changed, 93 insertions, 63 deletions
diff --git a/modules/office/calcurse/calcurse-sync.sh b/modules/office/calcurse/calcurse-sync.sh
index 8251e06..169adc9 100644
--- a/modules/office/calcurse/calcurse-sync.sh
+++ b/modules/office/calcurse/calcurse-sync.sh
@@ -4,8 +4,12 @@
# it across machines via a remote (e.g. a private GitHub repo).
#
# Usage:
-# calcurse-sync init Turn the calcurse data dir into a git repo
-# and (optionally) attach a remote.
+# calcurse-sync init [remote-url] Turn the calcurse data dir into a git
+# repo and (optionally) attach a remote.
+# Safe to re-run — no-ops if a repo
+# already exists. If no remote is given,
+# falls back to $CALCURSE_SYNC_REMOTE,
+# then (if interactive) a prompt.
# calcurse-sync sync Commit any changes and push. Initializes
# the repo automatically on first run.
# calcurse-sync pull Pull down changes from the remote.
@@ -15,6 +19,7 @@
#
# Defaults to $XDG_DATA_HOME/calcurse (usually ~/.local/share/calcurse).
# Override with $CALCURSE_DATA_DIR if yours lives elsewhere.
+# Override the default remote used on first init with $CALCURSE_SYNC_REMOTE.
set -euo pipefail
@@ -77,9 +82,13 @@ readable_timestamp() {
}
# Initializes the git repo, makes an initial commit if there's anything to
-# commit, and prompts for a remote to push to. Shared by `init` (explicit,
-# manual) and `sync` (automatic, first-run-on-a-new-device).
+# commit, and attaches a remote. The remote is resolved in this order:
+# explicit arg > $CALCURSE_SYNC_REMOTE > interactive prompt (tty only) >
+# skipped. Shared by `init` (explicit/manual) and `sync`/activation
+# (automatic, first-run-on-a-new-device).
do_init() {
+ local remote_url="${1:-${CALCURSE_SYNC_REMOTE:-}}"
+
info "No git repository found in $DATA_DIR — initializing one."
git -C "$DATA_DIR" init -b "$BRANCH" >/dev/null
@@ -88,18 +97,19 @@ do_init() {
cat > "$DATA_DIR/.gitignore" <<'EOF'
*.lock
*.swp
-*.pid
-*.log
EOF
fi
- local remote_url=""
- if [ -t 0 ]; then
- read -r -p "Remote URL to push to (leave blank to skip): " remote_url
+ git -C "$DATA_DIR" add -A
+ if ! git -C "$DATA_DIR" diff --cached --quiet; then
+ git -C "$DATA_DIR" commit -m "sync: $(readable_timestamp)" >/dev/null
+ info "Created initial commit."
else
- warn "Running non-interactively (e.g. from a calcurse hook) — skipping"
- warn "the remote-URL prompt. Run 'calcurse-sync remote <url>' once you're"
- warn "at a terminal to enable pushing."
+ warn "Nothing to commit yet (data directory is empty)."
+ fi
+
+ if [ -z "$remote_url" ] && [ -t 0 ]; then
+ read -r -p "Remote URL to push to (leave blank to skip): " remote_url
fi
if [ -n "$remote_url" ]; then
@@ -112,9 +122,9 @@ EOF
error "credentials, then try 'calcurse-sync sync' again."
exit 1
fi
- elif [ -t 0 ]; then
+ else
warn "No remote configured. This repo will only track history locally"
- warn "until you run 'calcurse-sync remote <url>'."
+ warn "until you run 'calcurse-sync remote <url>' (or set CALCURSE_SYNC_REMOTE)."
fi
}
@@ -123,11 +133,11 @@ cmd_init() {
require_data_dir
if repo_exists; then
- die "a git repository already exists in $DATA_DIR
-If you meant to reconfigure the remote, use 'calcurse-sync remote <url>' instead."
+ info "Repository already exists in $DATA_DIR — nothing to do."
+ return 0
fi
- do_init
+ do_init "${1:-}"
}
cmd_remote() {
@@ -235,7 +245,7 @@ cmd_status() {
}
cmd_help() {
- sed -n '2,17p' "$0" | sed 's/^# \{0,1\}//'
+ sed -n '2,20p' "$0" | sed 's/^# \{0,1\}//'
}
main() {
diff --git a/modules/office/calcurse/default.nix b/modules/office/calcurse/default.nix
index e8b38b6..c72896e 100644
--- a/modules/office/calcurse/default.nix
+++ b/modules/office/calcurse/default.nix
@@ -13,22 +13,27 @@ let
paths = [
pkgs.bash
pkgs.calcurse
- calcurseSync
]
- ++ lib.optionals config.development.nixvim.enable [ config.development.nixvim.package ];
+ ++ lib.optionals config.development.nixvim.enable [ config.development.nixvim.package ]
+ ++ lib.optionals config.office.calcurse.sync.enable [ calcurseSync ];
nativeBuildInputs = [ pkgs.makeWrapper ];
postBuild = ''
${lib.optionalString config.development.nixvim.enable ''
wrapProgram $out/bin/calcurse --set PAGER "nvim"
''}
- wrapProgram $out/bin/calcurse-sync \
- --prefix PATH : ${
- lib.makeBinPath [
- config.development.git.package
- pkgs.coreutils
- pkgs.gnused
- ]
- }
+ ${lib.optionalString config.office.calcurse.sync.enable ''
+ wrapProgram $out/bin/calcurse-sync \
+ --prefix PATH : ${
+ lib.makeBinPath [
+ config.development.git.package
+ pkgs.coreutils
+ pkgs.gnused
+ ]
+ } \
+ ${lib.optionalString (config.office.calcurse.sync.remote != null) ''
+ --set CALCURSE_SYNC_REMOTE ${lib.escapeShellArg config.office.calcurse.sync.remote}
+ ''}
+ ''}
'';
meta = {
mainProgram = "calcurse";
@@ -44,44 +49,59 @@ in
default = calcursePackage;
description = "The calcurse package to use.";
};
- };
- config = lib.mkIf config.office.calcurse.enable {
- home.packages = [ config.office.calcurse.package ];
- xdg.configFile."calcurse/conf" = {
- source = ./conf;
- force = true;
- };
- xdg.configFile."calcurse/keys" = {
- source = ./keys;
- force = true;
- };
- xdg.configFile."calcurse/hooks/pre-load" = {
- source = ./hooks/pre-load;
- executable = true;
- force = true;
- };
- xdg.configFile."calcurse/hooks/post-save" = {
- source = ./hooks/post-save;
- executable = true;
- force = true;
+ sync = {
+ enable = lib.mkEnableOption "Enables git-backed syncing of the calcurse data directory (builds calcurse-sync, installs the sync hooks, and runs an initial 'calcurse-sync init' on activation).";
+ remote = lib.mkOption {
+ type = lib.types.nullOr lib.types.str;
+ default = null;
+ description = "Git remote URL for the calcurse data directory. When set, calcurse-sync uses it automatically on first init instead of prompting.";
+ };
};
+ };
- programs.git.includes = lib.mkIf config.development.git.enable [
+ config = lib.mkIf config.office.calcurse.enable (
+ lib.mkMerge [
{
- condition = "gitdir:${config.xdg.dataHome}/calcurse/";
- contents = {
- user = {
- name = "Calcurse of ${config.home.username}";
- email = "${config.home.username}@calcurse.localhost";
- };
- commit = {
- gpgSign = false;
- };
- tag = {
- gpgSign = false;
- };
+ home.packages = [ config.office.calcurse.package ];
+ xdg.configFile."calcurse/conf" = {
+ source = ./conf;
+ force = true;
+ };
+ xdg.configFile."calcurse/keys" = {
+ source = ./keys;
+ force = true;
};
}
- ];
- };
+ (lib.mkIf config.office.calcurse.sync.enable {
+ xdg.configFile."calcurse/hooks/pre-load" = {
+ source = ./hooks/pre-load;
+ executable = true;
+ force = true;
+ };
+ xdg.configFile."calcurse/hooks/post-save" = {
+ source = ./hooks/post-save;
+ executable = true;
+ force = true;
+ };
+
+ programs.git.includes = lib.mkIf config.development.git.enable [
+ {
+ condition = "gitdir:${config.xdg.dataHome}/calcurse/";
+ contents = {
+ user = {
+ name = "Calcurse of ${config.home.username}";
+ email = "${config.home.username}@calcurse.localhost";
+ };
+ commit.gpgSign = false;
+ tag.gpgSign = false;
+ };
+ }
+ ];
+
+ home.activation.calcurseSyncInit = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
+ run ${config.office.calcurse.package}/bin/calcurse-sync init || true
+ '';
+ })
+ ]
+ );
}