diff --git a/checks/flake-module.nix b/checks/flake-module.nix index c783ebaca..46a4d9440 100644 --- a/checks/flake-module.nix +++ b/checks/flake-module.nix @@ -18,19 +18,6 @@ { checks = let - # ensure all options can be rendered after importing clan into nixos - renderClanOptions = - let - docs = pkgs.nixosOptionsDoc { - options = - (pkgs.nixos { - imports = [ self.nixosModules.clanCore ]; - clan.core.clanDir = ./.; - }).options; - warningsAreErrors = false; - }; - in - docs.optionsJSON; nixosTestArgs = { # reference to nixpkgs for the current system inherit pkgs; @@ -61,7 +48,7 @@ self'.legacyPackages.homeConfigurations or { } ); in - { inherit renderClanOptions; } // nixosTests // flakeOutputs; + nixosTests // flakeOutputs; legacyPackages = { nixosTests = let diff --git a/docs/nix/flake-module.nix b/docs/nix/flake-module.nix index 4793962eb..5a8ffa3c6 100644 --- a/docs/nix/flake-module.nix +++ b/docs/nix/flake-module.nix @@ -11,11 +11,9 @@ buildClanOptions = self'.legacyPackages.clan-internals-docs; # Simply evaluated options (JSON) # { clanCore = «derivation JSON»; clanModules = { ${name} = «derivation JSON» }; } - jsonDocs = import ./get-module-docs.nix { - inherit (inputs) nixpkgs; - inherit pkgs; - inherit (self.nixosModules) clanCore; + jsonDocs = pkgs.callPackage ./get-module-docs.nix { inherit (self) clanModules; + evalClanModules = self.lib.evalClanModules; }; clanModulesFileInfo = pkgs.writeText "info.json" (builtins.toJSON jsonDocs.clanModules); diff --git a/docs/nix/get-module-docs.nix b/docs/nix/get-module-docs.nix index 840721375..d78d9be6f 100644 --- a/docs/nix/get-module-docs.nix +++ b/docs/nix/get-module-docs.nix @@ -1,47 +1,22 @@ { - nixpkgs, - pkgs, - clanCore, + nixosOptionsDoc, clanModules, + evalClanModules, + lib, }: -let - allNixosModules = (import "${nixpkgs}/nixos/modules/module-list.nix") ++ [ - "${nixpkgs}/nixos/modules/misc/assertions.nix" - { nixpkgs.hostPlatform = "x86_64-linux"; } - ]; - - clanCoreNixosModules = [ - clanCore - { clan.core.clanDir = ./.; } - ] ++ allNixosModules; - - # TODO: optimally we would not have to evaluate all nixos modules for every page - # but some of our module options secretly depend on nixos modules. - # We would have to get rid of these implicit dependencies and make them explicit - clanCoreNixos = pkgs.nixos { imports = clanCoreNixosModules; }; - - # using extendModules here instead of re-evaluating nixos every time - # improves eval performance slightly (10%) - getOptions = modules: (clanCoreNixos.extendModules { inherit modules; }).options; - - getOptionsWithoutCore = modules: builtins.removeAttrs (getOptions modules) [ "core" ]; - - evalDocs = - options: - pkgs.nixosOptionsDoc { - options = options; - warningsAreErrors = true; - }; - +{ # clanModules docs - clanModulesDocs = builtins.mapAttrs ( - name: module: (evalDocs ((getOptionsWithoutCore [ module ]).clan.${name} or { })).optionsJSON + clanModules = lib.mapAttrs ( + name: module: + (nixosOptionsDoc { + options = ((evalClanModules [ module ]).options).clan.${name} or { }; + warningsAreErrors = true; + }).optionsJSON ) clanModules; - # clanCore docs - clanCoreDocs = (evalDocs (getOptions [ ]).clan.core).optionsJSON; -in -{ - clanCore = clanCoreDocs; - clanModules = clanModulesDocs; + clanCore = + (nixosOptionsDoc { + options = ((evalClanModules [ ]).options).clan.core or { }; + warningsAreErrors = true; + }).optionsJSON; } diff --git a/lib/default.nix b/lib/default.nix index 1faa640d0..530ddd620 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -5,7 +5,10 @@ ... }: let - eval = import ./eval-clan-modules { inherit clan-core nixpkgs lib; }; + eval = import ./eval-clan-modules { + inherit clan-core lib; + pkgs = nixpkgs.legacyPackages.x86_64-linux; + }; in { inherit (eval) evalClanModules evalClanModulesWithRoles; diff --git a/lib/eval-clan-modules/default.nix b/lib/eval-clan-modules/default.nix index b501ae461..a5d4f5995 100644 --- a/lib/eval-clan-modules/default.nix +++ b/lib/eval-clan-modules/default.nix @@ -1,26 +1,23 @@ { - nixpkgs, clan-core, lib, + pkgs, }: let - inherit (import nixpkgs { system = "x86_64-linux"; }) pkgs; - - inherit (clan-core) clanModules; - baseModule = { imports = (import (pkgs.path + "/nixos/modules/module-list.nix")) ++ [ { - nixpkgs.hostPlatform = "x86_64-linux"; + nixpkgs.pkgs = pkgs; clan.core.name = "dummy"; + system.stateVersion = lib.version; } ]; }; # This function takes a list of module names and evaluates them - # evalClanModules :: [ String ] -> { config, options, ... } + # evalClanModules :: [ module ] -> { config, options, ... } evalClanModulesLegacy = - modulenames: + modules: let evaled = lib.evalModules { modules = [ @@ -29,7 +26,7 @@ let clan.core.clanDir = clan-core; } clan-core.nixosModules.clanCore - ] ++ (map (name: clanModules.${name}) modulenames); + ] ++ modules; }; in # lib.warn '' diff --git a/pkgs/schemas/flake-module.nix b/pkgs/schemas/flake-module.nix index e9e186874..648903b5f 100644 --- a/pkgs/schemas/flake-module.nix +++ b/pkgs/schemas/flake-module.nix @@ -12,23 +12,18 @@ # borgbackup = self.clanModules.borgbackup; # }; - optionsFromModule = - mName: - let - eval = self.lib.evalClanModules [ mName ]; - in - if (eval.options.clan ? "${mName}") then eval.options.clan.${mName} else { }; + optionsFromModule = name: module: (self.lib.evalClanModules [ module ]).options.clan.${name} or { }; clanModuleSchemas = lib.mapAttrs ( - modulename: _: jsonLib.parseOptions (optionsFromModule modulename) { } + name: module: jsonLib.parseOptions (optionsFromModule name module) { } ) clanModules; clanModuleFunctionSchemas = lib.attrsets.mapAttrsToList ( - modulename: _: + modulename: module: (self.lib.modules.getFrontmatter modulename) // { name = modulename; - parameters = jsonLib.parseOptions (optionsFromModule modulename) { }; + parameters = jsonLib.parseOptions (optionsFromModule modulename module) { }; } ) clanModules; in