summaryrefslogtreecommitdiff
path: root/modules/devenv/dotfiles.nix
diff options
context:
space:
mode:
authorquentin@aristote.fr <quentin@aristote.fr>2023-08-26 23:28:27 +0200
committerquentin@aristote.fr <quentin@aristote.fr>2023-08-27 12:05:15 +0200
commit2cb43216d3c2cbc6f40e0d6646abb9f31a1c40f7 (patch)
tree05eb1717f529ae1f78a7c615ceb6e1980909efae /modules/devenv/dotfiles.nix
parente467ecaea03942161ba5b09a251deb31c5b9ba53 (diff)
devenv: add more modules
Diffstat (limited to 'modules/devenv/dotfiles.nix')
-rw-r--r--modules/devenv/dotfiles.nix56
1 files changed, 56 insertions, 0 deletions
diff --git a/modules/devenv/dotfiles.nix b/modules/devenv/dotfiles.nix
new file mode 100644
index 0000000..8b8d95b
--- /dev/null
+++ b/modules/devenv/dotfiles.nix
@@ -0,0 +1,56 @@
+{
+ config,
+ lib,
+ ...
+}: let
+ cfg = config.dotfiles;
+ dotfilesToIgnore = lib.attrNames (lib.filterAttrs (_: {gitignore, ...}: gitignore) cfg);
+in {
+ options.dotfiles = lib.mkOption {
+ type = with lib.types;
+ # this cannot be a lazyAttrsOf, see https://nixos.org/manual/nixos/unstable/#sec-option-types-composed
+ attrsOf (submodule {
+ options = {
+ gitignore =
+ lib.mkEnableOption ""
+ // {
+ default = true;
+ description = "Whether git should ignore this dotfile, typically if it is generated to contain absolute paths.";
+ };
+ text = lib.mkOption {
+ type = lib.types.lines;
+ default = "";
+ description = "The content of the dotfile.";
+ };
+ };
+ });
+ };
+
+ config.enterShell =
+ lib.mkIf (cfg != {})
+ (''
+ echo Installing dotfiles...
+ ''
+ + lib.concatStringsSep "\n" (lib.mapAttrsToList (
+ name: {
+ text,
+ gitignore,
+ }:
+ # this has to be done here to avoid infinite recursion
+ let
+ content =
+ text
+ + lib.optionalString (name == ".gitignore") ''
+ # dotfiles
+ ${lib.concatStringsSep "\n" dotfilesToIgnore}
+ '';
+ in ''
+ ${
+ if gitignore
+ then "ln -s"
+ else "cp"
+ } "${builtins.toFile name content}" "${name}"
+ ''
+ )
+ cfg));
+}