From 04fef22dc3cefbc27a651826adebb882e52a3a0c Mon Sep 17 00:00:00 2001 From: valentin gagarin Date: Wed, 13 Nov 2024 15:24:41 +0100 Subject: [PATCH] extract importing Nix files --- website/content/default.nix | 2 +- website/lib.nix | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/website/content/default.nix b/website/content/default.nix index fd140183..8cc4daa9 100644 --- a/website/content/default.nix +++ b/website/content/default.nix @@ -3,7 +3,7 @@ let inherit (config) pages; in { - imports = with lib.fileset; toList (difference (fileFilter ({ hasExt, ... }: hasExt "nix") ./.) ./default.nix); + imports = lib.nixFiles ./.; collections.news.type = config.content-types.article; diff --git a/website/lib.nix b/website/lib.nix index 4423cbf2..cedef3c9 100644 --- a/website/lib.nix +++ b/website/lib.nix @@ -65,6 +65,17 @@ rec { in join "/" relativeComponents; + /** + Recursively list all Nix files from a directory, except the top-level `default.nix` + + Useful for module system `imports` from a top-level module. + **/ + nixFiles = dir: with lib.fileset; + toList (difference + (fileFilter ({ hasExt, ... }: hasExt "nix") dir) + (dir + "/default.nix") + ); + types = rec { collection = elemType: let