-
-
Save samueldr/6740881ad9a974e13f457b054f85fc58 to your computer and use it in GitHub Desktop.
Precursor to flake-compat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
# Fields we care about when parsing, in order they'll be merged. | |
flakeFields = [ | |
"info" | |
"inputs" | |
"locked" | |
"original" | |
]; | |
# The lock information. | |
flakeLockInfos = builtins.fromJSON (builtins.readFile ./flake.lock); | |
# This is a watered-down version of flake.lock parsing. | |
# This is probably somewhat wrong. | |
inputsInfo = builtins.mapAttrs (input: data: | |
let | |
# Ensure we have at least empty attrsets for each fields. | |
data' = ( | |
(builtins.listToAttrs (builtins.map (name: { inherit name; value = {}; }) flakeFields)) | |
// data | |
); | |
in | |
builtins.foldl' (coll: next: coll // next) {} | |
(builtins.map (attrname: data'.${attrname}) flakeFields) | |
) flakeLockInfos.inputs; | |
# Here we apply the parsed data. | |
# This is definitely naïve and simplistic. | |
inputs = builtins.mapAttrs (name: info: | |
let | |
# FIXME: extremely assumes all github.com inputs | |
path = fetchTarball { | |
url = "https://github.com/${info.owner}/${info.repo}/archive/${info.rev}.tar.gz"; | |
sha256 = info.narHash; | |
}; | |
in | |
{ __toString = _: path; } // info // (import path {}) | |
) inputsInfo; | |
# This is the current flake. | |
self = { | |
__toString = _: ./.; | |
lastModified = toString builtins.currentTime; | |
} // (import ./flake.nix).outputs (inputs //{ | |
inherit self; | |
}); | |
in | |
self |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment