2023-08-27 07:48:57 +02:00
|
|
|
# flakelight -- Framework for simplifying flake setup
|
2023-08-25 06:14:55 +02:00
|
|
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2024-01-15 03:39:15 +01:00
|
|
|
{ config, lib, flakelight, genSystems, moduleArgs, ... }:
|
2023-08-25 06:14:55 +02:00
|
|
|
let
|
2024-02-07 06:52:22 +01:00
|
|
|
inherit (lib) filterAttrs functionArgs mapAttrs mkDefault mkIf mkMerge
|
2024-01-15 03:39:15 +01:00
|
|
|
mkOption;
|
2024-02-07 09:54:03 +01:00
|
|
|
inherit (lib.types) attrs coercedTo functionTo lazyAttrsOf lines listOf
|
2023-12-06 04:44:12 +01:00
|
|
|
package str submodule;
|
2023-08-27 07:48:57 +02:00
|
|
|
inherit (flakelight) supportedSystem;
|
2024-02-07 09:54:03 +01:00
|
|
|
inherit (flakelight.types) function nullable optCallWith optFunctionTo
|
|
|
|
packageDef;
|
2023-12-06 04:44:12 +01:00
|
|
|
|
|
|
|
devShellModule.options = {
|
|
|
|
inputsFrom = mkOption {
|
2024-02-07 06:52:22 +01:00
|
|
|
type = optFunctionTo (listOf package);
|
|
|
|
default = [ ];
|
2023-12-06 04:44:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
packages = mkOption {
|
2024-02-07 06:52:22 +01:00
|
|
|
type = optFunctionTo (listOf package);
|
|
|
|
default = [ ];
|
2023-12-06 04:44:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
shellHook = mkOption {
|
|
|
|
type = optFunctionTo lines;
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
env = mkOption {
|
|
|
|
type = optFunctionTo (lazyAttrsOf str);
|
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
|
|
|
|
stdenv = mkOption {
|
2024-02-07 06:52:22 +01:00
|
|
|
type = optFunctionTo package;
|
2023-12-06 04:44:12 +01:00
|
|
|
default = pkgs: pkgs.stdenv;
|
|
|
|
};
|
|
|
|
|
|
|
|
overrideShell = mkOption {
|
2024-02-07 09:54:03 +01:00
|
|
|
type = nullable packageDef;
|
2023-12-06 04:44:12 +01:00
|
|
|
internal = true;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
};
|
2024-01-15 03:39:15 +01:00
|
|
|
|
2024-02-07 06:52:22 +01:00
|
|
|
wrapFn = fn: pkgs:
|
|
|
|
if (functionArgs fn == { }) || !(package.check (pkgs.callPackage fn { }))
|
|
|
|
then fn pkgs
|
2024-01-15 03:39:15 +01:00
|
|
|
else { overrideShell = fn; };
|
2023-08-25 06:14:55 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2023-12-05 10:27:10 +01:00
|
|
|
devShell = mkOption {
|
|
|
|
default = null;
|
2024-02-07 09:54:03 +01:00
|
|
|
type = nullable (coercedTo function wrapFn
|
2024-02-07 06:52:22 +01:00
|
|
|
(coercedTo attrs (x: _: x)
|
|
|
|
(functionTo (submodule devShellModule))));
|
2023-08-25 06:14:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
devShells = mkOption {
|
2024-01-15 04:17:50 +01:00
|
|
|
type = optCallWith moduleArgs (lazyAttrsOf packageDef);
|
2023-08-25 06:14:55 +02:00
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkMerge [
|
2023-12-05 10:27:10 +01:00
|
|
|
(mkIf (config.devShell != null) {
|
|
|
|
devShells.default = mkDefault ({ pkgs, mkShell }:
|
2024-02-07 06:52:22 +01:00
|
|
|
let cfg = mapAttrs (_: v: v pkgs) (config.devShell pkgs); in
|
2023-12-06 04:44:12 +01:00
|
|
|
mkShell.override { inherit (cfg) stdenv; }
|
|
|
|
(cfg.env // { inherit (cfg) inputsFrom packages shellHook; }));
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf (config.devShell.overrideShell or null != null) {
|
|
|
|
devShells.default = config.devShell.overrideShell;
|
2023-08-25 06:14:55 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf (config.devShells != { }) {
|
2024-01-10 10:16:24 +01:00
|
|
|
outputs.devShells = genSystems (pkgs:
|
|
|
|
filterAttrs (_: supportedSystem pkgs)
|
|
|
|
(mapAttrs (_: v: pkgs.callPackage v { }) config.devShells));
|
2023-08-25 06:14:55 +02:00
|
|
|
})
|
|
|
|
];
|
|
|
|
}
|