Merge pull request #203 from nix-community/fix-search

Fix search
This commit is contained in:
Jörg Thalheim 2020-04-02 12:58:55 +01:00 committed by GitHub
commit 5e4eafc662
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 23 deletions

View file

@ -15,7 +15,9 @@ nix-build --quiet release.nix
git clone git@github.com:nix-community/nur-search
nix run '(import ./release.nix {})' -c nur index . > nur-search/data/packages.json
git clone git@github.com:nix-community/nur-combined
nix run '(import ./release.nix {})' -c nur index nur-combined > nur-search/data/packages.json
# rebuild and publish nur-search repository
# -----------------------------------------

View file

@ -21,7 +21,7 @@ let
localPath = ../repos + "/${name}";
in
if lib.pathExists localPath then
"${localPath}"
localPath
else if lib.hasPrefix "https://github.com" attr.url && !submodules then
fetchzip {
url = "${attr.url}/archive/${revision.rev}.zip";

View file

@ -8,23 +8,20 @@ from typing import Any, Dict
def index_repo(directory: Path, repo: str, expression_file: str) -> Dict[str, Any]:
default_nix = directory.joinpath("default.nix")
fetch_source_cmd = [
"nix-build",
"--builders",
"",
"--no-out-link",
str(default_nix),
"-A",
f'repo-sources."{repo}"',
]
repo_path = subprocess.check_output(fetch_source_cmd).strip().decode("utf-8")
expression_path = Path(repo_path).joinpath(expression_file)
default_nix = directory.joinpath("default.nix").resolve()
expr = """
with import <nixpkgs> {};
let
nur = import %s { nurpkgs = pkgs; inherit pkgs; };
in
callPackage (nur.repo-sources."%s" + "/%s") {}
""" % (
default_nix,
repo,
expression_file,
)
with NamedTemporaryFile(mode="w") as f:
expr = f"with import <nixpkgs> {{}}; callPackage {expression_path} {{}}"
f.write(expr)
f.flush()
query_cmd = ["nix-env", "-qa", "*", "--json", "-f", str(f.name)]
@ -42,11 +39,11 @@ def index_repo(directory: Path, repo: str, expression_file: str) -> Dict[str, An
position = pkg["meta"].get("position", None)
# TODO commit hash
prefix = f"https://github.com/nix-community/nur-combined/tree/master/repos/{repo}"
if position is not None and position.startswith(repo_path):
prefix_len = len(repo_path)
stripped = position[prefix_len:]
path, line = stripped.rsplit(":", 1)
pkg["meta"]["position"] = f"{prefix}{path}#L{line}"
if position is not None and position.startswith("/nix/store"):
path_str, line = position.rsplit(":", 1)
path = Path(path_str)
stripped = path.parts[4:]
pkg["meta"]["position"] = f"{prefix}{stripped}#L{line}"
else:
pkg["meta"]["position"] = prefix
pkgs[f"nur.repos.{repo}.{name}"] = pkg
@ -62,6 +59,7 @@ def index_command(args: Namespace) -> None:
pkgs: Dict[str, Any] = {}
for (repo, data) in repos.items():
pkgs.update(index_repo(directory, repo, data.get("file", "default.nix")))
repo_pkgs = index_repo(directory, repo, data.get("file", "default.nix"))
pkgs.update(repo_pkgs)
json.dump(pkgs, sys.stdout, indent=4)