Files
nix/modules/home-manager/profiles/vault/default.nix
2024-05-03 22:41:09 -03:00

75 lines
1.6 KiB
Nix

{
config,
lib,
pkgs,
...
}: let
cfg = config.profiles.vault;
vault = pkgs.writeShellScriptBin "vault" ''
VAULT_DIR="${cfg.vaultDir}"
${builtins.readFile ./cli.sh}
'';
in {
imports = [];
options.profiles.vault = with lib;
with lib.types; {
enable = mkEnableOption "";
vaultDir = mkOption {
type = either path str;
default = "${config.home.homeDirectory}/.vault";
};
periodicPush = mkOption {
type = bool;
default = true;
};
};
config = with lib;
mkIf cfg.enable {
services.flatpak.packages = [
"md.obsidian.Obsidian"
];
home.packages = [
vault
];
home.file = {
"${cfg.vaultDir}/vault" = {
executable = true;
text = ''
${vault}
'';
};
};
systemd.user.services = mkIf cfg.periodicPush {
vault-periodic-push = {
Install = {
WantedBy = ["default.target"];
};
Service = let
script = pkgs.writeShellScriptBin "vault-periodic-push" ''
${vault} sync
'';
in {
Type = "oneshot";
RemainAfterExit = true;
StandardOutput = "journal";
ExecStart = script;
ExecStop = script;
};
};
};
systemd.user.timers = mkIf cfg.periodicPush {
vault-periodic-push = {
Install = {
WantedBy = ["timers.target"];
};
Timer = {
OnBootSec = "1min";
OnUnitActiveSec = "2h";
};
};
};
};
}