50 lines
1.3 KiB
Nix
Raw Permalink Normal View History

2025-01-30 14:48:17 -05:00
{
config,
pkgs,
lib,
...
}:
let
2025-01-31 15:40:41 -05:00
cfg = config.nmasur.presets.programs.dotfiles;
2025-01-30 14:48:17 -05:00
in
{
# Allows me to make sure I can work on my dotfiles locally
2025-01-31 15:40:41 -05:00
options.nmasur.preset.programs.dotfiles = {
2025-01-30 14:48:17 -05:00
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";
2025-02-05 17:25:29 -05:00
default = config.home.homeDirectory + "/dev/personal/dotfiles";
2025-01-30 14:48:17 -05:00
};
};
config = lib.mkIf cfg.enable {
2025-02-05 17:25:29 -05:00
# Always make the dotfiles directory considered safe for git and direnv
2025-02-01 16:10:16 -05:00
programs.git.extraConfig.safe.directory = cfg.path;
programs.direnv.config.whitelist.prefix = [ cfg.path ];
2025-01-30 14:48:17 -05:00
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}")
2025-02-05 17:25:29 -05:00
run ${lib.getExe pkgs.git} clone ${cfg.repo} "${cfg.path}"
2025-01-30 14:48:17 -05:00
fi
'';
};
# Set a variable for dotfiles repo, not necessary but convenient
home.sessionVariables.DOTS = cfg.path;
};
}