Skip to content

Instantly share code, notes, and snippets.

@samueldr
Last active March 9, 2024 01:12
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 samueldr/6740881ad9a974e13f457b054f85fc58 to your computer and use it in GitHub Desktop.
Save samueldr/6740881ad9a974e13f457b054f85fc58 to your computer and use it in GitHub Desktop.
Precursor to flake-compat
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