From a9dc191c2f2be5c217a9d4e996555758a7d176cb Mon Sep 17 00:00:00 2001 From: Hektor Misplon Date: Fri, 22 May 2026 10:06:44 +0200 Subject: [PATCH] chore(hooks): enforce enable option on all home modules --- home/modules/default.nix | 73 +++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/home/modules/default.nix b/home/modules/default.nix index 7e7c9c0d..20555de1 100644 --- a/home/modules/default.nix +++ b/home/modules/default.nix @@ -5,33 +5,52 @@ ... }: -{ - options = { - host.username = lib.mkOption { - type = lib.types.str; - default = config.home.username; - }; +let + moduleDirs = lib.filterAttrs (_: v: v == "directory") (builtins.readDir ./.); + dirHasEnableOption = + name: + let + nixFiles = lib.filterAttrs (n: v: v == "regular" && lib.hasSuffix ".nix" n) ( + builtins.readDir ./${name} + ); + in + !(builtins.pathExists ./${name}/default.nix) + || lib.any (f: lib.hasInfix "mkEnableOption" (builtins.readFile ./${name}/${f})) ( + builtins.attrNames nixFiles + ); + withoutEnableOption = builtins.attrNames ( + lib.filterAttrs (name: _: !dirHasEnableOption name) moduleDirs + ); +in +lib.throwIf (withoutEnableOption != [ ]) + "home modules missing enable option: ${lib.concatStringsSep ", " withoutEnableOption}" + { + options = { + host.username = lib.mkOption { + type = lib.types.str; + default = config.home.username; + }; - nixgl.wrap = lib.mkOption { - type = lib.types.functionTo lib.types.package; - default = if config.lib ? nixGL then config.lib.nixGL.wrap else lib.id; - readOnly = true; - }; + nixgl.wrap = lib.mkOption { + type = lib.types.functionTo lib.types.package; + default = if config.lib ? nixGL then config.lib.nixGL.wrap else lib.id; + readOnly = true; + }; - wrapApp = lib.mkOption { - type = lib.types.raw; - default = - pkg: flags: - if config.lib ? nixGL then - pkg.overrideAttrs (old: { - nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.makeWrapper ]; - postInstall = (old.postInstall or "") + '' - wrapProgram $out/bin/${pkg.meta.mainProgram} --add-flags "${flags}" - ''; - }) - else - pkg; - readOnly = true; + wrapApp = lib.mkOption { + type = lib.types.raw; + default = + pkg: flags: + if config.lib ? nixGL then + pkg.overrideAttrs (old: { + nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.makeWrapper ]; + postInstall = (old.postInstall or "") + '' + wrapProgram $out/bin/${pkg.meta.mainProgram} --add-flags "${flags}" + ''; + }) + else + pkg; + readOnly = true; + }; }; - }; -} + }