-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.nix
More file actions
47 lines (44 loc) · 1.42 KB
/
default.nix
File metadata and controls
47 lines (44 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{ pkgs ? import <nixpkgs> {}, ... }: let
inherit (pkgs.lib.attrsets) mapAttrs' nameValuePair filterAttrs optionalAttrs;
inherit (pkgs.lib.strings) removeSuffix hasPrefix hasSuffix;
inherit (pkgs.lib) pathExists;
inherit (builtins) readDir;
tryEval' = builtins.tryEval;
/* Import all files ending in .nix (excluding default.nix) and directories
*/
importFromDir = {
description = ''
Non-recursively import all files ending in .nix (excluding default.nix)
and directories containing a default.nix.
This does not import files or directories beginning with `.`
'';
__functor = _: d: a: mapAttrs' (n: _: nameValuePair
(removeSuffix ".nix" n)
(import (d + "/${n}") a)
)
(filterAttrs (n': v:
!(hasPrefix "." n')
&& n' != "default.nix"
&& n' != "flake.nix"
&& !(v != "directory" && !(hasSuffix ".nix" n'))
&& !(v == "directory" && !(pathExists (d + "/${n'}/default.nix"))))
(readDir d)
);
};
in {
_doc = ''
Platonic.Systems's extended nix library, preferably imported as `lib'`.
'';
/* More succinct version of tryEval
*/
tryEval = {
description = ''
A more succinct version of tryEval, enabling use like `(tryEval e).value
or e'`
'';
__functor = _: e: let
e' = tryEval' e;
in optionalAttrs e'.success { inherit (e') value; };
};
inherit importFromDir;
} // importFromDir ./. { inherit pkgs; }