Skip to content

Commit

Permalink
Merge pull request #1 from nvim-neorocks/flake
Browse files Browse the repository at this point in the history
build: add nix dev + build environment + ci builds
  • Loading branch information
mrcjkb authored Jan 18, 2024
2 parents 4274d19 + db6e914 commit a3c00da
Show file tree
Hide file tree
Showing 6 changed files with 312 additions and 3 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake . -Lv
28 changes: 28 additions & 0 deletions .github/workflows/nix-build.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
zig-out
zig-cache

.direnv

# Added by cargo

/target

# Added by nix

/result
175 changes: 175 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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;
};
};
}
22 changes: 22 additions & 0 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
@@ -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
];
};
}

0 comments on commit a3c00da

Please sign in to comment.