From db6e91465040dc1c922263665b7a021bb09c7d7e Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Wed, 17 Jan 2024 19:26:12 +0100 Subject: [PATCH] build: add nix dev + build environment + ci builds --- .envrc | 1 + .github/workflows/nix-build.yml | 28 +++++ .gitignore | 8 +- flake.lock | 175 ++++++++++++++++++++++++++++++++ flake.nix | 81 +++++++++++++++ nix/overlay.nix | 22 ++++ 6 files changed, 312 insertions(+), 3 deletions(-) create mode 100644 .envrc create mode 100644 .github/workflows/nix-build.yml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/overlay.nix diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..a1d35403 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake . -Lv diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml new file mode 100644 index 00000000..7691dc71 --- /dev/null +++ b/.github/workflows/nix-build.yml @@ -0,0 +1,28 @@ +--- +name: "Nix build" +on: + pull_request: + push: + branches: [ master ] +jobs: + build: + name: ${{ matrix.attribute }} / ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + attribute: + - .#devShells.x86_64-linux.default + - .#packages.x86_64-linux.rocks + - .#checks.x86_64-linux.pre-commit-check + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@v9 + - uses: cachix/cachix-action@v14 + with: + name: neorocks + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + # Some of the tests query luarocks.org. TODO: Get sandboxed tests working + - run: nix build "${{matrix.attribute}}" --option sandbox false diff --git a/.gitignore b/.gitignore index 29bd239d..3547ac06 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ -zig-out -zig-cache - +.direnv # Added by cargo /target + +# Added by nix + +/result diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..cedd6d05 --- /dev/null +++ b/flake.lock @@ -0,0 +1,175 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1704982712, + "narHash": "sha256-2Ptt+9h8dczgle2Oo6z5ni5rt/uLMG47UFTR1ry/wgg=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "07f6395285469419cf9d078f59b5b49993198c00", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1703887061, + "narHash": "sha256-gGPa9qWNc6eCXT/+Z5/zMkyYOuRZqeFZBDbopNZQkuY=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "43e1aa1308018f37118e34d3a9cb4f5e75dc11d5", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1705403940, + "narHash": "sha256-bl7E3w35Bleiexg01WsN0RuAQEL23HaQeNBC2zjt+9w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f0326542989e1bdac955ad6269b334a8da4b0c95", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1703961334, + "narHash": "sha256-M1mV/Cq+pgjk0rt6VxoyyD+O8cOUiai8t9Q6Yyq4noY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b0d36bd0a420ecee3bc916c91886caca87c894e9", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1704874635, + "narHash": "sha256-YWuCrtsty5vVZvu+7BchAxmcYzTMfolSPP5io8+WYCg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3dc440faeee9e889fe2d1b4d25ad0f430d449356", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1705229514, + "narHash": "sha256-itILy0zimR/iyUGq5Dgg0fiW8plRDyxF153LWGsg3Cw=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "ffa9a5b90b0acfaa03b1533b83eaf5dead819a05", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..9eca6daf --- /dev/null +++ b/flake.nix @@ -0,0 +1,81 @@ +{ + description = "Luarocks <3 Rust"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + pre-commit-hooks = { + url = "github:cachix/pre-commit-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = inputs @ { + self, + nixpkgs, + flake-parts, + pre-commit-hooks, + ... + }: let + overlay = import ./nix/overlay.nix {inherit self;}; + in + flake-parts.lib.mkFlake {inherit inputs;} { + systems = [ + "x86_64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + perSystem = { + config, + self', + inputs', + pkgs, + system, + ... + }: let + pkgs = import nixpkgs { + inherit system; + overlays = [ + overlay + ]; + }; + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = self; + hooks = { + alejandra.enable = true; + rustfmt.enable = true; + }; + }; + in { + packages = with pkgs; { + default = rocks; + inherit rocks; + }; + + devShells.default = pkgs.mkShell { + name = "rocks devShell"; + inherit (pre-commit-check) shellHook; + buildInputs = + (with pkgs; [ + rust-analyzer + ]) + ++ (with pre-commit-hooks.packages.${system}; [ + alejandra + rustfmt + ]) + ++ pkgs.rocks.buildInputs + ++ pkgs.rocks.nativeBuildInputs; + }; + + checks = with pkgs; { + inherit + pre-commit-check + rocks + ; + }; + }; + flake = { + overlays.default = overlay; + }; + }; +} diff --git a/nix/overlay.nix b/nix/overlay.nix new file mode 100644 index 00000000..a5ebb263 --- /dev/null +++ b/nix/overlay.nix @@ -0,0 +1,22 @@ +{self}: final: prev: { + rocks = with final; + rustPlatform.buildRustPackage { + pname = "rocks"; + version = ((lib.importTOML "${self}/rocks-bin/Cargo.toml").package).version; + + src = self; + + cargoLock = { + lockFile = ../Cargo.lock; + }; + + nativeBuildInputs = [ + pkg-config + ]; + + buildInputs = [ + luajit + openssl + ]; + }; +}