From 1e8a89e5f81bca67c5f649318179fc11727262d0 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Tue, 9 May 2023 09:41:01 -0700 Subject: [PATCH] Add moduleLocation to mkFlake argument tmp --- extras/flakeModules.nix | 6 +++--- lib.nix | 11 +++++++---- modules/nixosModules.nix | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/extras/flakeModules.nix b/extras/flakeModules.nix index 6468dcb..d4e0e63 100644 --- a/extras/flakeModules.nix +++ b/extras/flakeModules.nix @@ -1,4 +1,4 @@ -{ config, self, lib, flake-parts-lib, ... }: +{ config, self, lib, flake-parts-lib, moduleLocation, ... }: let inherit (lib) filterAttrs @@ -15,8 +15,8 @@ let type = types.lazyAttrsOf types.deferredModule; default = { }; apply = mapAttrs (k: v: { - _file = "${toString self.outPath}/flake.nix#flakeModules.${k}"; - key = "${toString self.outPath}/flake.nix#flakeModules.${k}"; + _file = "${toString moduleLocation}#flakeModules.${k}"; + key = "${toString moduleLocation}#flakeModules.${k}"; imports = [ v ]; }); description = '' diff --git a/lib.nix b/lib.nix index ae588c8..102dabb 100644 --- a/lib.nix +++ b/lib.nix @@ -98,6 +98,7 @@ let ${errorExample} '') + , moduleLocation ? "${self.outPath}/flake.nix" }: throwIf (!args?self && !args?inputs) '' @@ -117,7 +118,7 @@ let (module: lib.evalModules { specialArgs = { - inherit self flake-parts-lib; + inherit self flake-parts-lib moduleLocation; inputs = args.inputs or /* legacy, warned above */ self.inputs; } // specialArgs; modules = [ ./all-modules.nix module ]; @@ -138,9 +139,11 @@ let mkFlake = args: module: let loc = - if args?inputs.self.outPath - then args.inputs.self.outPath + "/flake.nix" - else ""; + args.moduleLocation or ( + if args?inputs.self.outPath + then args.inputs.self.outPath + "/flake.nix" + else "" + ); mod = lib.setDefaultModuleLocation loc module; eval = flake-parts-lib.evalFlakeModule args mod; in diff --git a/modules/nixosModules.nix b/modules/nixosModules.nix index 1d21f9e..be375bb 100644 --- a/modules/nixosModules.nix +++ b/modules/nixosModules.nix @@ -1,4 +1,4 @@ -{ config, self, lib, flake-parts-lib, ... }: +{ config, self, lib, flake-parts-lib, moduleLocation, ... }: let inherit (lib) filterAttrs @@ -17,7 +17,7 @@ in nixosModules = mkOption { type = types.lazyAttrsOf types.unspecified; 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 = '' NixOS modules.