environment.etc: Add convenience option 'text'

This allows writing

  environment.etc.hosts.text = "127.0.0.1 localhost";

instead of

  environment.etc.hosts.source = pkgs.writeText "hosts" "127.0.0.1 localhost";
This commit is contained in:
Eelco Dolstra 2013-02-03 14:12:49 +01:00
parent ab238804b8
commit 1daab1ebf5
3 changed files with 37 additions and 32 deletions

View File

@ -48,7 +48,7 @@ in
"rpc".source = pkgs.glibc + "/etc/rpc";
# /etc/hosts: Hostname-to-IP mappings.
"hosts".source = pkgs.writeText "hosts"
"hosts".text =
''
127.0.0.1 localhost
${optionalString cfg.enableIPv6 ''
@ -58,7 +58,7 @@ in
'';
# /etc/resolvconf.conf: Configuration for openresolv.
"resolvconf.conf".source = pkgs.writeText "resolvconf.conf" (
"resolvconf.conf".text =
''
# This is the default, but we must set it here to prevent
# a collision with an apparently unrelated environment
@ -74,7 +74,7 @@ in
'' + optionalString config.services.bind.enable ''
# This hosts runs a full-blown DNS resolver.
name_servers='127.0.0.1'
'' );
'';
};
# The ip-up target is started when we have IP connectivity. So

View File

@ -45,9 +45,6 @@ in
options = singleton ({ name, config, ... }:
{ options = {
source = mkOption {
description = "Path of the source file.";
};
target = mkOption {
description = ''
@ -57,6 +54,17 @@ in
'';
};
text = mkOption {
default = null;
type = types.nullOr types.string;
description = "Text of the file.";
};
source = mkOption {
types = types.path;
description = "Path of the source file.";
};
mode = mkOption {
default = "symlink";
example = "0600";
@ -71,6 +79,8 @@ in
config = {
target = mkDefault name;
source = mkIf (config.text != null)
(mkDefault (pkgs.writeText "etc-file" config.text));
};
});

View File

@ -7,28 +7,6 @@ let
fileSystems = attrValues config.fileSystems;
fstab = pkgs.writeText "fstab"
''
# This is a generated file. Do not edit!
# Filesystems.
${flip concatMapStrings fileSystems (fs:
(if fs.device != null then fs.device else "/dev/disk/by-label/${fs.label}")
+ " " + fs.mountPoint
+ " " + fs.fsType
+ " " + fs.options
+ " 0"
+ " " + (if fs.fsType == "none" || fs.device == "none" || fs.fsType == "btrfs" || fs.fsType == "tmpfs" || fs.noCheck then "0" else
if fs.mountPoint == "/" then "1" else "2")
+ "\n"
)}
# Swap devices.
${flip concatMapStrings config.swapDevices (sw:
"${sw.device} none swap\n"
)}
'';
fileSystemOpts = { name, ... }: {
options = {
@ -171,10 +149,27 @@ in
[ pkgs.ntfs3g pkgs.cifs_utils ]
++ config.system.fsPackages;
environment.etc = singleton
{ source = fstab;
target = "fstab";
};
environment.etc.fstab.text =
''
# This is a generated file. Do not edit!
# Filesystems.
${flip concatMapStrings fileSystems (fs:
(if fs.device != null then fs.device else "/dev/disk/by-label/${fs.label}")
+ " " + fs.mountPoint
+ " " + fs.fsType
+ " " + fs.options
+ " 0"
+ " " + (if fs.fsType == "none" || fs.device == "none" || fs.fsType == "btrfs" || fs.fsType == "tmpfs" || fs.noCheck then "0" else
if fs.mountPoint == "/" then "1" else "2")
+ "\n"
)}
# Swap devices.
${flip concatMapStrings config.swapDevices (sw:
"${sw.device} none swap\n"
)}
'';
# Provide a target that pulls in all filesystems.
systemd.targets.fs =