From 2cb43216d3c2cbc6f40e0d6646abb9f31a1c40f7 Mon Sep 17 00:00:00 2001 From: "quentin@aristote.fr" Date: Sat, 26 Aug 2023 23:28:27 +0200 Subject: devenv: add more modules --- modules/devenv/dotfiles.nix | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 modules/devenv/dotfiles.nix (limited to 'modules/devenv/dotfiles.nix') 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)); +} -- cgit v1.2.3