From 29738555b1426b985827dc3ac9cc70b6ae3a9928 Mon Sep 17 00:00:00 2001 From: reo101 Date: Mon, 5 Aug 2024 01:12:54 +0300 Subject: [PATCH] feat(shells)!: redefine in terms of `createThings` --- flake.nix | 11 ++--- modules/flake/shells/default.nix | 77 ++++++++++++++++++++++++++++++++ shells/default.nix | 7 --- 3 files changed, 81 insertions(+), 14 deletions(-) create mode 100644 modules/flake/shells/default.nix delete mode 100644 shells/default.nix diff --git a/flake.nix b/flake.nix index 1c52a79..fa45c68 100644 --- a/flake.nix +++ b/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; diff --git a/modules/flake/shells/default.nix b/modules/flake/shells/default.nix new file mode 100644 index 0000000..6f4c2c7 --- /dev/null +++ b/modules/flake/shells/default.nix @@ -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; + }; + }; +} diff --git a/shells/default.nix b/shells/default.nix deleted file mode 100644 index 20f89e7..0000000 --- a/shells/default.nix +++ /dev/null @@ -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; }; -}