npins: restore asFlake patch

This commit is contained in:
Primrose 2026-01-15 21:30:49 +01:00
parent 627888c13f
commit d2617493e8
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA

View file

@ -112,7 +112,18 @@ let
else else
builtins.throw "Unknown source type ${spec.type}"; builtins.throw "Unknown source type ${spec.type}";
in in
spec // { outPath = mayOverride name path; }; spec
// rec {
outPath = mayOverride name path;
# Waiting for discussion upstream
# https://github.com/andir/npins/issues/159
asFlake =
if sources ? flake-compat then
(import sources.flake-compat { src = outPath; }).outputs
else
throw ".asFlake needs flake-compat as a source";
};
mkGitSource = mkGitSource =
{ {
@ -221,29 +232,31 @@ let
imageDigest = image_digest; imageDigest = image_digest;
finalImageTag = image_tag; finalImageTag = image_tag;
}; };
in
mkFunctor ( sources = mkFunctor (
{ {
input ? ./sources.json, input ? ./sources.json,
}: }:
let let
data = data =
if builtins.isPath input then if builtins.isPath input then
# while `readFile` will throw an error anyways if the path doesn't exist, # while `readFile` will throw an error anyways if the path doesn't exist,
# we still need to check beforehand because *our* error can be caught but not the one from the builtin # we still need to check beforehand because *our* error can be caught but not the one from the builtin
# *piegames sighs* # *piegames sighs*
if builtins.pathExists input then if builtins.pathExists input then
builtins.fromJSON (builtins.readFile input) builtins.fromJSON (builtins.readFile input)
else
throw "Input path ${toString input} does not exist"
else if builtins.isAttrs input then
input
else else
throw "Input path ${toString input} does not exist" throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset";
else if builtins.isAttrs input then version = data.version;
input in
else if version == 7 then
throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset"; builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins
version = data.version; else
in throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
if version == 7 then );
builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins in
else sources
throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
)