From fe5916eb40a9c9942f511dad0abd78f12382c38e Mon Sep 17 00:00:00 2001 From: Archit Gupta Date: Thu, 21 Mar 2024 04:10:38 -0700 Subject: [PATCH] Use submoduleWith instead of submodule This results in not enabling shorthandOnlyDefinesConfig, allowing imports to be set in submodules. This can, for example, allow a devShell to import another devShell's config to extend it. --- builtinModules/apps.nix | 14 ++++++++------ builtinModules/devShells.nix | 4 ++-- tests/default.nix | 8 ++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/builtinModules/apps.nix b/builtinModules/apps.nix index 748095f..f2edb45 100644 --- a/builtinModules/apps.nix +++ b/builtinModules/apps.nix @@ -8,16 +8,18 @@ let inherit (lib) defaultFunctor fix isFunction last mapAttrs mergeDefinitions mkIf mkMerge mkOption mkOptionType; inherit (lib.types) coercedTo enum lazyAttrsOf - optionDescriptionPhrase pathInStore submodule; + optionDescriptionPhrase pathInStore submoduleWith; inherit (flakelight.types) nullable optFunctionTo stringLike; isStorePath = s: match "${storeDir}/[^.][^ \n]*" s != null; - app = submodule { - options = { - type = mkOption { type = enum [ "app" ]; default = "app"; }; - program = mkOption { type = pathInStore // { check = isStorePath; }; }; - }; + app = submoduleWith { + modules = [{ + options = { + type = mkOption { type = enum [ "app" ]; default = "app"; }; + program = mkOption { type = pathInStore // { check = isStorePath; }; }; + }; + }]; }; mkApp = name: pkgs: s: diff --git a/builtinModules/devShells.nix b/builtinModules/devShells.nix index 7c07655..7bca419 100644 --- a/builtinModules/devShells.nix +++ b/builtinModules/devShells.nix @@ -6,7 +6,7 @@ let inherit (lib) filterAttrs functionArgs mapAttrs mkIf mkMerge mkOption; inherit (lib.types) coercedTo lazyAttrsOf lines listOf - package str submodule; + package str submoduleWith; inherit (flakelight) supportedSystem; inherit (flakelight.types) function nullable optCallWith optFunctionTo; @@ -53,7 +53,7 @@ let devShellType = coercedTo function wrapFn (optFunctionTo (coercedTo package packageOverride - (submodule devShellModule))); + (submoduleWith { modules = [ devShellModule ]; }))); genDevShell = pkgs: cfg: if cfg.overrideShell != null then cfg.overrideShell diff --git a/tests/default.nix b/tests/default.nix index bd773d1..22c83e3 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -400,6 +400,14 @@ in }) (f: f ? devShells.x86_64-linux.default); + devShells-import = test + (flakelight ./empty ({ config, ... }: { + devShell.inputsFrom = pkgs: [ pkgs.emacs ]; + devShells.shell1 = pkgs: { imports = [ (config.devShell pkgs) ]; }; + })) + (f: (lib.isDerivation f.devShells.x86_64-linux.default) + && (lib.isDerivation f.devShells.x86_64-linux.shell1)); + overlay = test (flakelight ./empty { overlay = final: prev: { testValue = "hello"; };