push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
# shellcheck shell=bash
# getSortedMapKeys
# Stores the sorted keys of the input associative array referenced by inputMapRef in the indexed arrray referenced by
# outputArrRef.
#
# Note from the Bash manual on arrays:
# There is no maximum limit on the size of an array, nor any requirement that members be indexed or assigned contiguously.
# - https://www.gnu.org/software/bash/manual/html_node/Arrays.html
#
# Since no guarantees are made about the order in which associative maps are traversed, this function is primarly
# useful for getting rid of yet another source of non-determinism. As an added benefit, it checks that the arguments
# provided are of correct type, unlike native parameter expansion which will accept expansions of strings.
#
# Arguments:
# - inputMapRef: a reference to an associative array (not mutated)
# - outputArrRef: a reference to an indexed array (contents are replaced entirely)
#
# Returns 0.
getSortedMapKeys() {
if (($# != 2)); then
nixErrorLog "expected two arguments!"
nixErrorLog "usage: getSortedMapKeys inputMapRef outputArrRef"
exit 1
fi
local -rn inputMapRef="$1"
# shellcheck disable=SC2178
# Don't warn about outputArrRef being used as an array because it is an array.
local -rn outputArrRef="$2"
if ! isDeclaredMap "${!inputMapRef}"; then
nixErrorLog "first argument inputMapRef must be a reference to an associative array"
exit 1
elif ! isDeclaredArray "${!outputArrRef}"; then
nixErrorLog "second argument outputArrRef must be a reference to an indexed array"
exit 1
fi
# shellcheck disable=SC2034
local -a keys=("${!inputMapRef[@]}")
sortArray keys "${!outputArrRef}"
return 0
}

View File

@@ -0,0 +1,17 @@
{
callPackages,
isDeclaredArray,
isDeclaredMap,
makeSetupHook,
sortArray,
}:
makeSetupHook {
name = "getSortedMapKeys";
propagatedBuildInputs = [
isDeclaredArray
isDeclaredMap
sortArray
];
passthru.tests = callPackages ./tests.nix { };
meta.description = "Gets the sorted indices of an associative array";
} ./getSortedMapKeys.bash

View File

@@ -0,0 +1,80 @@
# NOTE: Tests related to getSortedMapKeys go here.
{
getSortedMapKeys,
lib,
testers,
}:
let
inherit (lib.attrsets) recurseIntoAttrs;
inherit (testers) shellcheck shfmt testEqualArrayOrMap;
check =
{
name,
valuesMap,
expectedArray,
}:
(testEqualArrayOrMap {
inherit name valuesMap expectedArray;
script = ''
set -eu
nixLog "running getSortedMapKeys with valuesMap to populate actualArray"
getSortedMapKeys valuesMap actualArray
'';
}).overrideAttrs
(prevAttrs: {
nativeBuildInputs = prevAttrs.nativeBuildInputs or [ ] ++ [ getSortedMapKeys ];
});
in
recurseIntoAttrs {
shellcheck = shellcheck {
name = "getSortedMapKeys";
src = ./getSortedMapKeys.bash;
};
shfmt = shfmt {
name = "getSortedMapKeys";
src = ./getSortedMapKeys.bash;
};
empty = check {
name = "empty";
valuesMap = { };
expectedArray = [ ];
};
singleton = check {
name = "singleton";
valuesMap = {
"apple" = "fruit";
};
expectedArray = [ "apple" ];
};
keysAreSorted = check {
name = "keysAreSorted";
valuesMap = {
"apple" = "fruit";
"bee" = "insect";
"carrot" = "vegetable";
};
expectedArray = [
"apple"
"bee"
"carrot"
];
};
# NOTE: While keys can be whitespace, they cannot be null (empty).
keysCanBeWhitespace = check {
name = "keysCanBeWhitespace";
valuesMap = {
" " = 1;
" " = 2;
};
expectedArray = [
" "
" "
];
};
}