+Digest16 = NewType('Digest16', str)
+Digest32 = NewType('Digest32', str)
+
+
+class ChannelTableEntry(types.SimpleNamespace):
+ absolute_url: str
+ digest: Digest16
+ file: str
+ size: int
+ url: str
+
+
+class AliasPin(NamedTuple):
+ pass
+
+
+class SymlinkPin(NamedTuple):
+ @property
+ def release_name(self) -> str:
+ return 'link'
+
+
+class GitPin(NamedTuple):
+ git_revision: str
+ release_name: str
+
+
+class ChannelPin(NamedTuple):
+ git_revision: str
+ release_name: str
+ tarball_url: str
+ tarball_sha256: str
+
+
+Pin = Union[AliasPin, SymlinkPin, GitPin, ChannelPin]
+
+
+def copy_to_nix_store(v: Verification, filename: str) -> str:
+ v.status('Putting tarball in Nix store')
+ process = subprocess.run(
+ ['nix-store', '--add', filename], stdout=subprocess.PIPE)
+ v.result(process.returncode == 0)
+ return process.stdout.decode().strip()
+
+
+class AliasSearchPath(NamedTuple):
+ alias_of: str
+
+ # pylint: disable=no-self-use
+ def pin(self, _: Verification, __: Optional[Pin]) -> AliasPin:
+ return AliasPin()
+
+
+class SymlinkSearchPath(NamedTuple):
+ path: str
+
+ # pylint: disable=no-self-use
+ def pin(self, _: Verification, __: Optional[Pin]) -> SymlinkPin:
+ return SymlinkPin()
+
+ def fetch(self, v: Verification, _: Pin) -> str:
+ with tempfile.TemporaryDirectory() as td:
+ archive_filename = os.path.join(td, 'link.tar.gz')
+ os.symlink(self.path, os.path.join(td, 'link'))
+ with tarfile.open(archive_filename, mode='x:gz') as t:
+ t.add(os.path.join(td, 'link'), arcname='link')
+ return copy_to_nix_store(v, archive_filename)
+
+
+class GitSearchPath(NamedTuple):
+ git_ref: str
+ git_repo: str
+
+ def pin(self, v: Verification, old_pin: Optional[Pin]) -> GitPin:
+ if old_pin is not None:
+ assert isinstance(old_pin, GitPin)
+ old_revision = old_pin.git_revision if old_pin is not None else None
+
+ new_revision = git_fetch(v, self, None, old_revision)
+ return GitPin(release_name=git_revision_name(v, self, new_revision),
+ git_revision=new_revision)
+
+ def fetch(self, v: Verification, pin: Pin) -> str:
+ assert isinstance(pin, GitPin)
+ ensure_git_rev_available(v, self, pin, None)
+ return git_get_tarball(v, self, pin)
+
+
+class ChannelSearchPath(NamedTuple):
+ channel_url: str
+ git_ref: str
+ git_repo: str
+
+ def pin(self, v: Verification, old_pin: Optional[Pin]) -> ChannelPin:
+ if old_pin is not None:
+ assert isinstance(old_pin, ChannelPin)
+ old_revision = old_pin.git_revision if old_pin is not None else None
+
+ channel_html, forwarded_url = fetch_channel(v, self)
+ table, new_gitpin = parse_channel(v, channel_html)
+ fetch_resources(v, new_gitpin, forwarded_url, table)
+ ensure_git_rev_available(v, self, new_gitpin, old_revision)
+ check_channel_contents(v, self, table, new_gitpin)
+ return ChannelPin(
+ release_name=new_gitpin.release_name,
+ tarball_url=table['nixexprs.tar.xz'].absolute_url,
+ tarball_sha256=table['nixexprs.tar.xz'].digest,
+ git_revision=new_gitpin.git_revision)
+
+ # pylint: disable=no-self-use
+ def fetch(self, v: Verification, pin: Pin) -> str:
+ assert isinstance(pin, ChannelPin)
+
+ return fetch_with_nix_prefetch_url(
+ v, pin.tarball_url, Digest16(pin.tarball_sha256))
+
+
+SearchPath = Union[AliasSearchPath,
+ SymlinkSearchPath,
+ GitSearchPath,
+ ChannelSearchPath]
+TarrableSearchPath = Union[GitSearchPath, ChannelSearchPath]
+
+