types: refactor source
This commit is contained in:
parent
34e88f9cef
commit
3ac7941968
@ -18,10 +18,10 @@ let
|
|||||||
type = types.attrsOf (types.submodule ({ config, ... }: {
|
type = types.attrsOf (types.submodule ({ config, ... }: {
|
||||||
options = {
|
options = {
|
||||||
origin = mkOption {
|
origin = mkOption {
|
||||||
type = types.git-source;
|
type = types.source-types.git;
|
||||||
};
|
};
|
||||||
mirror = mkOption {
|
mirror = mkOption {
|
||||||
type = types.git-source;
|
type = types.source-types.git;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
@ -31,7 +31,7 @@ let
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
latest = mkOption {
|
latest = mkOption {
|
||||||
type = types.nullOr types.git-source;
|
type = types.nullOr types.source-types.git;
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
timerConfig = mkOption {
|
timerConfig = mkOption {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
let
|
let
|
||||||
inherit (lib)
|
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
|
genid hasSuffix head isInt isString length mergeOneOption mkOption
|
||||||
mkOptionType optional optionalAttrs optionals range splitString
|
mkOptionType optional optionalAttrs optionals range splitString
|
||||||
stringLength substring test testString typeOf;
|
stringLength substring test testString typeOf;
|
||||||
@ -231,61 +231,50 @@ rec {
|
|||||||
source = submodule ({ config, ... }: {
|
source = submodule ({ config, ... }: {
|
||||||
options = {
|
options = {
|
||||||
type = let
|
type = let
|
||||||
types = [
|
known-types = attrNames source-types;
|
||||||
"file"
|
type-candidates = filter (k: config.${k} != null) known-types;
|
||||||
"git"
|
|
||||||
"pass"
|
|
||||||
"symlink"
|
|
||||||
];
|
|
||||||
in mkOption {
|
in mkOption {
|
||||||
type = enum types;
|
default = if length type-candidates == 1
|
||||||
default = let
|
then head type-candidates
|
||||||
cands = filter (k: config.${k} != null) types;
|
|
||||||
in
|
|
||||||
if length cands == 1
|
|
||||||
then head cands
|
|
||||||
else throw "cannot determine type";
|
else throw "cannot determine type";
|
||||||
|
type = enum known-types;
|
||||||
};
|
};
|
||||||
file = let
|
file = mkOption {
|
||||||
file-path = (file-source.getSubOptions "FIXME").path.type;
|
|
||||||
in mkOption {
|
|
||||||
type = nullOr (either file-source file-path);
|
|
||||||
default = null;
|
|
||||||
apply = x:
|
apply = x:
|
||||||
if file-path.check x
|
if absolute-pathname.check x
|
||||||
then { path = x; }
|
then { path = x; }
|
||||||
else x;
|
else x;
|
||||||
|
default = null;
|
||||||
|
type = nullOr (either absolute-pathname source-types.file);
|
||||||
};
|
};
|
||||||
git = mkOption {
|
git = mkOption {
|
||||||
type = nullOr git-source;
|
|
||||||
default = null;
|
default = null;
|
||||||
|
type = nullOr source-types.git;
|
||||||
};
|
};
|
||||||
pass = mkOption {
|
pass = mkOption {
|
||||||
type = nullOr pass-source;
|
|
||||||
default = null;
|
default = null;
|
||||||
|
type = nullOr source-types.pass;
|
||||||
};
|
};
|
||||||
symlink = let
|
symlink = mkOption {
|
||||||
symlink-target = (symlink-source.getSubOptions "FIXME").target.type;
|
type = nullOr (either pathname source-types.symlink);
|
||||||
in mkOption {
|
|
||||||
type = nullOr (either symlink-source symlink-target);
|
|
||||||
default = null;
|
default = null;
|
||||||
apply = x:
|
apply = x:
|
||||||
if symlink-target.check x
|
if pathname.check x
|
||||||
then { target = x; }
|
then { target = x; }
|
||||||
else x;
|
else x;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
file-source = submodule {
|
source-types = {
|
||||||
|
file = submodule {
|
||||||
options = {
|
options = {
|
||||||
path = mkOption {
|
path = mkOption {
|
||||||
type = absolute-pathname;
|
type = absolute-pathname;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
git = submodule {
|
||||||
git-source = submodule {
|
|
||||||
options = {
|
options = {
|
||||||
ref = mkOption {
|
ref = mkOption {
|
||||||
type = str; # TODO types.git.ref
|
type = str; # TODO types.git.ref
|
||||||
@ -295,8 +284,7 @@ rec {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
pass = submodule {
|
||||||
pass-source = submodule {
|
|
||||||
options = {
|
options = {
|
||||||
dir = mkOption {
|
dir = mkOption {
|
||||||
type = absolute-pathname;
|
type = absolute-pathname;
|
||||||
@ -306,8 +294,7 @@ rec {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
symlink = submodule {
|
||||||
symlink-source = submodule {
|
|
||||||
options = {
|
options = {
|
||||||
target = mkOption {
|
target = mkOption {
|
||||||
type = pathname; # TODO relative-pathname
|
type = pathname; # TODO relative-pathname
|
||||||
@ -315,6 +302,7 @@ rec {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
suffixed-str = suffs:
|
suffixed-str = suffs:
|
||||||
mkOptionType {
|
mkOptionType {
|
||||||
|
Loading…
Reference in New Issue
Block a user