diff --git a/.envrc b/.envrc new file mode 100644 index 0000000000..860f5bc121 --- /dev/null +++ b/.envrc @@ -0,0 +1,2 @@ +export NIX_CONFIG="experimental-features = nix-command flakes" +use flake diff --git a/.github/workflows/lint-nix.yml b/.github/workflows/lint-nix.yml new file mode 100644 index 0000000000..c4541602db --- /dev/null +++ b/.github/workflows/lint-nix.yml @@ -0,0 +1,72 @@ +name: Lint / Nix + +on: + workflow_call: + + push: + branches: [main] + paths: + - .github/workflows/lint-nix.yml + - flake.lock + - flake.nix + - '**/*.nix' + + pull_request: + branches: [main] + paths: + - .github/workflows/lint-nix.yml + - flake.lock + - flake.nix + - '**/*.nix' + +permissions: + contents: read + +concurrency: + group: check-nix-${{ github.ref }} + cancel-in-progress: true + +jobs: + check-nix: + runs-on: ubuntu-22.04 + steps: + - name: Check out repository + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + persist-credentials: false + + - name: Set up Nix + uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 # v22 + + - name: Check flake + shell: bash + run: | + set -o pipefail + + nix flake check \ + --all-systems \ + --show-trace \ + --print-build-logs \ + 2>&1 | tee /tmp/nix-flake-check.log + + - name: Reject Nix warnings + shell: bash + run: | + if grep -Ei '(^|[^[:alpha:]])warning:' /tmp/nix-flake-check.log; then + echo "::error::Nix emitted one or more warnings" + exit 1 + fi + + - name: Check formatting + shell: bash + run: | + mapfile -t nix_files < <(git ls-files '*.nix') + nix run --inputs-from . nixpkgs#nixfmt -- --check "${nix_files[@]}" + + - name: Statix + shell: bash + run: nix run --inputs-from . nixpkgs#statix -- check . + + - name: Deadnix + shell: bash + run: nix run --inputs-from . nixpkgs#deadnix -- --fail . diff --git a/.gitignore b/.gitignore index 17c7eb5d16..49b60ed994 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,7 @@ yarn-error.log* # misc engine.bin + +# Nix +.direnv/ +result diff --git a/README.md b/README.md index 37105b3ab8..bf3e193515 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![lint](https://img.shields.io/github/actions/workflow/status/axone-protocol/docs/lint.yml?label=lint&style=for-the-badge&logo=github)](https://github.com/axone-protocol/docs/actions/workflows/lint.yml) [![build](https://img.shields.io/github/actions/workflow/status/axone-protocol/docs/build.yml?label=build&style=for-the-badge&logo=github)](https://github.com/axone-protocol/docs/actions/workflows/build.yml) +[![Built with Nix](https://img.shields.io/badge/Built_With-Nix-5277C3.svg?style=for-the-badge&logo=nixos&logoColor=white)](https://nixos.org/) [![vercel deploy](https://deploy-badge.vercel.app/vercel/docs-bgu5cuq5p-axone?style=for-the-badge)](https://docs.axone.xyz/) [![license][bsd-3-clause-image]][bsd-3-clause] [![cc-by-sa-4.0][cc-by-sa-image]][cc-by-sa] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..7f4999dfb4 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1780453794, + "narHash": "sha256-bXMRa9VTsHSPXL4Cw8R6JJLQeY3Y/IP4+YJCYVmQ7FY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6b316287bae2ee04c9b93c8c858d930fd07d7338", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-26.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..ef6ba1a4f3 --- /dev/null +++ b/flake.nix @@ -0,0 +1,55 @@ +{ + description = "Axone technical reference development environment"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05"; + }; + + outputs = + { nixpkgs, ... }: + let + supportedSystems = [ + "aarch64-darwin" + "x86_64-darwin" + "x86_64-linux" + "aarch64-linux" + ]; + + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + nixpkgsFor = + system: + import nixpkgs { + inherit system; + config.allowDeprecatedx86_64Darwin = true; + }; + in + { + devShells = forAllSystems ( + system: + let + pkgs = nixpkgsFor system; + in + { + default = pkgs.mkShell { + packages = [ + pkgs.codespell + pkgs.git + pkgs.marksman + pkgs.markdownlint-cli2 + pkgs.nixd + pkgs.nodejs_22 + pkgs.rtk + pkgs.shellcheck + pkgs.typescript-language-server + pkgs.vscode-langservers-extracted + pkgs.yaml-language-server + pkgs.yarn + ]; + shellHook = '' + echo "Axone technical reference development environment loaded" + ''; + }; + } + ); + }; +}