Turn environment.etc into an attribute set

This provides a more convenient syntax and allows easier overriding.

For example,

  environment.etc = singleton
    { target = "vconsole.conf";
      source = vconsoleConf;
    };

can now be written as

  environment.etc."vconsole.conf".source = vconsoleConf;
This commit is contained in:
Eelco Dolstra
2013-02-03 14:28:18 +01:00
parent 73152e1702
commit ab238804b8
3 changed files with 67 additions and 61 deletions
+18 -28
View File
@@ -38,35 +38,27 @@ in
require = [options]; require = [options];
environment.etc = environment.etc =
[ { # /etc/services: TCP/UDP port assignments. { # /etc/services: TCP/UDP port assignments.
source = pkgs.iana_etc + "/etc/services"; "services".source = pkgs.iana_etc + "/etc/services";
target = "services";
}
{ # /etc/protocols: IP protocol numbers. # /etc/protocols: IP protocol numbers.
source = pkgs.iana_etc + "/etc/protocols"; "protocols".source = pkgs.iana_etc + "/etc/protocols";
target = "protocols";
}
{ # /etc/rpc: RPC program numbers. # /etc/rpc: RPC program numbers.
source = pkgs.glibc + "/etc/rpc"; "rpc".source = pkgs.glibc + "/etc/rpc";
target = "rpc";
}
{ # /etc/hosts: Hostname-to-IP mappings. # /etc/hosts: Hostname-to-IP mappings.
source = pkgs.writeText "hosts" "hosts".source = pkgs.writeText "hosts"
'' ''
127.0.0.1 localhost 127.0.0.1 localhost
${optionalString cfg.enableIPv6 '' ${optionalString cfg.enableIPv6 ''
::1 localhost ::1 localhost
''} ''}
${cfg.extraHosts} ${cfg.extraHosts}
''; '';
target = "hosts";
}
{ # /etc/resolvconf.conf: Configuration for openresolv. # /etc/resolvconf.conf: Configuration for openresolv.
source = pkgs.writeText "resolvconf.conf" ( "resolvconf.conf".source = pkgs.writeText "resolvconf.conf" (
'' ''
# This is the default, but we must set it here to prevent # This is the default, but we must set it here to prevent
# a collision with an apparently unrelated environment # a collision with an apparently unrelated environment
@@ -83,9 +75,7 @@ in
# This hosts runs a full-blown DNS resolver. # This hosts runs a full-blown DNS resolver.
name_servers='127.0.0.1' name_servers='127.0.0.1'
'' ); '' );
target = "resolvconf.conf"; };
}
];
# The ip-up target is started when we have IP connectivity. So # The ip-up target is started when we have IP connectivity. So
# services that depend on IP connectivity (like ntpd) should be # services that depend on IP connectivity (like ntpd) should be
+48 -29
View File
@@ -6,6 +6,8 @@ with pkgs.lib;
let let
etc' = attrValues config.environment.etc;
etc = pkgs.stdenv.mkDerivation { etc = pkgs.stdenv.mkDerivation {
name = "etc"; name = "etc";
@@ -14,9 +16,9 @@ let
preferLocalBuild = true; preferLocalBuild = true;
/* !!! Use toXML. */ /* !!! Use toXML. */
sources = map (x: x.source) config.environment.etc; sources = map (x: x.source) etc';
targets = map (x: x.target) config.environment.etc; targets = map (x: x.target) etc';
modes = map (x: x.mode) config.environment.etc; modes = map (x: x.mode) etc';
}; };
in in
@@ -28,34 +30,51 @@ in
options = { options = {
environment.etc = mkOption { environment.etc = mkOption {
default = []; type = types.loaOf types.optionSet;
example = [ default = {};
{ source = "/nix/store/.../etc/dir/file.conf.example"; example =
target = "dir/file.conf"; { hosts =
mode = "0440"; { source = "/nix/store/.../etc/dir/file.conf.example";
} mode = "0440";
]; };
"default/useradd".text = "GROUP=100 ...";
};
description = '' description = ''
List of files that have to be linked in <filename>/etc</filename>. Set of files that have to be linked in <filename>/etc</filename>.
''; '';
type = types.listOf types.optionSet;
options = { options = singleton ({ name, config, ... }:
source = mkOption { { options = {
description = "Source file."; source = mkOption {
}; description = "Path of the source file.";
target = mkOption { };
description = "Name of symlink (relative to <filename>/etc</filename>).";
}; target = mkOption {
mode = mkOption { description = ''
default = "symlink"; Name of symlink (relative to
example = "0600"; <filename>/etc</filename>). Defaults to the attribute
description = '' name.
If set to something else than <literal>symlink</literal>, '';
the file is copied instead of symlinked, with the given };
file mode.
''; mode = mkOption {
}; 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.
'';
};
};
config = {
target = mkDefault name;
};
});
}; };
}; };
+1 -4
View File
@@ -65,10 +65,7 @@ in
# Let systemd-vconsole-setup.service do the work of setting up the # Let systemd-vconsole-setup.service do the work of setting up the
# virtual consoles. FIXME: trigger a restart of # virtual consoles. FIXME: trigger a restart of
# systemd-vconsole-setup.service if /etc/vconsole.conf changes. # systemd-vconsole-setup.service if /etc/vconsole.conf changes.
environment.etc = singleton environment.etc."vconsole.conf".source = vconsoleConf;
{ target = "vconsole.conf";
source = vconsoleConf;
};
# This is identical to the systemd-vconsole-setup.service unit # This is identical to the systemd-vconsole-setup.service unit
# shipped with systemd, except that it uses /dev/tty1 instead of # shipped with systemd, except that it uses /dev/tty1 instead of