diff --git a/.github/actions/nix-setup/action.yaml b/.github/actions/nix-setup/action.yaml new file mode 100644 index 00000000..2c1111b3 --- /dev/null +++ b/.github/actions/nix-setup/action.yaml @@ -0,0 +1,20 @@ +--- +name: Setup Nix and direnv +description: | + Sets up the Nix package manager and direnv to use the same packages + vendored through Nix for local development. +inputs: + github_token: + description: 'Github Access Token' + required: true +runs: + using: composite + steps: + - name: Install Nix package manager + uses: cachix/install-nix-action@v22 + with: + github_access_token: ${{ inputs.github_token }} + extra_nix_config: | + experimental-features = nix-command flakes + - name: Set up Nix cache + uses: DeterminateSystems/magic-nix-cache-action@v2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3d021ca..cf8bf0ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,6 +59,51 @@ jobs: env: DATABASE_URL: postgres://eventually:password@localhost:5432/eventually?sslmode=disable + nix-test: + name: Test [Nix] + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.required }} + strategy: + matrix: + build: [stable, nightly] + include: + - build: stable + required: true + toolchain: stable + - build: nightly + required: false + toolchain: nightly + + services: + postgres: + env: + POSTGRES_USER: eventually + POSTGRES_PASSWORD: password + POSTGRES_DB: eventually + image: postgres:latest + ports: ["5432:5432"] + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Checkout source code + uses: actions/checkout@v4 + - name: Set up Nix system + uses: ./.github/actions/nix-setup + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Preload nix-develop shell + run: nix develop .#${{ matrix.toolchain }} --verbose -c echo "nix-develop shell loaded!" + - name: Rust cache + uses: Swatinem/rust-cache@v2 + - name: Run 'cargo test' + run: nix develop .#${{ matrix.toolchain }} --verbose -c cargo test --workspace --all-features + env: + DATABASE_URL: postgres://eventually:password@localhost:5432/eventually?sslmode=disable + coverage: name: Code Coverage runs-on: ubuntu-latest diff --git a/flake.nix b/flake.nix index 80dfd54b..10c5cda8 100644 --- a/flake.nix +++ b/flake.nix @@ -19,20 +19,55 @@ pkgs = import nixpkgs { inherit system overlays; + config.allowBroken = true; }; - nativeBuildInputs = with pkgs; [ rust-bin.nightly.latest.default protobuf3_24 ]; + nativeBuildInputs = with pkgs; [ protobuf3_24 ]; buildInputs = with pkgs; [ pkg-config openssl ] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.SystemConfiguration ]; + + packages = with pkgs; [ + cargo-llvm-cov + ]; + + defaultShell = with pkgs; mkShell { + inherit buildInputs packages; + + nativeBuildInputs = with pkgs; nativeBuildInputs ++ [ + rust-bin.nightly.latest.default + ]; + + PROTOC = "${protobuf3_24}/bin/protoc"; + }; in with pkgs; { - devShells.default = with pkgs; mkShell { - inherit nativeBuildInputs buildInputs; + devShells = rec { + default = nightly; - PROTOC = "${protobuf3_24}/bin/protoc"; + nightly = with pkgs; mkShell { + inherit buildInputs packages; + + nativeBuildInputs = with pkgs; nativeBuildInputs ++ [ + rust-bin.nightly.latest.default + ]; + + PROTOC = "${protobuf3_24}/bin/protoc"; + }; + + stable = with pkgs; mkShell { + name = "stable"; + + inherit buildInputs packages; + + nativeBuildInputs = with pkgs; nativeBuildInputs ++ [ + rust-bin.stable.latest.default + ]; + + PROTOC = "${protobuf3_24}/bin/protoc"; + }; }; } );