summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2018-02-28 14:30:11 +0100
committertv <tv@krebsco.de>2018-02-28 15:15:58 +0100
commit3ac7941968e20ebaf553a7e44f8dbfb990de4eb1 (patch)
tree74b9204b22961de1a8c881e4c186faebfe7465f6
parent34e88f9cef87c582fb7d88e90e5a96cb28a61188 (diff)
types: refactor source
-rw-r--r--krebs/3modules/repo-sync.nix6
-rw-r--r--lib/types.nix102
2 files changed, 48 insertions, 60 deletions
diff --git a/krebs/3modules/repo-sync.nix b/krebs/3modules/repo-sync.nix
index b2e3aa7c5..45d9d81c3 100644
--- a/krebs/3modules/repo-sync.nix
+++ b/krebs/3modules/repo-sync.nix
@@ -18,10 +18,10 @@ let
type = types.attrsOf (types.submodule ({ config, ... }: {
options = {
origin = mkOption {
- type = types.git-source;
+ type = types.source-types.git;
};
mirror = mkOption {
- type = types.git-source;
+ type = types.source-types.git;
};
};
config = {
@@ -31,7 +31,7 @@ let
}));
};
latest = mkOption {
- type = types.nullOr types.git-source;
+ type = types.nullOr types.source-types.git;
default = null;
};
timerConfig = mkOption {
diff --git a/lib/types.nix b/lib/types.nix
index b85794925..9ae92ea7e 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,78 @@ 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);
+ 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;
- };
- name = mkOption {
- type = pathname; # TODO relative-pathname
+ pass = submodule {
+ options = {
+ dir = mkOption {
+ type = absolute-pathname;
+ };
+ name = mkOption {
+ type = pathname; # TODO relative-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 {