Skip to content

Commit

Permalink
merge quality PR's
Browse files Browse the repository at this point in the history
  • Loading branch information
0z13 committed Mar 16, 2023
1 parent 35bb57c commit 3d30b8c
Showing 1 changed file with 62 additions and 5 deletions.
67 changes: 62 additions & 5 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,42 @@ let

lockFile = builtins.fromJSON (builtins.readFile lockFilePath);

# Using custom fetchurl function here so that we can specify outputHashMode.
# The hash we get from the lock file is using recursive ingestion even though
# it’s not unpacked. So builtins.fetchurl and import <nix/fetchurl.nix> are
# insufficient.
# Note that this will be a derivation and not a path as fetchTarball is,
# causing the hash of this input to be different on flake and non-flake evaluation.
fetchurl = { url, sha256 }:
derivation {
builder = "builtin:fetchurl";

name = "source";
inherit url;

outputHash = sha256;
outputHashAlgo = "sha256";
outputHashMode = "recursive";
executable = false;
unpack = false;

system = "builtin";

# No need to double the amount of network traffic
preferLocalBuild = true;

impureEnvVars = [
# We borrow these environment variables from the caller to allow
# easy proxy configuration. This is impure, but a fixed-output
# derivation like fetchurl is allowed to do so since its result is
# by definition pure.
"http_proxy" "https_proxy" "ftp_proxy" "all_proxy" "no_proxy"
];

# To make "nix-prefetch-url" work.
urls = [ url ];
};

fetchTree =
info:
if info.type == "github" then
Expand Down Expand Up @@ -44,7 +80,13 @@ let
} else {
})
else if info.type == "path" then
{ outPath = builtins.path { path = info.path; };

{ outPath = (builtins.path {
path = if builtins.substring 0 1 info.path != "/"
then src + ("/" + info.path)
else info.path; }
// (if info ? narHash then { sha256 = info.narHash; } else {})
);
narHash = info.narHash;
}
else if info.type == "tarball" then
Expand All @@ -53,6 +95,7 @@ let
({ inherit (info) url; }
// (if info ? narHash then { sha256 = info.narHash; } else {})
);
narHash = info.narHash;
}
else if info.type == "gitlab" then
{ inherit (info) rev narHash lastModified;
Expand All @@ -63,8 +106,23 @@ let
);
shortRev = builtins.substring 0 7 info.rev;
}
else if info.type == "file" then
{ outPath =
if builtins.substring 0 7 info.url == "http://" || builtins.substring 0 8 info.url == "https://" then
fetchurl
({ inherit (info) url; }
// (if info ? narHash then { sha256 = info.narHash; } else {})
)
else if builtins.substring 0 7 info.url == "file://" then
builtins.path
({ path = builtins.substring 7 (-1) info.url; }
// (if info ? narHash then { sha256 = info.narHash; } else {})
)
else throw "can't support url scheme of flake input with url '${info.url}'";
narHash = info.narHash;
}
else
# FIXME: add Mercurial, tarball inputs.
# FIXME: add Mercurial input
throw "flake input has unsupported input type '${info.type}'";

callFlake4 = flakeSrc: locks:
Expand Down Expand Up @@ -167,8 +225,7 @@ let

outputs = flake.outputs (inputs // { self = result; });

result = outputs // sourceInfo // { inherit inputs; inherit outputs; inherit sourceInfo; _type = "flake"; };

result = outputs // sourceInfo // { inherit inputs; inherit outputs; inherit sourceInfo; };
in
if node.flake or true then
assert builtins.isFunction flake.outputs;
Expand All @@ -190,7 +247,7 @@ let
in
rec {
defaultNix =
(builtins.removeAttrs result ["__functor"])
result
// (if result ? defaultPackage.${system} then { default = result.defaultPackage.${system}; } else {})
// (if result ? packages.${system}.default then { default = result.packages.${system}.default; } else {});

Expand Down

0 comments on commit 3d30b8c

Please sign in to comment.