1
0
Fork 0
mirror of https://github.com/hercules-ci/flake-parts.git synced 2025-03-16 13:28:20 +00:00

Add moduleLocation to mkFlake argument

tmp
This commit is contained in:
Yang, Bo 2023-05-09 09:41:01 -07:00
parent 006c75898c
commit 1e8a89e5f8
3 changed files with 12 additions and 9 deletions

View file

@ -1,4 +1,4 @@
{ config, self, lib, flake-parts-lib, ... }: { config, self, lib, flake-parts-lib, moduleLocation, ... }:
let let
inherit (lib) inherit (lib)
filterAttrs filterAttrs
@ -15,8 +15,8 @@ let
type = types.lazyAttrsOf types.deferredModule; type = types.lazyAttrsOf types.deferredModule;
default = { }; default = { };
apply = mapAttrs (k: v: { apply = mapAttrs (k: v: {
_file = "${toString self.outPath}/flake.nix#flakeModules.${k}"; _file = "${toString moduleLocation}#flakeModules.${k}";
key = "${toString self.outPath}/flake.nix#flakeModules.${k}"; key = "${toString moduleLocation}#flakeModules.${k}";
imports = [ v ]; imports = [ v ];
}); });
description = '' description = ''

11
lib.nix
View file

@ -98,6 +98,7 @@ let
${errorExample} ${errorExample}
'') '')
, moduleLocation ? "${self.outPath}/flake.nix"
}: }:
throwIf throwIf
(!args?self && !args?inputs) '' (!args?self && !args?inputs) ''
@ -117,7 +118,7 @@ let
(module: (module:
lib.evalModules { lib.evalModules {
specialArgs = { specialArgs = {
inherit self flake-parts-lib; inherit self flake-parts-lib moduleLocation;
inputs = args.inputs or /* legacy, warned above */ self.inputs; inputs = args.inputs or /* legacy, warned above */ self.inputs;
} // specialArgs; } // specialArgs;
modules = [ ./all-modules.nix module ]; modules = [ ./all-modules.nix module ];
@ -138,9 +139,11 @@ let
mkFlake = args: module: mkFlake = args: module:
let let
loc = loc =
if args?inputs.self.outPath args.moduleLocation or (
then args.inputs.self.outPath + "/flake.nix" if args?inputs.self.outPath
else "<mkFlake argument>"; then args.inputs.self.outPath + "/flake.nix"
else "<mkFlake argument>"
);
mod = lib.setDefaultModuleLocation loc module; mod = lib.setDefaultModuleLocation loc module;
eval = flake-parts-lib.evalFlakeModule args mod; eval = flake-parts-lib.evalFlakeModule args mod;
in in

View file

@ -1,4 +1,4 @@
{ config, self, lib, flake-parts-lib, ... }: { config, self, lib, flake-parts-lib, moduleLocation, ... }:
let let
inherit (lib) inherit (lib)
filterAttrs filterAttrs
@ -17,7 +17,7 @@ in
nixosModules = mkOption { nixosModules = mkOption {
type = types.lazyAttrsOf types.unspecified; type = types.lazyAttrsOf types.unspecified;
default = { }; default = { };
apply = mapAttrs (k: v: { _file = "${toString self.outPath}/flake.nix#nixosModules.${k}"; imports = [ v ]; }); apply = mapAttrs (k: v: { _file = "${toString moduleLocation}#nixosModules.${k}"; imports = [ v ]; });
description = '' description = ''
NixOS modules. NixOS modules.