diff options
author | makefu <github@syntax-fehler.de> | 2018-03-07 01:49:57 +0100 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2018-03-07 01:49:57 +0100 |
commit | 6b647a237a5f4db23b7eff70f305be7106da7711 (patch) | |
tree | 3542eabb416599e0d2dea8a2f2358f27f4b911e2 /lib/types.nix | |
parent | 194e7011d42ed75c76dc7a7efea450ba6497d2f1 (diff) | |
parent | 02f67eed443ba552d775d1a0ab7860d439f7552b (diff) |
Merge remote-tracking branch 'lass/master'
Diffstat (limited to 'lib/types.nix')
-rw-r--r-- | lib/types.nix | 115 |
1 files changed, 59 insertions, 56 deletions
diff --git a/lib/types.nix b/lib/types.nix index b85794925..1cf2d96c9 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -2,7 +2,7 @@ let inherit (lib) - all any concatMapStringsSep concatStringsSep const filter flip + all any attrNames concatMapStringsSep concatStringsSep const filter flip genid hasSuffix head isInt isString length mergeOneOption mkOption mkOptionType optional optionalAttrs optionals range splitString stringLength substring test testString typeOf; @@ -231,90 +231,93 @@ rec { source = submodule ({ config, ... }: { options = { type = let - types = [ - "file" - "git" - "pass" - "symlink" - ]; + known-types = attrNames source-types; + type-candidates = filter (k: config.${k} != null) known-types; in mkOption { - type = enum types; - default = let - cands = filter (k: config.${k} != null) types; - in - if length cands == 1 - then head cands - else throw "cannot determine type"; - }; - file = let - file-path = (file-source.getSubOptions "FIXME").path.type; - in mkOption { - type = nullOr (either file-source file-path); - default = null; + default = if length type-candidates == 1 + then head type-candidates + else throw "cannot determine type"; + type = enum known-types; + }; + file = mkOption { apply = x: - if file-path.check x + if absolute-pathname.check x then { path = x; } else x; + default = null; + type = nullOr (either absolute-pathname source-types.file); }; git = mkOption { - type = nullOr git-source; default = null; + type = nullOr source-types.git; }; pass = mkOption { - type = nullOr pass-source; default = null; + type = nullOr source-types.pass; }; - symlink = let - symlink-target = (symlink-source.getSubOptions "FIXME").target.type; - in mkOption { - type = nullOr (either symlink-source symlink-target); + pipe = mkOption { + apply = x: + if absolute-pathname.check x + then { command = x; } + else x; + default = null; + type = nullOr (either absolute-pathname source-types.pipe); + }; + symlink = mkOption { + type = nullOr (either pathname source-types.symlink); default = null; apply = x: - if symlink-target.check x + if pathname.check x then { target = x; } else x; }; }; }); - file-source = submodule { - options = { - path = mkOption { - type = absolute-pathname; + source-types = { + file = submodule { + options = { + path = mkOption { + type = absolute-pathname; + }; }; }; - }; - - git-source = submodule { - options = { - ref = mkOption { - type = str; # TODO types.git.ref - }; - url = mkOption { - type = str; # TODO types.git.url + git = submodule { + options = { + ref = mkOption { + type = str; # TODO types.git.ref + }; + url = mkOption { + type = str; # TODO types.git.url + }; }; }; - }; - - pass-source = submodule { - options = { - dir = mkOption { - type = absolute-pathname; + pass = submodule { + options = { + dir = mkOption { + type = absolute-pathname; + }; + name = mkOption { + type = pathname; # TODO relative-pathname + }; }; - name = mkOption { - type = pathname; # TODO relative-pathname + }; + pipe = submodule { + options = { + command = mkOption { + type = absolute-pathname; + }; }; }; - }; - - symlink-source = submodule { - options = { - target = mkOption { - type = pathname; # TODO relative-pathname + symlink = submodule { + options = { + target = mkOption { + type = pathname; # TODO relative-pathname + }; }; }; - }; + }; suffixed-str = suffs: mkOptionType { |