Merge remote-tracking branch 'ni/master'
This commit is contained in:
commit
25cf61f6a7
|
@ -33,7 +33,7 @@ with import <stockholm/lib>;
|
|||
};
|
||||
});
|
||||
in {
|
||||
hosts = mapAttrs hostDefaults {
|
||||
hosts = mapAttrs hostDefaults ({
|
||||
hotdog = {
|
||||
ci = true;
|
||||
nets = {
|
||||
|
@ -153,7 +153,7 @@ in {
|
|||
ssh.privkey.path = <secrets/ssh.id_ed25519>;
|
||||
ssh.pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKYMXMWZIK0jjnZDM9INiYAKcwjXs2241vew54K8veCR";
|
||||
};
|
||||
} // testHosts;
|
||||
} // testHosts);
|
||||
users = {
|
||||
krebs = {
|
||||
pubkey = "lol"; # TODO krebs.users.krebs.pubkey should be unnecessary
|
||||
|
|
|
@ -93,7 +93,13 @@ let
|
|||
in
|
||||
if max.pos == 0
|
||||
then a
|
||||
else "${concatStringsSep ":" lhs}::${concatStringsSep ":" rhs}";
|
||||
else let
|
||||
sep =
|
||||
if 8 - (length lhs + length rhs) == 1
|
||||
then ":0:"
|
||||
else "::";
|
||||
in
|
||||
"${concatStringsSep ":" lhs}${sep}${concatStringsSep ":" rhs}";
|
||||
|
||||
drop-leading-zeros =
|
||||
let
|
||||
|
@ -112,6 +118,33 @@ let
|
|||
(if test ".*::.*" a
|
||||
then a
|
||||
else group-zeros (drop-leading-zeros a));
|
||||
|
||||
hashToLength = n: s: substring 0 n (hashString "sha256" s);
|
||||
|
||||
dropLast = n: xs: reverseList (drop n (reverseList xs));
|
||||
takeLast = n: xs: reverseList (take n (reverseList xs));
|
||||
|
||||
# Split string into list of chunks where each chunk is at most n chars long.
|
||||
# The leftmost chunk might shorter.
|
||||
# Example: stringToGroupsOf "123456" -> ["12" "3456"]
|
||||
stringToGroupsOf = n: s: let
|
||||
acc =
|
||||
foldl'
|
||||
(acc: c: if stringLength acc.chunk < n then {
|
||||
chunk = acc.chunk + c;
|
||||
chunks = acc.chunks;
|
||||
} else {
|
||||
chunk = c;
|
||||
chunks = acc.chunks ++ [acc.chunk];
|
||||
})
|
||||
{
|
||||
chunk = "";
|
||||
chunks = [];
|
||||
}
|
||||
(stringToCharacters s);
|
||||
in
|
||||
filter (x: x != []) ([acc.chunk] ++ acc.chunks);
|
||||
|
||||
};
|
||||
in
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ let {
|
|||
inherit subnetname;
|
||||
subnetCIDR = "${subnetAddress}/${toString subnetPrefixLength}";
|
||||
subnetAddress = appendZeros subnetPrefixLength subnetPrefix;
|
||||
subnetHash = hash 4 subnetname;
|
||||
subnetHash = hashToLength 4 subnetname;
|
||||
subnetPrefix = joinAddress netPrefix subnetHash;
|
||||
subnetPrefixLength = netPrefixLength + 16;
|
||||
|
||||
|
@ -34,7 +34,9 @@ let {
|
|||
set =
|
||||
concatStringsSep
|
||||
":"
|
||||
(stringToGroupsOf 4 (hash (suffixLength / 4) suffixSpec.hostName));
|
||||
(stringToGroupsOf
|
||||
4
|
||||
(hashToLength (suffixLength / 4) suffixSpec.hostName));
|
||||
string = suffixSpec;
|
||||
};
|
||||
suffixLength = addressLength - subnetPrefixLength;
|
||||
|
@ -54,32 +56,6 @@ let {
|
|||
in
|
||||
formatAddress (map (const "0") (range 1 zeroCount) ++ parsedaddr);
|
||||
|
||||
# Split string into list of chunks where each chunk is at most n chars long.
|
||||
# The leftmost chunk might shorter.
|
||||
# Example: stringToGroupsOf "123456" -> ["12" "3456"]
|
||||
stringToGroupsOf = n: s: let
|
||||
acc =
|
||||
foldl'
|
||||
(acc: c: if stringLength acc.chunk < n then {
|
||||
chunk = acc.chunk + c;
|
||||
chunks = acc.chunks;
|
||||
} else {
|
||||
chunk = c;
|
||||
chunks = acc.chunks ++ [acc.chunk];
|
||||
})
|
||||
{
|
||||
chunk = "";
|
||||
chunks = [];
|
||||
}
|
||||
(stringToCharacters s);
|
||||
in
|
||||
filter (x: x != []) ([acc.chunk] ++ acc.chunks);
|
||||
|
||||
hash = n: s: substring 0 n (hashString "sha256" s);
|
||||
|
||||
dropLast = n: xs: reverseList (drop n (reverseList xs));
|
||||
takeLast = n: xs: reverseList (take n (reverseList xs));
|
||||
|
||||
hasEmptyPrefix = xs: take 2 xs == ["" ""];
|
||||
hasEmptySuffix = xs: takeLast 2 xs == ["" ""];
|
||||
hasEmptyInfix = xs: any (x: x == "") (trimEmpty 2 xs);
|
||||
|
|
Loading…
Reference in a new issue