diff --git a/README.md b/README.md index ed74ebee0..4be241732 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,22 @@ and open a pull request towards [https://github.com/nix-community/NUR](https://g At the moment repositories should be buildable on Nixpkgs unstable. Later we will add options to also provide branches for other Nixpkgs channels. +## Use a different nix file as root expression + +To use a different file instead of `default.nix` to load packages from, set the `file` +option to a path relative to the repository root: + +```json +{ + "repos": { + "mic92": { + "url": "https://github.com/Mic92/nur-packages", + "file": "subdirectory/default.nix" + } + } +} +``` + ## Contribution guideline - When adding packages to your repository make sure they build and set diff --git a/default.nix b/default.nix index 65cc6301f..0a5fb9a5f 100644 --- a/default.nix +++ b/default.nix @@ -20,7 +20,9 @@ let inherit (revision) rev sha256; }; - createRepo = (name: attr: callPackages (repoSource name attr) {}); + expressionPath = name: attr: (repoSource name attr) + "/" + (attr.file or ""); + + createRepo = (name: attr: callPackages (expressionPath name attr) {}); in { repos = lib.mapAttrs createRepo manifest; } diff --git a/nur/update.py b/nur/update.py index a41b44266..273b65f32 100755 --- a/nur/update.py +++ b/nur/update.py @@ -51,13 +51,13 @@ class GithubRepo(): f"Repository {self.owner}/{self.name} not found") raise - def prefetch(self, ref: str) -> Tuple[str, Path]: + def prefetch(self, ref: str, nix_file: str) -> Tuple[str, Path]: data = subprocess.check_output([ "nix-prefetch-url", "--unpack", "--print-path", self.url(f"archive/{ref}.tar.gz") ]) sha256, path = data.decode().strip().split("\n") - return sha256, Path(path) + return sha256, Path(path).joinpath(nix_file) class RepoType(Enum): @@ -82,7 +82,7 @@ class Repo(): self.type = RepoType.from_url(url) -def prefetch_git(url: str) -> Tuple[str, str, Path]: +def prefetch_git(url: str, nix_file: str) -> Tuple[str, str, Path]: with tempfile.TemporaryDirectory() as tempdir: try: result = subprocess.run( @@ -95,12 +95,13 @@ def prefetch_git(url: str) -> Tuple[str, str, Path]: metadata = json.loads(result.stdout) lines = result.stderr.decode("utf-8").split("\n") - path = re.search("path is (.+)", lines[-5]) - assert path is not None - return metadata["rev"], metadata["sha256"], path.group(1) + repo_path = re.search("path is (.+)", lines[-5]) + assert repo_path is not None + path = Path(repo_path.group(1)).joinpath(nix_file) + return metadata["rev"], metadata["sha256"], path -def prefetch(name: str, url: ParseResult, +def prefetch(name: str, url: ParseResult, nix_file: str, locked_repo: Optional[Repo]) -> Tuple[Repo, Optional[Path]]: repo_type = RepoType.from_url(url) @@ -111,15 +112,16 @@ def prefetch(name: str, url: ParseResult, if locked_repo is not None: if locked_repo.rev == commit: return locked_repo, None - sha256, path = gh_repo.prefetch(commit) + sha256, path = gh_repo.prefetch(commit, nix_file) else: - commit, sha256, path = prefetch_git(url.geturl()) + commit, sha256, path = prefetch_git(url.geturl(), nix_file) return Repo(name, url, commit, sha256), path -def update(name: str, url: ParseResult, locked_repo: Optional[Repo]) -> Repo: - repo, path = prefetch(name, url, locked_repo) +def update(name: str, url: ParseResult, nix_file: str, + locked_repo: Optional[Repo]) -> Repo: + repo, path = prefetch(name, url, nix_file, locked_repo) if path: with tempfile.NamedTemporaryFile(mode="w") as f: f.write(f""" @@ -165,6 +167,7 @@ def main() -> None: for name, repo in manifest["repos"].items(): url = urlparse(repo["url"]) + nix_file = repo.get("file", "default.nix") repo_json = lock_manifest["repos"].get(name, None) if repo_json and repo_json["url"] != url.geturl(): repo_json = None @@ -178,7 +181,7 @@ def main() -> None: ) try: - repos.append(update(name, url, locked_repo)) + repos.append(update(name, url, nix_file, locked_repo)) except NurError as e: print(f"failed to update repository {name}: {e}", file=sys.stderr) if locked_repo: