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-10 10:16:24 +01:00
|
|
|
{ config, lib, flakelight, genSystems, ... }:
|
2023-08-25 06:14:55 +02:00
|
|
|
let
|
2023-12-05 10:27:10 +01:00
|
|
|
inherit (lib) filterAttrs mapAttrs mkDefault mkIf mkMerge mkOption;
|
2023-12-06 04:44:12 +01:00
|
|
|
inherit (lib.types) coercedTo functionTo lazyAttrsOf lines listOf nullOr
|
|
|
|
package str submodule;
|
2023-08-27 07:48:57 +02:00
|
|
|
inherit (flakelight) supportedSystem;
|
|
|
|
inherit (flakelight.types) optFunctionTo packageDef;
|
2023-12-06 04:44:12 +01:00
|
|
|
|
|
|
|
devShellModule.options = {
|
|
|
|
inputsFrom = mkOption {
|
|
|
|
type = functionTo (listOf package);
|
|
|
|
default = _: [ ];
|
|
|
|
};
|
|
|
|
|
|
|
|
packages = mkOption {
|
|
|
|
type = functionTo (listOf package);
|
|
|
|
default = _: [ ];
|
|
|
|
};
|
|
|
|
|
|
|
|
shellHook = mkOption {
|
|
|
|
type = optFunctionTo lines;
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
env = mkOption {
|
|
|
|
type = optFunctionTo (lazyAttrsOf str);
|
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
|
|
|
|
stdenv = mkOption {
|
|
|
|
type = functionTo package;
|
|
|
|
default = pkgs: pkgs.stdenv;
|
|
|
|
};
|
|
|
|
|
|
|
|
overrideShell = mkOption {
|
|
|
|
type = nullOr packageDef;
|
|
|
|
internal = true;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
};
|
2023-08-25 06:14:55 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2023-12-05 10:27:10 +01:00
|
|
|
devShell = mkOption {
|
|
|
|
default = null;
|
2023-12-06 04:44:12 +01:00
|
|
|
type = nullOr (coercedTo packageDef
|
|
|
|
(x: { overrideShell = x; })
|
|
|
|
(submodule devShellModule));
|
2023-08-25 06:14:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
devShells = mkOption {
|
|
|
|
type = lazyAttrsOf packageDef;
|
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkMerge [
|
2023-12-05 10:27:10 +01:00
|
|
|
(mkIf (config.devShell != null) {
|
|
|
|
devShells.default = mkDefault ({ pkgs, mkShell }:
|
2023-12-06 04:44:12 +01:00
|
|
|
let cfg = mapAttrs (_: v: v pkgs) config.devShell; in
|
|
|
|
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
|
|
|
})
|
|
|
|
];
|
|
|
|
}
|