From d16bcb693db18b8ab2508cef6400ce1219dac833 Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Fri, 2 Aug 2024 14:25:52 -0600 Subject: pkgs/lib: refactor out of util/ --- pkgs/default.nix | 2 ++ pkgs/lib/default.nix | 4 ++++ pkgs/lib/importAll.nix | 17 +++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 pkgs/lib/default.nix create mode 100644 pkgs/lib/importAll.nix (limited to 'pkgs') diff --git a/pkgs/default.nix b/pkgs/default.nix index d595e04..82f6380 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -3,6 +3,8 @@ with prev.lib; let inherit (final) callPackage fetchpatch; in { + lib = callPackage ./lib { }; + btclone = callPackage ./btclone { }; gem5 = callPackage ./gem5.nix { gem5ISA = "x86"; }; git-aliases = callPackage ./git-aliases.nix { }; diff --git a/pkgs/lib/default.nix b/pkgs/lib/default.nix new file mode 100644 index 0000000..a273758 --- /dev/null +++ b/pkgs/lib/default.nix @@ -0,0 +1,4 @@ +{ callPackage }: +{ + importAll = callPackage ./importAll.nix { }; +} diff --git a/pkgs/lib/importAll.nix b/pkgs/lib/importAll.nix new file mode 100644 index 0000000..30a1dd9 --- /dev/null +++ b/pkgs/lib/importAll.nix @@ -0,0 +1,17 @@ +{ lib }: +{ root, exclude ? [ ] }: +with builtins; with lib; + +# http://chriswarbo.net/projects/nixos/useful_hacks.html +let + basename = removeSuffix ".nix"; + + isMatch = name: type: (hasSuffix ".nix" name || type == "directory") + && ! elem name (map basename exclude); + + entry = name: _: { + name = basename name; + value = import (root + "/${name}"); + }; +in +mapAttrs' entry (filterAttrs isMatch (readDir root)) -- cgit v1.2.3