feat: vault profile
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
{...}: {
|
||||
imports = [
|
||||
./gterminal.nix
|
||||
./vault
|
||||
];
|
||||
options = {};
|
||||
config = {};
|
||||
|
||||
22
modules/home-manager/profiles/vault/cli.sh
Normal file
22
modules/home-manager/profiles/vault/cli.sh
Normal file
@@ -0,0 +1,22 @@
|
||||
set -e
|
||||
|
||||
function sync() {
|
||||
pushd "$VAULT_DIR"
|
||||
|
||||
git pull
|
||||
|
||||
git add .
|
||||
|
||||
if [[ $(git status --porcelain) ]]; then
|
||||
git commit -am "vault sync: $(date +%F) $(date +%R)"
|
||||
git push -u origin main
|
||||
fi
|
||||
|
||||
popd
|
||||
}
|
||||
|
||||
|
||||
case "$1" in
|
||||
"sync") sync ;;
|
||||
*) echo "Not a valid command: $1" ;;
|
||||
esac
|
||||
66
modules/home-manager/profiles/vault/default.nix
Normal file
66
modules/home-manager/profiles/vault/default.nix
Normal file
@@ -0,0 +1,66 @@
|
||||
{
|
||||
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
|
||||
];
|
||||
|
||||
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";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
./hyprland.nix
|
||||
./krita
|
||||
./neovim.nix
|
||||
./obsidian
|
||||
./prismlauncher.nix
|
||||
./wezterm.nix
|
||||
];
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
cfg = config.programs.obsidian;
|
||||
vaultCmd = pkgs.writeShellScriptBin "vault" ''
|
||||
function awk() { ${pkgs.gawk}/bin/awk "$@"; }
|
||||
function git() { ${pkgs.git}/bin/git "$@"; }
|
||||
function gum() { ${pkgs.gum}/bin/gum "$@"; }
|
||||
|
||||
${builtins.readFile ./vault.sh}
|
||||
'';
|
||||
in {
|
||||
imports = [];
|
||||
options.programs.obsidian = with lib;
|
||||
with lib.types; {
|
||||
enable = mkEnableOption "";
|
||||
vaultCmd = mkOption {
|
||||
type = bool;
|
||||
default = false;
|
||||
};
|
||||
vaultDir = mkOption {
|
||||
type = str;
|
||||
default = "${config.home.homeDirectory}/.vault";
|
||||
};
|
||||
};
|
||||
config = with lib;
|
||||
mkIf cfg.enable {
|
||||
services.flatpak.packages = [
|
||||
"md.obsidian.Obsidian"
|
||||
];
|
||||
home.packages = [
|
||||
(
|
||||
if cfg.vaultCmd
|
||||
then vaultCmd
|
||||
else null
|
||||
)
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
function vault-sync() {
|
||||
local vault_dir="$1"
|
||||
|
||||
date="$(date +%F) $(date +%R)"
|
||||
|
||||
set -e
|
||||
|
||||
pushd "$vault_dir"
|
||||
|
||||
gum log --structured --prefix 'vault sync' --level info "Syncing vault through git"
|
||||
|
||||
gum log --structured --prefix 'vault sync' --level debug "Pulling from remote"
|
||||
git pull
|
||||
|
||||
# Skip if there's no changes
|
||||
if git diff --quiet "*.*"; then
|
||||
gum log --structured \
|
||||
--prefix 'vault sync' \
|
||||
--level warn \
|
||||
'No files changed'
|
||||
popd
|
||||
exit 0
|
||||
else
|
||||
gum log --structured --prefix 'vault sync' --level debug 'Committing' commit_msg "vault sync: $date"
|
||||
git commit -am "vault sync: $date"
|
||||
|
||||
gum log --structured --prefix 'vault sync' --level debug 'Pushing to remote'
|
||||
git push
|
||||
|
||||
gum log --structured --prefix 'vault sync' --level info 'Vault synced!'
|
||||
fi
|
||||
|
||||
popd
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
"sync") vault-sync "$vault_dir" ;;
|
||||
*) gum log --structured --prefix 'vault' --level error "Command $1 does not exist" ;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user