summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/default.nix36
-rw-r--r--lib/haskell.nix7
-rw-r--r--lib/types.nix19
3 files changed, 49 insertions, 13 deletions
diff --git a/lib/default.nix b/lib/default.nix
index 7c3b0370e..280f04299 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -39,6 +39,8 @@ let
ne = x: y: x != y;
mod = x: y: x - y * (x / y);
+ on = b: u: x: y: b (u x) (u y);
+
genid = lib.genid_uint32; # TODO remove
genid_uint31 = x: ((lib.genid_uint32 x) + 16777216) / 2;
genid_uint32 = import ./genid.nix { inherit lib; };
@@ -95,9 +97,12 @@ let
path = dirPath + "/${relPath}";
in
nameValuePair (toPackageName name) (f path))
- (filter
- (name: name != "default.nix" && !hasPrefix "." name)
- (attrNames (readDir dirPath))));
+ (attrNames
+ (filterAttrs isNixDirEntry (readDir dirPath))));
+
+ isNixDirEntry = name: type:
+ (type == "regular" && hasSuffix ".nix" name && name != "default.nix") ||
+ (type == "directory" && !hasPrefix "." name);
# https://tools.ietf.org/html/rfc5952
normalize-ip6-addr =
@@ -182,6 +187,30 @@ let
in
filter (x: x != []) ([acc.chunk] ++ acc.chunks);
+ # Filter adjacent duplicate elements.
+ uniq = uniqBy eq;
+
+ # Filter adjacent duplicate elements determined via the given function.
+ uniqBy = cmp: let
+ f = a: s:
+ if length s == 0 then
+ []
+ else let
+ b = head s;
+ in
+ if cmp a b then
+ f b (tail s)
+ else
+ [b] ++ f b (tail s);
+ in
+ s:
+ if length s == 0 then
+ []
+ else let
+ b = head s;
+ in
+ [b] ++ f b (tail s);
+
warnOldVersion = oldName: newName:
if compareVersions oldName newName != -1 then
trace "Upstream `${oldName}' gets overridden by `${newName}'." newName
@@ -191,3 +220,4 @@ let
in
lib
+// { inherit lib; }
diff --git a/lib/haskell.nix b/lib/haskell.nix
index 4f0ee05ab..f87cfa761 100644
--- a/lib/haskell.nix
+++ b/lib/haskell.nix
@@ -39,7 +39,12 @@ rec {
in
if parse == null then
(pkgs.writeText name s).overrideAttrs (old: {
- dependencies = old.dependencies or [] ++ dependencies;
+ dependencies =
+ lib.uniq
+ (lib.sort (lib.on lib.lessThan (lib.getAttr "name"))
+ (filter
+ (lib.ne null)
+ (old.dependencies or [] ++ dependencies)));
})
else
diff --git a/lib/types.nix b/lib/types.nix
index 0e0e093fb..9f278c650 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -18,9 +18,6 @@ rec {
type = label;
default = config._module.args.name;
};
- cores = mkOption {
- type = uint;
- };
nets = mkOption {
type = attrsOf net;
default = {};
@@ -136,7 +133,7 @@ rec {
default = null;
};
ip4 = mkOption {
- type = nullOr (submodule {
+ type = nullOr (submodule (ip4: {
options = {
addr = mkOption {
type = addr4;
@@ -146,13 +143,15 @@ rec {
} // {
retiolum.default = "10.243.0.0/16";
wiregrill.default = "10.244.0.0/16";
- }.${config._module.args.name} or {});
+ }.${config._module.args.name} or {
+ default = "${ip4.config.addr}/32";
+ });
};
- });
+ }));
default = null;
};
ip6 = mkOption {
- type = nullOr (submodule {
+ type = nullOr (submodule (ip6: {
options = {
addr = mkOption {
type = addr6;
@@ -163,9 +162,11 @@ rec {
} // {
retiolum.default = "42:0::/32";
wiregrill.default = "42:1::/32";
- }.${config._module.args.name} or {});
+ }.${config._module.args.name} or {
+ default = "${ip6.config.addr}/128";
+ });
};
- });
+ }));
default = null;
};
ssh = mkOption {