From 45969c6d5d362f92b2ff03232df138f39c4f75af Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Sun, 11 Dec 2022 14:13:44 -0800 Subject: [PATCH] Create flake config --- flake.nix | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 flake.nix diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..9e66557 --- /dev/null +++ b/flake.nix @@ -0,0 +1,30 @@ +{ + description = "A semi-verbose flake format helper."; + + outputs = { self }: + let + inherit (builtins) elemAt foldl' head isAttrs length map zipAttrsWith; + + # Copied from to avoid taking a dependency + recursiveUpdateUntil = pred: lhs: rhs: + let f = attrPath: + zipAttrsWith (n: values: + let here = attrPath ++ [n]; + in + if length values == 1 || pred here (elemAt values 1) (head values) + then head values + else f here values + ); + in f [] [rhs lhs]; + recursiveUpdate = lhs: rhs: + recursiveUpdateUntil (path: lhs: rhs: !(isAttrs lhs && isAttrs rhs)) lhs rhs; + in + { + /* Create the flake outputs for systems and merge them into the expected format. + + system-outputs: function from a system to the flake outputs for that system. + systems: a list of systems to produce flake outputs for. + */ + outputs-for = system-outputs: systems: foldl' recursiveUpdate {} (map system-outputs systems); + }; +}