47 lines
1.4 KiB
Nix
47 lines
1.4 KiB
Nix
{ lib, ... }:
|
|
|
|
lib.makeExtensible (_: rec {
|
|
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
|
|
"unstable-${date}_${rev}";
|
|
|
|
mapModules = f: dir:
|
|
let
|
|
filter = name: type:
|
|
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;
|
|
|
|
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
|
|
lib.mapAttrs' mkModule (lib.filterAttrs filter (builtins.readDir dir));
|
|
|
|
mapModules' = f: dir: lib.attrValues (mapModules f dir);
|
|
})
|