Skip to content

Instantly share code, notes, and snippets.

@GrafBlutwurst
Last active February 8, 2022 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GrafBlutwurst/1c22253b66dd8cab7ecd158e19bafcf0 to your computer and use it in GitHub Desktop.
Save GrafBlutwurst/1c22253b66dd8cab7ecd158e19bafcf0 to your computer and use it in GitHub Desktop.
Example of how lists type merge breaks
let
pkgs = import <nixpkgs> { };
in
with pkgs.lib; with pkgs.lib.types; let
leftType = submodule {
options.foo = mkOption {
type = int;
description = "left.foo";
};
};
rightType = submodule {
options.bar = mkOption {
type = string;
description = "right.bar";
};
};
loc = [ "dummy" ];
leftValue = { foo = 1; };
rightValue = { bar = 1; };
rightValueWrong = { bar = true; };
defs = {
testCase1 = [
{ file = "f1"; value = [ leftValue ]; }
];
testCase2 = [
{ file = "f1"; value = [ leftValue leftValue ]; }
];
testCase3 = [
{ file = "f1"; value = [ leftValue leftValue ]; }
{ file = "f2"; value = [ leftValue leftValue ]; }
];
testCase4 = [
{ file = "f1"; value = [ rightValue ]; }
];
testCase5 = [
{ file = "f1"; value = [ leftValue ]; }
{ file = "f2"; value = [ rightValue ]; }
];
testCase6 = [
{ file = "f1"; value = [ rightValueWrong ]; }
];
};
#This doesn't work because list merge breaks for inner eithers
callMerge = defs:
let
typeDef = listOf (either leftType rightType);
in
typeDef.merge loc defs;
#This doesnt work because it no longer propertly checks the correctness of the records in the list
#Same happens if uniq is on the either
callMergeUniq = defs:
let
typeDef = uniq (listOf (either leftType rightType));
#typeDef = listOf (uniq (either leftType rightType));
in
typeDef.merge loc defs;
in
{
nonUniq = {
testCase1 = callMerge defs.testCase1;
testCase2 = callMerge defs.testCase2;
testCase3 = callMerge defs.testCase3;
#Seems like something with lists merge is funny ending up always trying to apply the first arugment of the inner either.
#testCase4Breaks = callMerge defs.testCase4;
#testCase5Breaks = callMerge defs.testCase5;
};
withUniq = {
testCase1 = callMergeUniq defs.testCase1;
testCase2 = callMergeUniq defs.testCase2;
#Makes sense that it breaks since we made it uniq
#testCase3Breaks = callMergeUniq defs.testCase3;
testCase4 = callMergeUniq defs.testCase4;
#Makes sense that it breaks since we made it uniq
#testCase5Breaks = callMergeUniq defs.testCase5;
testCase6 = callMergeUniq defs.testCase6;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment