-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.nix
68 lines (65 loc) · 1.35 KB
/
tools.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
{ pkgs }:
with builtins;
with pkgs;
with lib;
{
mkNss = { }: [
(
writeTextDir "etc/nsswitch.conf" ''
passwd: files
group: files
shadow: files
hosts: files dns
''
)
];
mkHosts = { hosts ? [] }: [
(
writeTextDir "etc/hosts" ''
127.0.0.1 localhost
::1 localhost
# user defined hosts:
${concatStringsSep "\n" hosts}
''
)
];
mkUsers = { users ? [] }: [
(
writeTextDir "etc/shadow" ''
root:!x:::::::
${concatMapStringsSep "\n" (user: "${user.name}:!:::::::") users}
''
)
(
writeTextDir "etc/passwd" ''
root:x:0:0::/root:${runtimeShell}
${concatMapStringsSep
"\n"
(user: "${user.name}:x:${toString user.uid}:${toString user.gid}::/home/${user.name}:")
users}
''
)
(
writeTextDir "etc/group" ''
root:x:0:
${concatMapStringsSep
"\n"
(user: "${user.name}:x:${toString user.gid}:")
users}
''
)
(
writeTextDir "etc/gshadow" ''
root:x::
${concatMapStringsSep
"\n"
(user: "${user.name}:x::")
users}
''
)
];
tagWithRev = { tag, rev }:
if typeOf rev == "string" && rev != ""
then "${tag}-${rev}"
else tag;
}