From 165c4030723ed33a8743e25758967f33c9bfe924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Mon, 21 Apr 2025 19:56:24 +0200 Subject: [PATCH] refactor(scripts): remove unnecessary imports They slow down evaluations --- flake-modules/default.nix | 2 +- flake-modules/scripts.nix | 14 -------------- scripts/default.nix | 30 ++++++++++++++++++++++-------- 3 files changed, 23 insertions(+), 23 deletions(-) delete mode 100644 flake-modules/scripts.nix diff --git a/flake-modules/default.nix b/flake-modules/default.nix index ce3e3c5..6b81037 100644 --- a/flake-modules/default.nix +++ b/flake-modules/default.nix @@ -13,7 +13,7 @@ in ./home-modules.nix ./nixvim-modules.nix ./overlays.nix - ./scripts.nix + ../scripts ]; perSystem = diff --git a/flake-modules/scripts.nix b/flake-modules/scripts.nix deleted file mode 100644 index 590f6a1..0000000 --- a/flake-modules/scripts.nix +++ /dev/null @@ -1,14 +0,0 @@ -let - scripts = import ../scripts; -in -{ - # Add scripts to overlay - flake.overlays.scripts = final: prev: scripts final; - - # Add scripts to packages - perSystem = - { pkgs, ... }: - { - packages = scripts pkgs; - }; -} diff --git a/scripts/default.nix b/scripts/default.nix index 23ec010..1894de7 100644 --- a/scripts/default.nix +++ b/scripts/default.nix @@ -1,23 +1,37 @@ -# Autodetects files with a package.nix and calls `callPackage` on them. -# -# Will add a package .#dirname to the flake if it finds a ./dirname/package.nix file. +{ lib, ... }: let - files = builtins.readDir ./.; + src = ./.; + # Autodetects files with a package.nix and calls `callPackage` on them. + # + # Will add a package .#dirname to the flake if it finds a ./dirname/package.nix file. + files = builtins.readDir src; isPackage = path: type: (type == "directory") && (builtins.readDir path) ? "package.nix"; toPackage = name: pkgs: { inherit name; - value = pkgs.callPackage (./. + "/${name}/package.nix") { }; + value = pkgs.callPackage "${src}/${name}/package.nix" { }; }; # call pkgs.callPackage on all ./*/package.nix makePackage = pkgs: name: let type = files.${name}; - path = ./. + "/${name}"; + path = "${src}/${name}"; package = toPackage name pkgs; in # if it is a package then return a package otherwise return no package c: if isPackage path type then [ package ] else [ ]; + # we have lib.filterMapAttrs at home + scripts = + pkgs: builtins.listToAttrs (builtins.concatMap (makePackage pkgs) (builtins.attrNames files)); in -# we have lib.filterMapAttrs at home -pkgs: builtins.listToAttrs (builtins.concatMap (makePackage pkgs) (builtins.attrNames files)) +{ + # Add scripts to overlay + flake.overlays.scripts = final: scripts; + + # Add scripts to packages + perSystem = + { pkgs, ... }: + { + packages = scripts pkgs; + }; +}