feat(shells)!: redefine in terms of createThings
This commit is contained in:
parent
5fa16c98ce
commit
29738555b1
3 changed files with 81 additions and 14 deletions
11
flake.nix
11
flake.nix
|
@ -21,19 +21,13 @@
|
|||
./modules/flake/topology
|
||||
./modules/flake/packages
|
||||
./modules/flake/overlays
|
||||
./modules/flake/shells
|
||||
];
|
||||
|
||||
perSystem = { lib, pkgs, system, ... }: {
|
||||
# Apps (`nix run`)
|
||||
apps = import ./apps { inherit pkgs; };
|
||||
|
||||
# Dev Shells (`nix develop`)
|
||||
devShells = import ./shells {
|
||||
inherit inputs;
|
||||
# NOTE: for `nixVersions.monitored`
|
||||
pkgs = pkgs.extend inputs.self.overlays.modifications;
|
||||
};
|
||||
|
||||
# Formatter (`nix fmt`)
|
||||
formatter = pkgs.nixpkgs-fmt;
|
||||
};
|
||||
|
@ -53,6 +47,9 @@
|
|||
# Automatic overlays, see `./modules/flake/overlays/default.nix`
|
||||
autoOverlays.enable = true;
|
||||
|
||||
# Automatic devShells, see `./modules/flake/shells/default.nix`
|
||||
autoDevShells.enable = true;
|
||||
|
||||
# Templates
|
||||
templates = import ./templates {
|
||||
inherit inputs;
|
||||
|
|
77
modules/flake/shells/default.nix
Normal file
77
modules/flake/shells/default.nix
Normal file
|
@ -0,0 +1,77 @@
|
|||
{ lib, config, self, inputs, ... }:
|
||||
|
||||
let
|
||||
inherit (config.lib)
|
||||
createThings;
|
||||
in
|
||||
let
|
||||
createDevShells = baseDir:
|
||||
createThings {
|
||||
inherit baseDir;
|
||||
thingType = "devShell";
|
||||
raw = false;
|
||||
extras.systems = {
|
||||
default = lib.const true;
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options = let
|
||||
inherit (lib) types;
|
||||
in {
|
||||
flake.autoDevShells = lib.mkOption {
|
||||
description = ''
|
||||
Automagically generate devShells from walking directories with Nix files
|
||||
'';
|
||||
type = types.submodule (submodule: {
|
||||
options = {
|
||||
enable = lib.mkEnableOption "Automatic devShells extraction";
|
||||
dir = lib.mkOption {
|
||||
description = ''
|
||||
Base directory of the contained devShells
|
||||
'';
|
||||
type = types.path;
|
||||
default = "${self}/shells";
|
||||
defaultText = ''''${self}/shells'';
|
||||
};
|
||||
result = lib.mkOption {
|
||||
description = ''
|
||||
The resulting automatic devShells
|
||||
'';
|
||||
type = types.attrsOf (types.submodule { options = {
|
||||
devShell = lib.mkOption { type = types.unspecified; };
|
||||
systems = lib.mkOption { type = types.functionTo types.bool; };
|
||||
};});
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
default =
|
||||
lib.optionalAttrs
|
||||
config.flake.autoDevShells.enable
|
||||
(createDevShells config.flake.autoDevShells.dir);
|
||||
};
|
||||
};
|
||||
});
|
||||
default = {};
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
perSystem = { lib, pkgs, system, ... }: let
|
||||
devShells =
|
||||
lib.pipe
|
||||
config.flake.autoDevShells.result
|
||||
[
|
||||
(lib.filterAttrs
|
||||
(name: { devShell, systems }:
|
||||
pkgs.callPackage systems {
|
||||
inherit (pkgs) lib hostPlatform targetPlatform;
|
||||
}))
|
||||
(lib.mapAttrs
|
||||
(name: { devShell, systems }:
|
||||
pkgs.callPackage devShell { inherit inputs; }))
|
||||
];
|
||||
in {
|
||||
inherit devShells;
|
||||
};
|
||||
};
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
# If pkgs is not defined, instanciate nixpkgs from locked commit
|
||||
{ pkgs ? (import ../nixpkgs.nix) { }
|
||||
, inputs
|
||||
, ...
|
||||
}: {
|
||||
default = import ./default { inherit pkgs inputs; };
|
||||
}
|
Loading…
Reference in a new issue