From 1daab1ebf5fdcc89030d0216dc3918b7f87f3ac5 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 3 Feb 2013 14:12:49 +0100 Subject: [PATCH] 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"; --- modules/config/networking.nix | 6 ++--- modules/system/etc/etc.nix | 16 +++++++++--- modules/tasks/filesystems.nix | 47 ++++++++++++++++------------------- 3 files changed, 37 insertions(+), 32 deletions(-) diff --git a/modules/config/networking.nix b/modules/config/networking.nix index 4cd74f79198..dbf67653dad 100644 --- a/modules/config/networking.nix +++ b/modules/config/networking.nix @@ -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 diff --git a/modules/system/etc/etc.nix b/modules/system/etc/etc.nix index 6fa50400a7f..ce7fc543536 100644 --- a/modules/system/etc/etc.nix +++ b/modules/system/etc/etc.nix @@ -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)); }; }); diff --git a/modules/tasks/filesystems.nix b/modules/tasks/filesystems.nix index 8efc96f7fe4..52f8e9b6ddf 100644 --- a/modules/tasks/filesystems.nix +++ b/modules/tasks/filesystems.nix @@ -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 =