feat: generalize Nix module file template

This commit is contained in:
Kiana Sheibani 2025-10-22 13:32:46 -04:00
parent 7a5a588385
commit 17a9aed526
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -2306,12 +2306,18 @@ Now that we have our new-and-improved template registry system, we can add new f
**** Nix
The default Nix file template is for a NixOS module. This is nice when you're writing a module, but most Nix files aren't modules. We'll restrict the default template to only trigger for files inside ~/etc/nixos~, and for there to be no template in other cases. We'll also add a template for flakes.
The default Nix file template is for a NixOS module. This is nice when you're writing a module, but most Nix files aren't modules. We'll restrict the default template to only trigger for files inside NixOS configurations, and for there to be no template in other cases. We'll also add a template for flakes.
#+begin_src emacs-lisp
(defvar ~/nixos-config-projects '()
"A list of project directories which contain NixOS configurations.")
(setq ~/nixos-config-projects
(mapcar #'expand-file-name
'("/etc/nixos/" "~/nix/nixos-config/" "~/nix/aether/")))
(set-file-templates!
'(nix-mode :remove t)
'("/etc/nixos/.*\\.nix$" :mode nix-mode)
'(nix-mode :when (lambda (_) (member (doom-project-root) ~/nixos-config-projects)))
'("/flake\\.nix$" :trigger "__flake.nix" :mode nix-mode))
#+end_src