forked from iynaix/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlib.nix
67 lines (63 loc) · 2.04 KB
/
lib.nix
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{ lib, pkgs, ... }:
lib.extend (
_: libprev: {
# namespace for custom functions
custom = {
# saner api for iterating through workspaces in a flat list
# takes a function that accepts the following attrset {workspace, key, monitor}
mapWorkspaces =
workspaceFn:
libprev.concatMap (
monitor:
libprev.forEach monitor.workspaces (
ws:
let
workspaceArg = {
inherit monitor;
workspace = toString ws;
key = toString (libprev.mod ws 10);
};
in
workspaceFn workspaceArg
)
);
# produces an attrset shell package with completions from either a string / writeShellApplication attrset / package
mkShellPackages = lib.mapAttrs (
name: value:
if lib.isString value then
pkgs.writeShellApplication {
inherit name;
text = value;
}
# packages
else if lib.isDerivation value then
value
# attrs to pass to writeShellApplication
else
pkgs.callPackage ./packages/write-shell-application-completions (value // { inherit name; })
);
# produces ini format strings, takes a single argument of the object
toQuotedINI = libprev.generators.toINI {
mkKeyValue = libprev.flip libprev.generators.mkKeyValueDefault "=" {
mkValueString =
v: if libprev.isString v then "\"${v}\"" else libprev.generators.mkValueStringDefault { } v;
};
};
# uses the direnv of a directory
useDirenv =
dir: content:
let
direnv = libprev.getExe pkgs.direnv;
in
''
pushd ${dir} > /dev/null
# activate direnv, it's always bash for a script
eval "$(${direnv} export bash)"
${content}
popd > /dev/null
# deactivate direnv by evaluating in the context of the original directory
eval "$(${direnv} export bash)"
'';
};
}
)