mirror of
https://github.com/nix-community/flakelight.git
synced 2025-08-14 09:08:38 +02:00
Allow devShell to be a package def or take args
Previously, devShell was inconsistent when setting it to a function. When setting directly, a function was assumed to be a package definition and was used to set devShells.default directly. When auto-loading, a function was assumed to take module args, and result in config (not a derivation). This now enables both behaviors in either case by detecting if a function is a package definition or if it expects module args and handling it accordingly.
This commit is contained in:
@ -2,13 +2,15 @@
|
||||
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
{ config, lib, flakelight, genSystems, ... }:
|
||||
{ config, lib, flakelight, genSystems, moduleArgs, ... }:
|
||||
let
|
||||
inherit (lib) filterAttrs mapAttrs mkDefault mkIf mkMerge mkOption;
|
||||
inherit (builtins) attrNames hasAttr;
|
||||
inherit (lib) all filterAttrs functionArgs mapAttrs mkDefault mkIf mkMerge
|
||||
mkOption;
|
||||
inherit (lib.types) coercedTo functionTo lazyAttrsOf lines listOf nullOr
|
||||
package str submodule;
|
||||
inherit (flakelight) supportedSystem;
|
||||
inherit (flakelight.types) optFunctionTo packageDef;
|
||||
inherit (flakelight.types) function optFunctionTo packageDef;
|
||||
|
||||
devShellModule.options = {
|
||||
inputsFrom = mkOption {
|
||||
@ -42,13 +44,17 @@ let
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
|
||||
moduleFromFn = fn:
|
||||
if all (a: hasAttr a moduleArgs) (attrNames (functionArgs fn))
|
||||
then fn moduleArgs
|
||||
else { overrideShell = fn; };
|
||||
in
|
||||
{
|
||||
options = {
|
||||
devShell = mkOption {
|
||||
default = null;
|
||||
type = nullOr (coercedTo packageDef
|
||||
(x: { overrideShell = x; })
|
||||
type = nullOr (coercedTo function moduleFromFn
|
||||
(submodule devShellModule));
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user