fork/nix-minecraft

git clone https://git.julia.blue/fork/nix-minecraft

Infinidogerefactor: pull removeVanilla into libba3ae2b

develop
1.2 KiB42 linesraw
1{ lib }:
2lib.makeExtensible (self:
3with lib;
4with builtins;
5rec {
6  latestVersion = versions:
7    last
8      (sort versionOlder
9        (filter
10          (v: isList (match "([[:digit:]]+\.[[:digit:]]+(\.[[:digit:]]+)?)" v))
11          (attrNames versions)));
12
13  escapeVersion = builtins.replaceStrings [ "." " " ] [ "_" "_" ];
14
15  removeVanilla = n: escapeVersion (lib.removePrefix "vanilla-" n);
16
17  # Stolen from digga: https://github.com/divnix/digga/blob/587013b2500031b71959496764b6fdd1b2096f9a/src/importers.nix#L61-L114
18  rakeLeaves =
19    dirPath:
20    let
21      seive = file: type:
22        # Only rake `.nix` files or directories
23        (type == "regular" && lib.hasSuffix ".nix" file) || (type == "directory")
24      ;
25
26      collect = file: type: {
27        name = lib.removeSuffix ".nix" file;
28        value =
29          let
30            path = dirPath + "/${file}";
31          in
32          if (type == "regular")
33            || (type == "directory" && builtins.pathExists (path + "/default.nix"))
34          then path
35          # recurse on directories that don't contain a `default.nix`
36          else rakeLeaves path;
37      };
38
39      files = lib.filterAttrs seive (builtins.readDir dirPath);
40    in
41    lib.filterAttrs (n: v: v != { }) (lib.mapAttrs' collect files);
42})