-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move bookmarks sync scripts into module
- Loading branch information
Showing
6 changed files
with
126 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -495,37 +495,9 @@ in | |
nixfiles.bookdb.remoteSync.send.sshKeyFile = config.sops.secrets."users/remote_sync/ssh_private_key".path; | ||
nixfiles.bookdb.remoteSync.send.targets = [ "carcosa.barrucadu.co.uk" ]; | ||
|
||
users.extraUsers.remote-sync = { | ||
home = "/var/lib/remote-sync"; | ||
createHome = true; | ||
isSystemUser = true; | ||
shell = pkgs.bashInteractive; | ||
group = "nogroup"; | ||
}; | ||
|
||
systemd.services.bookmarks-sync = { | ||
description = "Upload bookmarks data to carcosa"; | ||
startAt = "*:15"; | ||
path = with pkgs; [ openssh ]; | ||
serviceConfig = { | ||
ExecStart = pkgs.writeShellScript "bookmarks-sync" '' | ||
set -ex | ||
env "ES_HOST=$ES_HOST" \ | ||
${pkgs.nixfiles.bookmarks}/bin/bookmarks_ctl export-index | \ | ||
ssh -i "$SSH_KEY_FILE" \ | ||
-o UserKnownHostsFile=/dev/null \ | ||
-o StrictHostKeyChecking=no \ | ||
[email protected] \ | ||
bookmarks-receive-elasticsearch | ||
''; | ||
User = config.users.extraUsers.remote-sync.name; | ||
}; | ||
environment = { | ||
ES_HOST = config.systemd.services.bookmarks.environment.ES_HOST; | ||
SSH_KEY_FILE = config.sops.secrets."users/remote_sync/ssh_private_key".path; | ||
}; | ||
}; | ||
nixfiles.bookmarks.remoteSync.send.enable = true; | ||
nixfiles.bookmarks.remoteSync.send.sshKeyFile = config.sops.secrets."users/remote_sync/ssh_private_key".path; | ||
nixfiles.bookmarks.remoteSync.send.targets = [ "carcosa.barrucadu.co.uk" ]; | ||
|
||
sops.secrets."users/remote_sync/ssh_private_key".owner = config.users.extraUsers.remote-sync.name; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# see remote-sync-send.nix | ||
{ config, lib, pkgs, ... }: | ||
|
||
with lib; | ||
let | ||
cfg = config.nixfiles.bookmarks.remoteSync.receive; | ||
in | ||
{ | ||
config = mkIf cfg.enable { | ||
users.extraUsers.bookmarks-remote-sync-receive = { | ||
home = "/var/lib/bookmarks-remote-sync-receive"; | ||
createHome = true; | ||
isSystemUser = true; | ||
openssh.authorizedKeys.keys = cfg.authorizedKeys; | ||
shell = pkgs.bashInteractive; | ||
group = "nogroup"; | ||
packages = | ||
let | ||
receive-elasticsearch = '' | ||
env ES_HOST=${config.systemd.services.bookmarks.environment.ES_HOST} \ | ||
${pkgs.nixfiles.bookmarks}/bin/bookmarks_ctl import-index --drop-existing | ||
''; | ||
in | ||
[ | ||
(pkgs.writeShellScriptBin "receive-elasticsearch" bookmarks-receive-elasticsearch) | ||
]; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# see remote-sync-receive.nix | ||
{ config, lib, pkgs, ... }: | ||
|
||
with lib; | ||
let | ||
cfg = config.nixfiles.bookmarks.remoteSync.send; | ||
|
||
toService = target: { | ||
name = "bookmarks-sync-${target}"; | ||
value = { | ||
description = "Upload bookmarks data to ${target}"; | ||
startAt = "*:15"; | ||
path = with pkgs; [ openssh ]; | ||
serviceConfig = { | ||
ExecStart = pkgs.writeShellScript "bookmarks-sync" '' | ||
set -ex | ||
env "ES_HOST=$ES_HOST" \ | ||
${pkgs.nixfiles.bookmarks}/bin/bookmarks_ctl export-index | \ | ||
ssh -i "$SSH_KEY_FILE" \ | ||
-o UserKnownHostsFile=/dev/null \ | ||
-o StrictHostKeyChecking=no \ | ||
bookmarks-remote-sync-receive@${target} \ | ||
receive-elasticsearch | ||
''; | ||
User = config.users.extraUsers.bookmarks-remote-sync-send.name; | ||
}; | ||
environment = { | ||
ES_HOST = config.systemd.services.bookmarks.environment.ES_HOST; | ||
SSH_KEY_FILE = cfg.sshKeyFile; | ||
}; | ||
}; | ||
}; | ||
in | ||
{ | ||
config = mkIf cfg.enable { | ||
users.extraUsers.bookmarks-remote-sync-send = { | ||
home = "/var/lib/bookmarks-remote-sync-send"; | ||
createHome = true; | ||
isSystemUser = true; | ||
shell = pkgs.bashInteractive; | ||
group = "nogroup"; | ||
}; | ||
|
||
systemd.services = listToAttrs (map toService cfg.targets); | ||
}; | ||
} |