summary refs log tree commit diff
diff options
context:
space:
mode:
authorBenno Fünfstück <benno.fuenfstueck@gmail.com>2015-02-09 21:49:01 +0100
committerBenno Fünfstück <benno.fuenfstueck@gmail.com>2015-08-15 13:05:57 +0200
commit691f683c8c3e5423bfe39e3c12f5a325130ec014 (patch)
tree9b5d98f809c2a17f573201d25b162cf313137afe
parentfd53387bbaffcab7b6a8db083a92220238a1ef38 (diff)
downloadnixpkgs-691f683c8c3e5423bfe39e3c12f5a325130ec014.tar
nixpkgs-691f683c8c3e5423bfe39e3c12f5a325130ec014.tar.gz
nixpkgs-691f683c8c3e5423bfe39e3c12f5a325130ec014.tar.bz2
nixpkgs-691f683c8c3e5423bfe39e3c12f5a325130ec014.tar.lz
nixpkgs-691f683c8c3e5423bfe39e3c12f5a325130ec014.tar.xz
nixpkgs-691f683c8c3e5423bfe39e3c12f5a325130ec014.tar.zst
nixpkgs-691f683c8c3e5423bfe39e3c12f5a325130ec014.zip
types.nix: better error message for non-paths
This improves error messages when a set or a list is used where a path
was expected. For an example, if you used a package set (as opposed to a
single package) in systemPackages before this commit, the error was:

```
cannot coerce a list to a string, at "/home/nixpkgs/lib/types.nix":103:37
```

Now, the error message reads:

```
The option value `environment.systemPackages' in `/etc/nixos/configuration.nix' is not a list of paths.
```
-rw-r--r--lib/types.nix3
-rw-r--r--nixos/modules/config/system-path.nix2
2 files changed, 3 insertions, 2 deletions
diff --git a/lib/types.nix b/lib/types.nix
index a7f9bf1946e..27b653ebb6c 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -103,7 +103,8 @@ rec {
     path = mkOptionType {
       name = "path";
       # Hacky: there is no ‘isPath’ primop.
-      check = x: builtins.substring 0 1 (toString x) == "/";
+      # need to check isString first because otherwise toString throws an error.
+      check = x: builtins.isString x && builtins.substring 0 1 (toString x) == "/";
       merge = mergeOneOption;
     };
 
diff --git a/nixos/modules/config/system-path.nix b/nixos/modules/config/system-path.nix
index 62390f452ba..d7979593f40 100644
--- a/nixos/modules/config/system-path.nix
+++ b/nixos/modules/config/system-path.nix
@@ -57,7 +57,7 @@ in
     environment = {
 
       systemPackages = mkOption {
-        type = types.listOf types.path;
+        type = types.listOf types.package;
         default = [];
         example = literalExample "[ pkgs.firefox pkgs.thunderbird ]";
         description = ''