diff --git a/ci/deploy.sh b/ci/deploy.sh index 3f5e41983..1a94450c6 100755 --- a/ci/deploy.sh +++ b/ci/deploy.sh @@ -20,15 +20,17 @@ fi export encrypted_080f214a372c_key= encrypted_080f214a372c_iv= -./bin/nur format-manifest +nix-build release.nix + +result/bin/nur format-manifest if [ -n "$(git diff --exit-code repos.json)" ]; then echo "repos.json was not formatted before committing repos.json:" >&2 git diff --exit-code repos.json - echo "Please run ./nur/format-manifest.py and updates repos.json accordingly!" >&2 + echo "Please run ./bin/nur/format-manifest.py and updates repos.json accordingly!" >&2 exit 1 fi -./bin/nur update +result/bin/nur update nix-build # Pull requests and commits to other branches shouldn't try to deploy, just build to verify @@ -44,7 +46,7 @@ git config --global commit.gpgsign true git clone git@github.com:nix-community/nur-channel -./bin/nur build-channel nur-channel +result/bin/nur build-channel nur-channel if [[ -z "$(git diff --exit-code)" ]]; then echo "No changes to the output on this push; exiting." diff --git a/nur/path.py b/nur/path.py index f8fb911a4..260f0d795 100644 --- a/nur/path.py +++ b/nur/path.py @@ -1,7 +1,34 @@ +import os import subprocess from pathlib import Path -ROOT = Path(__file__).parent.parent.resolve() +from .error import NurError + + +def _is_repo(path: Path) -> bool: + return path.joinpath("lib/evalRepo.nix").exists() + + +def _find_root() -> Path: + source_root = Path(__file__).parent.parent.resolve() + if _is_repo(source_root): + # if it was not build with release.nix + return source_root + else: + root = Path(os.getcwd()).resolve() + + while True: + if _is_repo(root): + return root + new_root = root.parent.resolve() + if new_root == root: + if _is_repo(new_root): + return new_root + else: + raise NurError("NUR repository not found in current directory") + + +ROOT = _find_root() LOCK_PATH = ROOT.joinpath("repos.json.lock") MANIFEST_PATH = ROOT.joinpath("repos.json") EVALREPO_PATH = ROOT.joinpath("lib/evalRepo.nix") diff --git a/release.nix b/release.nix new file mode 100644 index 000000000..4f987843c --- /dev/null +++ b/release.nix @@ -0,0 +1,12 @@ +{ nixpkgs ? import }: + +with import {}; + +python3Packages.buildPythonApplication { + name = "nur"; + src = ./.; + + makeWrapperArgs = [ + "--prefix" "PATH" ":" "${stdenv.lib.makeBinPath [ nix-prefetch-git git nix ]}" + ]; +} diff --git a/setup.py b/setup.py new file mode 100644 index 000000000..4332d5454 --- /dev/null +++ b/setup.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +from setuptools import setup, find_packages +import sys + +assert sys.version_info >= (3, 6, 0), "nur requires Python 3.6+" + +setup( + name="nur", + version="0.0.1", + description="Tooling to maintain NUR", + author="Jörg Thalheim", + author_email="joerg@thalheim.io", + url="https://github.com/nix-community/nur", + license="MIT", + packages=find_packages(), + entry_points={"console_scripts": ["nur = nur:main"]}, + extras_require={"dev": ["mypy", "flake8>=3.5,<3.6", "black"]}, + classifiers=[ + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Topic :: Utilities", + "Intended Audience :: Developers", + "Programming Language :: Python :: 3.6", + ], +)