diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index c15d5b508..ca0b37af6 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -9,4 +9,6 @@ jobs: - uses: cachix/install-nix-action@v14 with: nix_path: nixpkgs=channel:nixos-unstable + extra_nix_config: | + experimental-features = nix-command flakes - run: ./ci/test.sh diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index da843ccf6..f20218f96 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -17,6 +17,8 @@ jobs: - uses: cachix/install-nix-action@v14 with: nix_path: nixpkgs=channel:nixos-unstable + extra_nix_config: | + experimental-features = nix-command flakes - name: update nur / nur-combined run: ./ci/update-nur.sh env: @@ -29,6 +31,8 @@ jobs: - uses: cachix/install-nix-action@v14 with: nix_path: nixpkgs=channel:nixos-unstable + extra_nix_config: | + experimental-features = nix-command flakes - name: update nur-search/data/packages.json run: ./ci/update-nur-search.sh env: diff --git a/bin/nur b/bin/nur index e998a1984..998edbeb0 100755 --- a/bin/nur +++ b/bin/nur @@ -4,7 +4,7 @@ import sys import os sys.path.insert(0, os.path.join( - os.path.dirname(os.path.dirname(os.path.realpath(__file__))))) + os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "ci")) from nur import main diff --git a/ci/flake.lock b/ci/flake.lock new file mode 100644 index 000000000..70ea91baf --- /dev/null +++ b/ci/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1631561581, + "narHash": "sha256-3VQMV5zvxaVLvqqUrNz3iJelLw30mIVSfZmAaauM3dA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "7e5bf3925f6fbdfaf50a2a7ca0be2879c4261d19", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1633329294, + "narHash": "sha256-0LpQLS4KMgxslMgmDHmxG/5twFlXDBW9z4Or1iOrCvU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ee084c02040e864eeeb4cf4f8538d92f7c675671", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/ci/flake.nix b/ci/flake.nix new file mode 100644 index 000000000..bf7623922 --- /dev/null +++ b/ci/flake.nix @@ -0,0 +1,12 @@ +{ + description = "Internal flake for ci tasks of NUR"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: { + packages.nur = nixpkgs.legacyPackages.${system}.python3.pkgs.callPackage ./nur.nix {}; + defaultPackage = self.packages.${system}.nur; + }); +} diff --git a/ci/nur.nix b/ci/nur.nix new file mode 100644 index 000000000..c53260ae0 --- /dev/null +++ b/ci/nur.nix @@ -0,0 +1,13 @@ +{ buildPythonApplication, lib, nix-prefetch-git, git, nixUnstable, glibcLocales }: + +buildPythonApplication { + name = "nur"; + src = ./.; + + doCheck = false; + + makeWrapperArgs = [ + "--prefix" "PATH" ":" "${lib.makeBinPath [ nix-prefetch-git git nixUnstable ]}" + "--set" "LOCALE_ARCHIVE" "${glibcLocales}/lib/locale/locale-archive" + ]; +} diff --git a/nur/__init__.py b/ci/nur/__init__.py similarity index 100% rename from nur/__init__.py rename to ci/nur/__init__.py diff --git a/nur/combine.py b/ci/nur/combine.py similarity index 100% rename from nur/combine.py rename to ci/nur/combine.py diff --git a/nur/error.py b/ci/nur/error.py similarity index 100% rename from nur/error.py rename to ci/nur/error.py diff --git a/nur/fileutils.py b/ci/nur/fileutils.py similarity index 100% rename from nur/fileutils.py rename to ci/nur/fileutils.py diff --git a/nur/format_manifest.py b/ci/nur/format_manifest.py similarity index 100% rename from nur/format_manifest.py rename to ci/nur/format_manifest.py diff --git a/nur/index.py b/ci/nur/index.py similarity index 100% rename from nur/index.py rename to ci/nur/index.py diff --git a/nur/manifest.py b/ci/nur/manifest.py similarity index 100% rename from nur/manifest.py rename to ci/nur/manifest.py diff --git a/nur/path.py b/ci/nur/path.py similarity index 100% rename from nur/path.py rename to ci/nur/path.py diff --git a/nur/prefetch.py b/ci/nur/prefetch.py similarity index 100% rename from nur/prefetch.py rename to ci/nur/prefetch.py diff --git a/nur/update.py b/ci/nur/update.py similarity index 100% rename from nur/update.py rename to ci/nur/update.py diff --git a/pyproject.toml b/ci/pyproject.toml similarity index 100% rename from pyproject.toml rename to ci/pyproject.toml diff --git a/setup.cfg b/ci/setup.cfg similarity index 100% rename from setup.cfg rename to ci/setup.cfg diff --git a/setup.py b/ci/setup.py similarity index 100% rename from setup.py rename to ci/setup.py diff --git a/ci/test.sh b/ci/test.sh index 6ad9e3655..1dd66332d 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -1,16 +1,11 @@ #!/usr/bin/env nix-shell -#!nix-shell -p bash -i bash -p python3Packages.mypy -p python3Packages.black -p python3Packages.flake8 -p nix +#!nix-shell -p bash -i bash -p python3Packages.mypy -p python3Packages.black -p python3Packages.flake8 -p nixUnstable set -eux -o pipefail # Exit with nonzero exit code if anything fails -nix run '(import ./release.nix {})' -c 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 ./bin/nur/format-manifest.py and updates repos.json accordingly!" >&2 - exit 1 -fi +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" +cd "${DIR}" # Type checker mypy nur # Format checker @@ -18,5 +13,14 @@ black --check . # Linter flake8 . -nix run '(import ./release.nix {})' -c nur update +cd "${DIR}/.." +nix run "${DIR}#" -- 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 ./bin/nur/format-manifest.py and updates repos.json accordingly!" >&2 + exit 1 +fi + +nix run "${DIR}#" -- update nix-build diff --git a/ci/update-nur-search.sh b/ci/update-nur-search.sh index 75eba0e29..8405982fc 100755 --- a/ci/update-nur-search.sh +++ b/ci/update-nur-search.sh @@ -1,5 +1,5 @@ #!/usr/bin/env nix-shell -#!nix-shell -p git -p nix -p bash -i bash +#!nix-shell -p git -p nixUnstable -p bash -i bash set -eu -o pipefail # Exit with nonzero exit code if anything fails @@ -12,13 +12,15 @@ set -x # build package.json for nur-search # --------------------------------- -nix-build --quiet release.nix +nix build "${DIR}#" -git clone --single-branch "https://$API_TOKEN_GITHUB@github.com/nix-community/nur-combined.git" +cd "${DIR}/.." -git clone --recurse-submodules "https://$API_TOKEN_GITHUB@github.com/nix-community/nur-search.git" +git clone --single-branch "https://${API_TOKEN_GITHUB:-git}@github.com/nix-community/nur-combined.git" || git -C nur-combined pull -nix run '(import ./release.nix {})' -c nur index nur-combined > nur-search/data/packages.json +git clone --recurse-submodules "https://${API_TOKEN_GITHUB:-git}@github.com/nix-community/nur-search.git" || git -C nur-search pull + +nix run "${DIR}#" -- index nur-combined > nur-search/data/packages.json # rebuild and publish nur-search repository # ----------------------------------------- diff --git a/ci/update-nur.sh b/ci/update-nur.sh index dda8af0a7..b94344817 100755 --- a/ci/update-nur.sh +++ b/ci/update-nur.sh @@ -1,5 +1,5 @@ #!/usr/bin/env nix-shell -#!nix-shell -p git -p nix -p bash -i bash +#!nix-shell -p git -p nixUnstable -p bash -i bash set -eu -o pipefail # Exit with nonzero exit code if anything fails @@ -9,17 +9,14 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" source ${DIR}/lib/setup-git.sh set -x -nix run '(import ./release.nix {})' -c nur update -nix-build +nix run ${DIR}# -- update + +cd ${DIR}/.. git clone \ --single-branch \ "https://$API_TOKEN_GITHUB@github.com/nix-community/nur-combined.git" -nix run '(import ./release.nix {})' -c nur combine \ - --irc-notify nur-bot@chat.freenode.net:6697/nixos-nur \ - nur-combined - if [[ -z "$(git diff --exit-code)" ]]; then echo "No changes to the output on this push; exiting." else diff --git a/release.nix b/release.nix deleted file mode 100644 index 5170a8a62..000000000 --- a/release.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ nixpkgs ? import }: - -with import {}; - -python3Packages.buildPythonApplication { - name = "nur"; - src = ./.; - - doCheck = true; - - makeWrapperArgs = [ - "--prefix" "PATH" ":" "${pkgs.lib.makeBinPath [ nix-prefetch-git git nix ]}" - "--set" "LOCALE_ARCHIVE" "${glibcLocales}/lib/locale/locale-archive" - ]; -}