2013-02-03 09:35:11 +00:00
|
|
|
# Management of static files in /etc.
|
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2010-09-13 15:41:38 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2006-12-11 15:32:10 +00:00
|
|
|
|
2009-01-02 16:06:52 +00:00
|
|
|
let
|
|
|
|
|
2013-02-03 13:19:05 +00:00
|
|
|
etc' = filter (f: f.enable) (attrValues config.environment.etc);
|
2013-02-03 12:24:22 +00:00
|
|
|
|
2016-09-27 13:28:11 +00:00
|
|
|
etc = pkgs.stdenvNoCC.mkDerivation {
|
2013-02-03 09:35:11 +00:00
|
|
|
name = "etc";
|
|
|
|
|
|
|
|
builder = ./make-etc.sh;
|
|
|
|
|
|
|
|
preferLocalBuild = true;
|
2015-07-07 13:01:36 +00:00
|
|
|
allowSubstitutes = false;
|
2013-02-03 09:35:11 +00:00
|
|
|
|
|
|
|
/* !!! Use toXML. */
|
2013-02-03 12:24:22 +00:00
|
|
|
sources = map (x: x.source) etc';
|
|
|
|
targets = map (x: x.target) etc';
|
|
|
|
modes = map (x: x.mode) etc';
|
2017-07-21 14:41:19 +00:00
|
|
|
users = map (x: x.user) etc';
|
|
|
|
groups = map (x: x.group) etc';
|
2013-02-03 09:35:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
2009-05-28 13:17:56 +00:00
|
|
|
environment.etc = mkOption {
|
2013-02-03 12:24:22 +00:00
|
|
|
default = {};
|
2013-10-30 15:19:07 +00:00
|
|
|
example = literalExample ''
|
2016-04-27 15:27:52 +00:00
|
|
|
{ example-configuration-file =
|
2013-02-03 12:24:22 +00:00
|
|
|
{ source = "/nix/store/.../etc/dir/file.conf.example";
|
|
|
|
mode = "0440";
|
|
|
|
};
|
|
|
|
"default/useradd".text = "GROUP=100 ...";
|
2013-10-30 15:19:07 +00:00
|
|
|
}
|
|
|
|
'';
|
2009-05-28 13:17:56 +00:00
|
|
|
description = ''
|
2013-02-03 12:24:22 +00:00
|
|
|
Set of files that have to be linked in <filename>/etc</filename>.
|
2009-05-28 13:17:56 +00:00
|
|
|
'';
|
2013-02-03 12:24:22 +00:00
|
|
|
|
2016-09-11 10:35:42 +00:00
|
|
|
type = with types; loaOf (submodule (
|
|
|
|
{ name, config, ... }:
|
2013-02-03 12:24:22 +00:00
|
|
|
{ options = {
|
|
|
|
|
2013-02-03 13:19:05 +00:00
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether this /etc file should be generated. This
|
|
|
|
option allows specific /etc files to be disabled.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-02-03 12:24:22 +00:00
|
|
|
target = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.str;
|
2013-02-03 12:24:22 +00:00
|
|
|
description = ''
|
|
|
|
Name of symlink (relative to
|
|
|
|
<filename>/etc</filename>). Defaults to the attribute
|
|
|
|
name.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-02-03 13:12:49 +00:00
|
|
|
text = mkOption {
|
|
|
|
default = null;
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.nullOr types.lines;
|
2013-02-03 13:12:49 +00:00
|
|
|
description = "Text of the file.";
|
|
|
|
};
|
|
|
|
|
|
|
|
source = mkOption {
|
2013-10-28 14:12:11 +00:00
|
|
|
type = types.path;
|
2013-02-03 13:12:49 +00:00
|
|
|
description = "Path of the source file.";
|
|
|
|
};
|
|
|
|
|
2013-02-03 12:24:22 +00:00
|
|
|
mode = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.str;
|
2013-02-03 12:24:22 +00:00
|
|
|
default = "symlink";
|
|
|
|
example = "0600";
|
|
|
|
description = ''
|
|
|
|
If set to something else than <literal>symlink</literal>,
|
|
|
|
the file is copied instead of symlinked, with the given
|
|
|
|
file mode.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-02-18 08:09:01 +00:00
|
|
|
uid = mkOption {
|
|
|
|
default = 0;
|
|
|
|
type = types.int;
|
|
|
|
description = ''
|
|
|
|
UID of created file. Only takes affect when the file is
|
|
|
|
copied (that is, the mode is not 'symlink').
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
gid = mkOption {
|
|
|
|
default = 0;
|
|
|
|
type = types.int;
|
|
|
|
description = ''
|
|
|
|
GID of created file. Only takes affect when the file is
|
|
|
|
copied (that is, the mode is not 'symlink').
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-07-21 14:41:19 +00:00
|
|
|
user = mkOption {
|
|
|
|
default = "+${toString config.uid}";
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
User name of created file.
|
|
|
|
Only takes affect when the file is copied (that is, the mode is not 'symlink').
|
|
|
|
Changing this option takes precedence over <literal>uid</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
default = "+${toString config.gid}";
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
Group name of created file.
|
|
|
|
Only takes affect when the file is copied (that is, the mode is not 'symlink').
|
|
|
|
Changing this option takes precedence over <literal>gid</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-02-03 12:24:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
target = mkDefault name;
|
2015-12-30 14:13:43 +00:00
|
|
|
source = mkIf (config.text != null) (
|
|
|
|
let name' = "etc-" + baseNameOf name;
|
|
|
|
in mkDefault (pkgs.writeText name' config.text));
|
2013-02-03 12:24:22 +00:00
|
|
|
};
|
|
|
|
|
2016-09-11 10:35:42 +00:00
|
|
|
}));
|
2013-02-03 12:24:22 +00:00
|
|
|
|
2009-01-02 16:06:52 +00:00
|
|
|
};
|
2013-02-03 09:35:11 +00:00
|
|
|
|
2009-01-02 16:06:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-03 09:35:11 +00:00
|
|
|
###### implementation
|
2009-08-16 13:14:33 +00:00
|
|
|
|
2013-02-03 09:35:11 +00:00
|
|
|
config = {
|
2009-08-16 13:14:33 +00:00
|
|
|
|
2013-02-03 09:35:11 +00:00
|
|
|
system.build.etc = etc;
|
2012-05-09 21:35:47 +00:00
|
|
|
|
2017-07-21 14:41:19 +00:00
|
|
|
system.activationScripts.etc = stringAfter [ "users" "groups" ]
|
2013-02-03 09:35:11 +00:00
|
|
|
''
|
|
|
|
# Set up the statically computed bits of /etc.
|
|
|
|
echo "setting up /etc..."
|
2014-07-25 10:48:21 +00:00
|
|
|
${pkgs.perl}/bin/perl -I${pkgs.perlPackages.FileSlurp}/lib/perl5/site_perl ${./setup-etc.pl} ${etc}/etc
|
2013-02-03 09:35:11 +00:00
|
|
|
'';
|
2009-01-02 16:06:52 +00:00
|
|
|
|
2013-02-03 09:35:11 +00:00
|
|
|
};
|
2009-10-30 08:37:08 +00:00
|
|
|
|
2007-02-26 21:18:13 +00:00
|
|
|
}
|