packaging stuff up

This commit is contained in:
Noah Masur
2025-01-30 14:48:17 -05:00
parent 0ebd0bac2c
commit b123ae3e69
19 changed files with 135 additions and 89 deletions

View File

@ -0,0 +1,46 @@
{
config,
pkgs,
lib,
...
}:
let
cfg = config.nmasur.presets.services.dotfiles;
in
{
# Allows me to make sure I can work on my dotfiles locally
options.nmasur.preset.services.dotfiles = {
enable = lib.mkEnableOption "Clone dotfiles repository";
repo = lib.mkOption {
type = lib.types.str;
description = "Git repo containing dotfiles";
default = "git@github.com:nmasur/dotfiles";
};
path = lib.mkOption {
type = lib.types.path;
description = "Path to dotfiles on disk";
default = config.homePath + "/dev/personal/dotfiles";
};
};
config = lib.mkIf cfg.enable {
home.activation = {
# Always clone dotfiles repository if it doesn't exist
cloneDotfiles = config.lib.dag.entryAfter [ "writeBoundary" "loadkey" ] ''
if [ ! -d "${cfg.path}" ]; then
run mkdir --parents $VERBOSE_ARG $(dirname "${cfg.path}")
run ${pkgs.git}/bin/git \
clone ${cfg.repo} "${cfg.path}"
fi
'';
};
# Set a variable for dotfiles repo, not necessary but convenient
home.sessionVariables.DOTS = cfg.path;
};
}

View File

@ -18,13 +18,16 @@ in
home.activation = {
# Always load the key if it doesn't exist
cloneDotfiles = config.lib.dag.entryAfter [ "writeBoundary" ] ''
loadkey = config.lib.dag.entryAfter [ "writeBoundary" ] ''
if [ ! -d ~/.ssh ]; then
run mkdir --parents $VERBOSE_ARG ~/.ssh/
fi
if [ ! -f ~/.ssh/id_ed25519 ]; then
run mkdir -p ~/.ssh/
$DRY_RUN_CMD mkdir --parents $VERBOSE_ARG $(dirname "${config.dotfilesPath}")
$DRY_RUN_CMD ${pkgs.git}/bin/git \
clone ${config.dotfilesRepo} "${config.dotfilesPath}"
printf "\nEnter the seed phrase for your SSH key...\n"
printf "\nThen press ^D when complete.\n\n"
mkdir -p ~/.ssh/
${pkgs.melt}/bin/melt restore ~/.ssh/id_ed25519
printf "\n\nContinuing activation.\n\n"
fi
'';
};

View File

@ -0,0 +1,35 @@
{
config,
pkgs,
lib,
...
}:
let
cfg = config.nmasur.presets.services.notes-git-sync;
in
{
options.nmasur.presets.services.notes-git-sync.enable = lib.mkEnableOption "Sync notes to folder";
config = lib.mkIf cfg.enable {
# Sync notes for Nextcloud automatically
systemd.user.timers.refresh-notes = {
Timer = {
OnCalendar = "*-*-* *:0/10:50"; # Every 10 minutes
Unit = "refresh-notes.service";
};
};
systemd.user.services.refresh-notes = {
Unit.Description = "Get latest notes.";
Service = {
Type = "oneshot";
ExecStartPre = "${pkgs.git}/bin/git -C /data/git/notes reset --hard master";
ExecStart = "${pkgs.git}/bin/git -C /data/git/notes pull";
WorkingDirectory = config.homePath;
Environment = "PATH=${pkgs.openssh}/bin";
};
};
};
}