Skip to content
Snippets Groups Projects
__init__.py 793 B
Newer Older
  • Learn to ignore specific revisions
  • """
    Helpers for development and CI scripts.
    """
    from __future__ import annotations
    
    import subprocess
    
    
    def get_url_hash(hash_type, name, url) -> dict[str, str]:
        """
        Get the nix hash of the given URL.
    
        :returns: Dictionary of arguments suitable to pass to :nix:`pkgs.fetchzip`
            or a function derived from it (such as :nix:`pkgs.fetchFromGitLab`)
            to specify the hash.
        """
        output = subprocess.run(
            [
                "nix-prefetch-url",
                "--type",
                hash_type,
                "--unpack",
                "--name",
                name,
                url,
            ],
            capture_output=True,
            check=True,
            encoding="utf-8",
        )
    
        return {
            "outputHashAlgo": hash_type,
            "outputHash": output.stdout.strip(),
        }