diff --git a/dev/flake-module.nix b/dev/flake-module.nix index 5ac60b94..64976b7b 100644 --- a/dev/flake-module.nix +++ b/dev/flake-module.nix @@ -48,4 +48,9 @@ }; }); }; + + # Make some non-standard flake outputs available for exploration in the REPL + # This isn't part of a proper flake anyway (see dev/flake.nix) so we may as + # well leave this on. + debug = true; } diff --git a/lib.nix b/lib.nix index 64c35c12..89098cb1 100644 --- a/lib.nix +++ b/lib.nix @@ -37,8 +37,11 @@ let attrs@{ staticModules ? [ ] }: mkOptionType { name = "deferredModule"; description = "module"; + descriptionClass = "noun"; check = x: isAttrs x || isFunction x || path.check x; - merge = loc: defs: staticModules ++ map (def: lib.setDefaultModuleLocation "${def.file}, via option ${showOption loc}" def.value) defs; + merge = loc: defs: { + imports = staticModules ++ map (def: lib.setDefaultModuleLocation "${def.file}, via option ${showOption loc}" def.value) defs; + }; inherit (submoduleWith { modules = staticModules; }) getSubOptions getSubModules; diff --git a/modules/apps.nix b/modules/apps.nix index 0fd5d7c6..e3952387 100644 --- a/modules/apps.nix +++ b/modules/apps.nix @@ -15,7 +15,9 @@ let }; getExe = x: - "${lib.getBin x}/bin/${x.meta.mainProgram or (throw ''Package ${x.name or ""} does not have meta.mainProgram set, so I don't know how to find the main executable. You can set meta.mainProgram, or pass the full path to executable, e.g. program = "''${pkg}/bin/foo"'')}"; + "${lib.getBin x}/bin/${x.meta.mainProgram or (throw + ''Package ${x.name or ""} does not have meta.mainProgram set, so I don't know how to find the main executable. You can set `meta.mainProgram`, or pass the full path to executable, e.g. program = "''${pkg}/bin/foo"'' + )}"; appType = lib.types.submodule { options = { diff --git a/modules/moduleWithSystem.nix b/modules/moduleWithSystem.nix index e5c70083..e4d397f5 100644 --- a/modules/moduleWithSystem.nix +++ b/modules/moduleWithSystem.nix @@ -9,22 +9,23 @@ let system = config._module.args.system or - config._module.args.pkgs.stdenv.hostPlatform.system or - (throw "moduleWithSystem: Could not determine the configuration's system parameter for this module system application."); + config._module.args.pkgs.stdenv.hostPlatform.system or (throw + "moduleWithSystem: Could not determine the `system` parameter for this module set evaluation." + ); - allArgs = withSystem system (args: args); + allPerSystemArgs = withSystem system (args: args); - lazyArgsPerParameter = f: builtins.mapAttrs - (k: v: allArgs.${k} or (throw "moduleWithSystem: module argument `${k}` does not exist.")) + lazyPerSystemArgsPerParameter = f: builtins.mapAttrs + (k: v: allPerSystemArgs.${k} or (throw "moduleWithSystem: per-system argument `${k}` does not exist.")) (builtins.functionArgs f); # Use reflection to make the call lazy in the argument. # Restricts args to the ones declared. - callLazily = f: a: f (lazyArgsPerParameter f); + callLazily = f: a: f (lazyPerSystemArgsPerParameter f); in { imports = [ - (callLazily module allArgs) + (callLazily module allPerSystemArgs) ]; }; }; diff --git a/modules/nixpkgs.nix b/modules/nixpkgs.nix index 44df9158..730af495 100644 --- a/modules/nixpkgs.nix +++ b/modules/nixpkgs.nix @@ -13,11 +13,13 @@ # { config = { - perSystem = { inputs', lib, ... }: { + perSystem = { inputs', lib, options, ... }: { config = { _module.args.pkgs = lib.mkOptionDefault ( builtins.seq - (inputs'.nixpkgs or (throw "flake-parts: The flake does not have a `nixpkgs` input. Please add it, or set `perSystem._module.args.pkgs` yourself.")) + inputs'.nixpkgs or (throw + "flake-parts: The flake does not have a `nixpkgs` input. Please add it, or set `${options._module.args}.pkgs` yourself." + ) inputs'.nixpkgs.legacyPackages ); }; diff --git a/modules/perSystem.nix b/modules/perSystem.nix index 499858a2..4b20e55b 100644 --- a/modules/perSystem.nix +++ b/modules/perSystem.nix @@ -119,9 +119,9 @@ in _module.args.moduleWithSystem = throwAliasError "moduleWithSystem"; }; }); - apply = modules: system: + apply = module: system: (lib.evalModules { - inherit modules; + modules = [ module ]; prefix = [ "perSystem" system ]; specialArgs = { inherit system;