diff options
| author | quentin@aristote.fr <quentin@aristote.fr> | 2023-08-27 16:25:47 +0200 |
|---|---|---|
| committer | quentin@aristote.fr <quentin@aristote.fr> | 2023-08-27 16:31:34 +0200 |
| commit | 511d1466331c7d4ede2c7f025a08a488d43fe027 (patch) | |
| tree | b53d6b3bb7252efd5ada30bab6a5e9a3310370bd | |
| parent | 2296a9c3d51ff7d9db1edb6e65376df21f485486 (diff) | |
devenv: add gitignore module
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | modules/devenv/dotfiles.nix | 8 | ||||
| -rw-r--r-- | modules/devenv/integrations/gitignore.nix | 56 |
3 files changed, 48 insertions, 18 deletions
@@ -1 +1,3 @@ +### devenv .devenv/ + diff --git a/modules/devenv/dotfiles.nix b/modules/devenv/dotfiles.nix index 8b8d95b..7f11194 100644 --- a/modules/devenv/dotfiles.nix +++ b/modules/devenv/dotfiles.nix @@ -40,15 +40,15 @@ in { let content = text - + lib.optionalString (name == ".gitignore") '' - # dotfiles + + lib.optionalString (name == ".gitignore" && dotfilesToIgnore != []) '' + ### dotfiles ${lib.concatStringsSep "\n" dotfilesToIgnore} ''; in '' ${ if gitignore - then "ln -s" - else "cp" + then "ln --symbolic --force" + else "install --mode=644" } "${builtins.toFile name content}" "${name}" '' ) diff --git a/modules/devenv/integrations/gitignore.nix b/modules/devenv/integrations/gitignore.nix index ed0e61a..c6b3b40 100644 --- a/modules/devenv/integrations/gitignore.nix +++ b/modules/devenv/integrations/gitignore.nix @@ -1,25 +1,53 @@ { config, lib, + pkgs, ... }: let cfg = config.gitignore; + ignoreDevenv = cfg.devenv.enable or false; + templates = lib.attrNames (lib.filterAttrs (name: value: (value.enable or false) && name != "devenv") cfg); + toUncomment = builtins.concatLists (lib.collect lib.isList cfg); in { - options.gitignore = { - extra = lib.mkOption { - type = lib.types.lines; - default = ""; - example = '' - *.my-file-extension - ''; - }; + options.gitignore = lib.mkOption { + type = with lib.types; (submodule { + freeformType = with lib.types; + attrsOf (submodule { + options = { + enable = lib.mkEnableOption ""; + uncomment = lib.mkOption { + type = with lib.types; listOf str; + default = []; + description = "Lines that should be uncommented and thus enabled in the template file."; + }; + }; + }); + options.extra = lib.mkOption { + type = lib.types.lines; + default = ""; + example = '' + *.my-file-extension + ''; + }; + }); + default = {extra = "";}; }; - config.dotfiles.gitignore = lib.mkIf (cfg.extra != "") { - gitignore = lib.mkDefault false; - text = '' - ## Miscellaneous - ${cfg.extra}; - ''; + config = { + dotfiles.".gitignore" = lib.mkIf (templates != {} || cfg.extra != "") { + gitignore = lib.mkDefault false; + text = + lib.optionalString (templates != []) (builtins.readFile (pkgs.personal.static.gitignore.override {inherit templates toUncomment;})) + + lib.optionalString ignoreDevenv '' + ### devenv + .devenv/ + + '' + + lib.optionalString (cfg.extra != "") '' + ### miscellaneous + ${cfg.extra} + ''; + }; + gitignore.devenv.enable = lib.mkDefault true; }; } |
