-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathdefault.nix
125 lines (97 loc) · 2.85 KB
/
default.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Copyright (c) 2019-2022, see AUTHORS. Licensed under MIT License, see LICENSE.
{ config, lib, pkgs, ... }:
with lib;
let
etc' = filter (f: f.enable) (attrValues config.environment.etc);
etc = pkgs.stdenvNoCC.mkDerivation {
name = "etc";
builder = ./make-etc.sh;
preferLocalBuild = true;
allowSubstitutes = false;
sources = map (x: x.source) etc';
targets = map (x: x.target) etc';
};
fileType = types.submodule (
{ name, config, ... }:
{
options = {
enable = mkOption {
type = types.bool;
default = true;
description = ''
Whether this <filename>/etc</filename> file should be generated. This
option allows specific <filename>/etc</filename> files to be disabled.
'';
};
target = mkOption {
type = types.str;
description = ''
Name of symlink (relative to <filename>/etc</filename>).
Defaults to the attribute name.
'';
};
text = mkOption {
type = types.nullOr types.lines;
default = null;
description = "Text of the file.";
};
source = mkOption {
type = types.path;
description = "Path of the source file.";
};
};
config = {
target = mkDefault name;
source = mkIf (config.text != null) (
let name' = "etc-" + baseNameOf name;
in mkDefault (pkgs.writeText name' config.text)
);
};
}
);
in
{
###### interface
options = {
environment = {
etc = mkOption {
type = types.loaOf fileType;
default = { };
example = literalExpression ''
{
example-configuration-file = {
source = "/nix/store/.../etc/dir/file.conf.example";
};
"default/useradd".text = "GROUP=100 ...";
}
'';
description = ''
Set of files that have to be linked in <filename>/etc</filename>.
'';
};
etcBackupExtension = mkOption {
type = types.nullOr types.str;
default = null;
example = ".bak";
description = ''
Backup file extension.
</para><para>
If a file in <filename>/etc</filename> already exists and is not managed
by Nix-on-Droid, the activation fails because we do not overwrite unknown
files. When an extension is provided through this option, the original
file will be moved in respect of the backup extension and the activation
executes successfully.
'';
};
};
};
###### implementation
config = {
build = {
inherit etc;
activation.setUpEtc = ''
$DRY_RUN_CMD bash ${./setup-etc.sh} /etc ${etc}/etc ${toString config.environment.etcBackupExtension}
'';
};
};
}