From ace4288c9dd523a3bfb1abb4cf0c7a39a8ee90f5 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Tue, 7 Feb 2023 14:24:32 -0500 Subject: [PATCH] Modify flake.nix to make dev shells optional --- flake.nix | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index cf65e5a..e0f05d9 100644 --- a/flake.nix +++ b/flake.nix @@ -10,11 +10,19 @@ flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; + inherit (pkgs) lib; + # Check if project has a shell.nix + hasShell = dir: (builtins.readDir ./${dir}) ? "shell.nix"; + + # Get all project directories currentDir = builtins.readDir ./.; - dirs = pkgs.lib.filterAttrs (_: v: v == "directory") currentDir; - in { - packages = builtins.mapAttrs (dir: _: pkgs.callPackage ./${dir} {}) dirs; - devShells = builtins.mapAttrs (dir: _: pkgs.callPackage ./${dir}/shell.nix {}) dirs; - }); + dirs = lib.filterAttrs (_: v: v == "directory") currentDir; + in + lib.concatMapAttrs (dir: _: { + packages.${dir} = pkgs.callPackage ./${dir} {}; + } // lib.optionalAttrs (hasShell dir) { + devShells.${dir} = pkgs.callPackage ./${dir}/shell.nix {}; + }) dirs + ); }