2023-03-07 11:25:53 +01:00
|
|
|
{ lib, ... }:
|
|
|
|
|
2023-04-10 15:12:45 +02:00
|
|
|
lib.makeExtensible (_: rec {
|
2023-03-07 11:25:53 +01:00
|
|
|
mkDate = longDate: lib.concatStringsSep "-" [
|
|
|
|
(builtins.substring 0 4 longDate)
|
|
|
|
(builtins.substring 4 2 longDate)
|
|
|
|
(builtins.substring 6 2 longDate)
|
|
|
|
];
|
|
|
|
mkVersionSrc = src: "unstable-" + builtins.substring 0 7 src.rev;
|
|
|
|
mkVersionInput = input:
|
|
|
|
let
|
|
|
|
date = mkDate (input.lastModifiedDate or "19700101");
|
|
|
|
rev = input.shortRev or "dirty";
|
|
|
|
in
|
2023-03-09 16:15:58 +01:00
|
|
|
"unstable-${date}_${rev}";
|
2023-03-11 16:56:22 +01:00
|
|
|
|
|
|
|
mapModules = f: dir:
|
|
|
|
let
|
2023-04-10 15:23:33 +02:00
|
|
|
filterModules = name: type:
|
2023-03-11 16:56:22 +01:00
|
|
|
let
|
|
|
|
isPublic = !(lib.hasPrefix "_" name);
|
|
|
|
isSomething = type != null;
|
|
|
|
isModule =
|
|
|
|
let
|
|
|
|
path = "${toString dir}/${name}";
|
|
|
|
isDefault = type == "directory" && builtins.pathExists "${path}/default.nix";
|
|
|
|
isFile = type == "regular" && lib.hasSuffix ".nix" name && name != "default.nix";
|
|
|
|
in
|
|
|
|
isDefault || isFile;
|
|
|
|
in
|
|
|
|
isPublic && isSomething && isModule;
|
|
|
|
|
2023-04-10 15:23:33 +02:00
|
|
|
modulesInDir = lib.filterAttrs filterModules (builtins.readDir dir);
|
|
|
|
|
2023-03-11 16:56:22 +01:00
|
|
|
mkModule = name: _:
|
|
|
|
let
|
|
|
|
path = "${toString dir}/${name}";
|
|
|
|
normalizedName =
|
|
|
|
if name == "default.nix"
|
|
|
|
then name
|
|
|
|
else lib.removeSuffix ".nix" name;
|
|
|
|
in
|
|
|
|
lib.nameValuePair normalizedName (f path);
|
|
|
|
in
|
2023-04-10 15:23:33 +02:00
|
|
|
lib.mapAttrs' mkModule modulesInDir;
|
2023-03-11 16:56:22 +01:00
|
|
|
|
|
|
|
mapModules' = f: dir: lib.attrValues (mapModules f dir);
|
2023-05-07 13:51:09 +02:00
|
|
|
|
|
|
|
listModules = mapModules' (path: path);
|
2023-05-11 17:33:14 +02:00
|
|
|
|
|
|
|
mapModulesRec = f: dir:
|
|
|
|
let
|
|
|
|
filterDirs = name: type:
|
|
|
|
let
|
|
|
|
isPublic = !(lib.hasPrefix "_" name);
|
|
|
|
isSomething = type != null;
|
|
|
|
isDir = type == "directory";
|
|
|
|
isDefault = isDir && builtins.pathExists "${toString dir}/${name}/default.nix";
|
|
|
|
in
|
|
|
|
isPublic && isSomething && isDir && !isDefault;
|
|
|
|
|
|
|
|
subDirs = lib.filterAttrs filterDirs (builtins.readDir dir);
|
|
|
|
|
|
|
|
mkSubModule = name: _:
|
|
|
|
let
|
|
|
|
path = "${toString dir}/${name}";
|
|
|
|
in
|
|
|
|
lib.nameValuePair name (mapModulesRec f path);
|
|
|
|
in
|
|
|
|
mapModules f dir //
|
|
|
|
(lib.mapAttrs' mkSubModule subDirs);
|
|
|
|
|
|
|
|
mapModulesRec' = f: dir:
|
|
|
|
let
|
|
|
|
attrValuesRec = attrs: map (values: if lib.isAttrs values then attrValuesRec values else values) (lib.attrValues attrs);
|
|
|
|
in
|
|
|
|
lib.flatten (attrValuesRec (mapModulesRec f dir));
|
|
|
|
|
|
|
|
listModulesRec = mapModulesRec' (path: path);
|
2023-03-07 11:25:53 +01:00
|
|
|
})
|