configuration.nix/scripts/default.nix
Jalil David Salamé Messina 165c403072
All checks were successful
/ check (push) Successful in 9s
/ check-renovaterc (push) Successful in 3s
/ build-packages (push) Successful in 13s
/ build-vm (push) Successful in 1s
/ report-size (push) Successful in 4s
refactor(scripts): remove unnecessary imports
They slow down evaluations
2025-04-21 20:51:28 +02:00

37 lines
1.1 KiB
Nix

{ lib, ... }:
let
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 "${src}/${name}/package.nix" { };
};
# call pkgs.callPackage on all ./*/package.nix
makePackage =
pkgs: name:
let
type = files.${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
{
# Add scripts to overlay
flake.overlays.scripts = final: scripts;
# Add scripts to packages
perSystem =
{ pkgs, ... }:
{
packages = scripts pkgs;
};
}