-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.nix
104 lines (99 loc) · 2.76 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
{ ... }:
let
# source: https://github.com/NixOS/nixpkgs/blob/529d4344f514b70b9736f432e974c59ffad9557a/lib/systems/flake-systems.nix
supportedSystems = [
# Tier 1
"x86_64-linux"
# Tier 2
"aarch64-linux"
"x86_64-darwin"
# Tier 3
"armv6l-linux"
"armv7l-linux"
"i686-linux"
# "mipsel-linux" is excluded because it is not bootstrapped
# Other platforms with sufficient support in stdenv which is not formally
# mandated by their platform tier.
"aarch64-darwin"
# "armv5tel-linux" is excluded because it is not bootstrapped
"powerpc64le-linux"
"riscv64-linux"
"x86_64-freebsd"
];
### From flake-utils
# Builds a map from <attr>=value to <attr>.<system>=value for each system.
eachSystem = let
# Applies a merge operation accross systems.
eachSystemOp =
op: systems: f:
builtins.foldl' (op f) { } (
if
!builtins ? currentSystem || builtins.elem builtins.currentSystem systems
then
systems
else
# Add the current system if the --impure flag is used.
systems ++ [ builtins.currentSystem ]
);
in eachSystemOp (
# Merge outputs for each system.
f: attrs: system:
let
ret = f system;
in
builtins.foldl' (
attrs: key:
attrs
// {
${key} = (attrs.${key} or { }) // {
${system} = ret.${key};
};
}
) attrs (builtins.attrNames ret)
);
###
in {
forAllSystems = eachSystem supportedSystems;
mkCustomShell =
mkShell: args: pkgs:
let
lib = pkgs.lib;
servicesLib = import ./services.nix { inherit pkgs lib; };
shellHookOption = args.returnToUserShell or false;
returnToUserShellHook =
let
execUserShell = ''
TARGET_SHELL=$(${pkgs.coreutils}/bin/pinky -l $USER | ${pkgs.gawk}/bin/awk '/Shell:/ {print $NF}')
exec $TARGET_SHELL
'';
in
{
"" = "";
"0" = "";
"1" = ''
if [ "$DIRENV_IN_ENVRC" = "1" ]; then
# do nothing, direnv will load a new shell
:
elif [ -n "$IN_NIX_SHELL" ]; then
${execUserShell}
else
echo "Unknown environment loader - use direnv or 'nix develop'"
fi
'';
"force" = execUserShell;
}
.${toString shellHookOption};
generatedArgs = {
services = null;
buildInputs = servicesLib.mkProcessComposeWrappers args ++ (args.buildInputs or []);
extraUnsetEnv = [
"returnToUserShell"
];
shellHook = ''
${args.shellHook or ""}
${returnToUserShellHook}
'';
};
in
mkShell (lib.recursiveUpdate args generatedArgs);
}