diff --git a/npins/default.nix b/npins/default.nix index 884fc8cc..94d09bee 100644 --- a/npins/default.nix +++ b/npins/default.nix @@ -112,7 +112,18 @@ let else builtins.throw "Unknown source type ${spec.type}"; 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 = { @@ -221,29 +232,31 @@ let imageDigest = image_digest; finalImageTag = image_tag; }; -in -mkFunctor ( - { - input ? ./sources.json, - }: - let - data = - if builtins.isPath input then - # 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 - # *piegames sighs* - if builtins.pathExists input then - builtins.fromJSON (builtins.readFile input) + + sources = mkFunctor ( + { + input ? ./sources.json, + }: + let + data = + if builtins.isPath input then + # 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 + # *piegames sighs* + if builtins.pathExists input then + builtins.fromJSON (builtins.readFile input) + else + throw "Input path ${toString input} does not exist" + else if builtins.isAttrs input then + input else - throw "Input path ${toString input} does not exist" - else if builtins.isAttrs input then - input - else - throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset"; - version = data.version; - in - if version == 7 then - builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins - else - throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`" -) + throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset"; + version = data.version; + in + if version == 7 then + builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins + else + throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`" + ); +in +sources