common.nix/flake.nix

39 lines
1.1 KiB
Nix
Raw Normal View History

2024-03-29 22:36:02 +02:00
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
2024-05-23 20:08:11 +03:00
outputs = { nixpkgs, ... }:
let
lib = nixpkgs.lib;
2024-03-29 22:36:02 +02:00
2024-05-23 20:08:11 +03:00
# Stolen from https://github.com/divnix/digga/blob/main/src/importers.nix
rakeLeaves = dirPath:
let
seive = file: type:
# Only rake `.nix` files or directories
(type == "regular" && lib.hasSuffix ".nix" file) || (type == "directory");
2024-03-29 22:36:02 +02:00
2024-05-23 20:08:11 +03:00
collect = file: type: {
name = lib.removeSuffix ".nix" file;
value =
let
path = dirPath + "/${file}";
in
if
(type == "regular")
|| (type == "directory" && builtins.pathExists (path + "/default.nix"))
then path
# recurse on directories that don't contain a `default.nix`
else rakeLeaves path;
};
2024-03-29 22:36:02 +02:00
2024-05-23 20:08:11 +03:00
files = lib.filterAttrs seive (builtins.readDir dirPath);
in
lib.filterAttrs (n: v: v != { }) (lib.mapAttrs' collect files);
2024-03-29 22:36:02 +02:00
in
2024-05-23 20:08:11 +03:00
{
nixosModules = rakeLeaves ./modules;
};
2024-03-29 22:36:02 +02:00
}