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-03-24 22:23:41 +01:00
|
|
|
inherit (lib) functionArgs mapAttrs mkIf mkMerge mkOption;
|
2024-02-22 03:40:32 +01:00
|
|
|
inherit (lib.types) coercedTo lazyAttrsOf lines listOf
|
2024-03-21 12:10:38 +01:00
|
|
|
package str submoduleWith;
|
2024-02-07 10:15:56 +01:00
|
|
|
inherit (flakelight.types) function nullable optCallWith optFunctionTo;
|
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 = "";
|
|
|
|
};
|
|
|
|
|
2024-10-31 05:52:12 +01:00
|
|
|
hardeningDisable = mkOption {
|
|
|
|
type = listOf str;
|
|
|
|
default = [ ];
|
|
|
|
};
|
|
|
|
|
2023-12-06 04:44:12 +01:00
|
|
|
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 10:15:56 +01:00
|
|
|
type = nullable package;
|
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:
|
2024-02-07 10:15:56 +01:00
|
|
|
let val = pkgs.callPackage fn { }; in
|
|
|
|
if (functionArgs fn == { }) || !(package.check val)
|
2024-02-07 06:52:22 +01:00
|
|
|
then fn pkgs
|
2024-02-26 03:40:05 +01:00
|
|
|
else val;
|
|
|
|
|
|
|
|
packageOverride = p: { overrideShell = p; };
|
2024-02-07 10:15:56 +01:00
|
|
|
|
|
|
|
devShellType = coercedTo function wrapFn
|
2024-02-26 03:40:05 +01:00
|
|
|
(optFunctionTo (coercedTo package packageOverride
|
2024-03-21 12:10:38 +01:00
|
|
|
(submoduleWith { modules = [ devShellModule ]; })));
|
2024-02-07 10:15:56 +01:00
|
|
|
|
|
|
|
genDevShell = pkgs: cfg:
|
|
|
|
if cfg.overrideShell != null then cfg.overrideShell
|
|
|
|
else
|
|
|
|
let cfg' = mapAttrs (_: v: v pkgs) cfg; in
|
|
|
|
pkgs.mkShell.override { inherit (cfg') stdenv; }
|
2024-10-31 05:52:12 +01:00
|
|
|
(cfg'.env // {
|
|
|
|
inherit (cfg') inputsFrom packages shellHook;
|
|
|
|
inherit (cfg) hardeningDisable;
|
|
|
|
});
|
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 10:15:56 +01:00
|
|
|
type = nullable devShellType;
|
2023-08-25 06:14:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
devShells = mkOption {
|
2024-02-07 10:15:56 +01:00
|
|
|
type = optCallWith moduleArgs (lazyAttrsOf devShellType);
|
2023-08-25 06:14:55 +02:00
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkMerge [
|
2023-12-05 10:27:10 +01:00
|
|
|
(mkIf (config.devShell != null) {
|
2024-02-07 10:15:56 +01:00
|
|
|
devShells.default = config.devShell;
|
2023-08-25 06:14:55 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf (config.devShells != { }) {
|
2024-01-10 10:16:24 +01:00
|
|
|
outputs.devShells = genSystems (pkgs:
|
2024-03-24 22:23:41 +01:00
|
|
|
mapAttrs (_: v: genDevShell pkgs (v pkgs)) config.devShells);
|
2023-08-25 06:14:55 +02:00
|
|
|
})
|
|
|
|
];
|
|
|
|
}
|