From f5ffea6d644e4a955386fdc29b731e6dab03a28b Mon Sep 17 00:00:00 2001 From: marc Date: Mon, 9 Nov 2026 19:28:24 +0100 Subject: [PATCH] Added diwan to thingvellir --- flake.lock | 8 +-- hosts/thingvellir/default.nix | 14 +++++ hosts/thingvellir/secrets.nix | 6 +++ modules/ai/diwan.nix | 3 ++ modules/app/nextcloud.nix | 77 ++++++++++++++++++++++++---- secrets/app.d/nextcloud-password.age | 9 ++++ secrets/secrets.nix | 3 ++ 7 files changed, 107 insertions(+), 13 deletions(-) create mode 100644 secrets/app.d/nextcloud-password.age diff --git a/flake.lock b/flake.lock index 63cc9f5..07f7df6 100644 --- a/flake.lock +++ b/flake.lock @@ -43,11 +43,11 @@ ] }, "locked": { - "lastModified": 1794237634, - "narHash": "sha256-JuKo2OLUhsgDJTeGm5SmJ3EZiyyxJViryh+W7UtsMYc=", + "lastModified": 1794246188, + "narHash": "sha256-Y9ABp5yvkeTjzj7s7gd3JxiL9nlUrB6+DhOA+BKdoAk=", "ref": "refs/heads/main", - "rev": "c09f2a1a11fe32812306bc6524350e59b3ac232d", - "revCount": 6, + "rev": "43215d6e0a35f8b8594e2dec78e9535731444e6a", + "revCount": 8, "type": "git", "url": "https://git.samfelag.xyz/marc/diwan" }, diff --git a/hosts/thingvellir/default.nix b/hosts/thingvellir/default.nix index 2b0f8ff..a44bf26 100644 --- a/hosts/thingvellir/default.nix +++ b/hosts/thingvellir/default.nix @@ -70,5 +70,19 @@ with lib; dev.docker.enable = true; dev.docker.users = ["marc"]; + + ai.claude.enable = true; + ai.diwan = { + enable = true; + notesDir = "/home/marc/org-agenda"; + }; + app.nextcloud.syncClient = { + enable = true; + user = "marc"; + localDir = "/home/marc/org-agenda"; + remoteUrl = "https://nextcloud.samfelag.xyz"; + remotePath = "/org-agenda"; + passwordFile = config.age.secrets."app.d/nextcloud-password".path; + }; }; } diff --git a/hosts/thingvellir/secrets.nix b/hosts/thingvellir/secrets.nix index 77d99fb..2eda7c3 100644 --- a/hosts/thingvellir/secrets.nix +++ b/hosts/thingvellir/secrets.nix @@ -20,5 +20,11 @@ group = "consul"; mode = "600"; }; + + "app.d/nextcloud-password" = { + file = ../../secrets/app.d/nextcloud-password.age; + owner = "marc"; + mode = "400"; + }; }; } diff --git a/modules/ai/diwan.nix b/modules/ai/diwan.nix index 85857c2..e9da61b 100644 --- a/modules/ai/diwan.nix +++ b/modules/ai/diwan.nix @@ -43,6 +43,9 @@ in description = "diwan tick"; after = [ "network-online.target" ]; wants = [ "network-online.target" ]; + # diwan shells out to `herdr`; systemd's default service PATH doesn't + # include it, so add it explicitly rather than relying on the login PATH. + path = [ inputs.herdr.packages.${system}.default ]; environment = { DIWAN_NOTES_DIR = cfg.notesDir; }; diff --git a/modules/app/nextcloud.nix b/modules/app/nextcloud.nix index 2646a4b..622b1ce 100644 --- a/modules/app/nextcloud.nix +++ b/modules/app/nextcloud.nix @@ -6,16 +6,75 @@ in { options.samfelag.modules.app.nextcloud = { enable = lib.mkEnableOption "nextcloud"; - }; - config = lib.mkIf cfg.enable { - environment.systemPackages = with pkgs; [ - nextcloud-client - ]; - hm.services.nextcloud-client = { - enable = true; - startInBackground = true; + syncClient = { + enable = lib.mkEnableOption "headless nextcloud sync via nextcloudcmd on a timer"; + + user = lib.mkOption { + type = lib.types.str; + description = "User to run the sync as, and Nextcloud login name"; + }; + + localDir = lib.mkOption { + type = lib.types.str; + description = "Local directory to sync"; + }; + + remoteUrl = lib.mkOption { + type = lib.types.str; + description = "Nextcloud server URL"; + }; + + remotePath = lib.mkOption { + type = lib.types.str; + default = ""; + description = "Remote path on the Nextcloud server to sync"; + }; + + passwordFile = lib.mkOption { + type = lib.types.str; + description = "Path to an EnvironmentFile containing NC_PASSWORD=... (should be secret)"; + }; + + interval = lib.mkOption { + type = lib.types.str; + default = "1min"; + description = "How often to run the sync (systemd time span)"; + }; }; - }; + config = lib.mkMerge [ + (lib.mkIf cfg.enable { + environment.systemPackages = with pkgs; [ + nextcloud-client + ]; + + hm.services.nextcloud-client = { + enable = true; + startInBackground = true; + }; + }) + + (lib.mkIf cfg.syncClient.enable { + systemd.services.nextcloud-sync = { + description = "Nextcloud headless sync (nextcloudcmd)"; + after = [ "network-online.target" ]; + wants = [ "network-online.target" ]; + serviceConfig = { + Type = "oneshot"; + User = cfg.syncClient.user; + EnvironmentFile = cfg.syncClient.passwordFile; + ExecStart = "${pkgs.nextcloud-client}/bin/nextcloudcmd --non-interactive -u ${cfg.syncClient.user} --path ${cfg.syncClient.remotePath} ${cfg.syncClient.localDir} ${cfg.syncClient.remoteUrl}"; + }; + }; + + systemd.timers.nextcloud-sync = { + wantedBy = [ "timers.target" ]; + timerConfig = { + OnBootSec = cfg.syncClient.interval; + OnUnitActiveSec = cfg.syncClient.interval; + }; + }; + }) + ]; } diff --git a/secrets/app.d/nextcloud-password.age b/secrets/app.d/nextcloud-password.age new file mode 100644 index 0000000..94504f9 --- /dev/null +++ b/secrets/app.d/nextcloud-password.age @@ -0,0 +1,9 @@ +age-encryption.org/v1 +-> ssh-ed25519 GWuf0Q VbKtptk2zh0R7h9LxIxRsYXqaq3uHCIZQEdOn3/QvSM +E9A0gRixWQfxmJSHeqxNv0W73jKNliQtP93CjzFXkJE +-> ssh-ed25519 kNjiNQ 2eJ3bwzlT8Jjox0TUyUKzMQqCDsIJtjHljyfQYkHi2I +KvtOT0oijhV8L07bW0dby8v4IWP/2n+XAlN4bmekihY +--- Cv64ZC71bS45sWrEpwhV4hmLPv+96QmIR/qOR+D8bo0 +Í ã2f}KÃÄäÞ˰–üÙ. +4¼Z¢2ðסzY” +…1§Ž–ëSŠ�’uÛ¹vm‘&еB]  »KÑ‚?" Ð\œÈ¶ÍTq \ No newline at end of file diff --git a/secrets/secrets.nix b/secrets/secrets.nix index db3259a..ab519ae 100644 --- a/secrets/secrets.nix +++ b/secrets/secrets.nix @@ -37,4 +37,7 @@ in # -- Nomad ------------------------------- "nomad.d/consul-token-client.json.age".publicKeys = samfelag-hosts; "nomad.d/consul-token-server.json.age".publicKeys = thingvellir; + + # -- Apps -------------------------------- + "app.d/nextcloud-password.age".publicKeys = thingvellir; }