Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimize nix CI time + nix nvim integration test #53

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions .github/workflows/nix.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: nix-build
name: nix

on:
pull_request:
push:
branches: ["master"]
branches: [ "master" ]

jobs:
nix-build:
nix:
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -15,10 +15,37 @@ jobs:
- macos-latest
fail-fast: false

name: nix-build (${{ matrix.os }})
name: nix test (${{ matrix.os }})
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22
- name: Install Nix
uses: nixbuild/nix-quick-install-action@v25
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- run: nix build
nix_conf: |
substituters = https://cache.nixos.org/ https://nix-community.cachix.org
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=
keep-outputs = true

- name: Restore and cache Nix store
uses: nix-community/cache-nix-action@v1
with:
linux-gc-enabled: true
macos-gc-enabled: true

# 500 MB
linux-max-store-size: 500000000
# 500 MB
macos-max-store-size: 500000000

# save a new cache every time
key: cache-${{ matrix.os }}-${{ hashFiles('.github/workflows/nix.yaml') }}
restore-keys: |
cache-${{ matrix.os }}-${{ hashFiles('.github/workflows/nix.yaml') }}
cache-${{ matrix.os }}-

- run: nix flake show
- run: nix build .#neovim-with-sg
- run: nix run .#neovim-with-sg -- --version
# Should have a default app
- run: nix run . -- --version
- run: nix run . -- -l scripts/test.lua
28 changes: 20 additions & 8 deletions contrib/default.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
{
pkgs,
symlinkJoin,
pkgs ? (import <nixpkgs> {}),
symlinkJoin ? pkgs.symlinkJoin,
sg-workspace ? (pkgs.callPackage (import ./workspace-drv.nix)),
sg-plugin ? (pkgs.callPackage (import ./plugin-drv.nix)),
meta ? (pkgs.callPackage (import ./meta.nix)),
...
}:
symlinkJoin {
name = "sg.nvim";
paths = [sg-workspace sg-plugin];
inherit meta;
}
}: let
sg-nvim = symlinkJoin {
name = "sg.nvim";
paths = [sg-workspace sg-plugin];
inherit meta;
};
in
sg-nvim
// {
# provides quick access if we're using home-manager
hm-vimPlugin = {
plugin = sg-nvim;
config = ''
package.cpath = package.cpath .. ";${sg-nvim}/lib/*.so;${sg-nvim}/lib/*.dylib"
'';
type = "lua";
};
}
4 changes: 2 additions & 2 deletions contrib/plugin-drv.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
pkgs,
stdenv,
proj_root ? ./.,
proj_root ? ./..,
meta ? (pkgs.callPackage (import ./meta.nix)),
...
}:
Expand All @@ -11,7 +11,7 @@ stdenv.mkDerivation {
phases = ["installPhase"];
installPhase = ''
mkdir -p $out
cp -r $src/{lua,plugin} $out
cp -r $src/{lua,plugin,dist} $out
'';
inherit meta;
}
16 changes: 16 additions & 0 deletions flake.lock

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

53 changes: 52 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
pre-commit-nix.url = "github:cachix/pre-commit-hooks.nix";
rust-overlay.url = "github:oxalica/rust-overlay";
crane.url = "github:ipetkov/crane";
nixpkgs-latest-vimplugins.url = "github:nixos/nixpkgs";
};

outputs = {
Expand All @@ -19,7 +20,7 @@

flake = {
overlays.default = final: prev: {
sg-nvim = self.packages."${prev.system}".default;
inherit (self.packages.${prev.system}) sg-nvim;
};
# HACK: both nixpkgs.lib and pkgs.lib contain licenses
# Technically impossible to do `callPackage` without proper `${system}`
Expand All @@ -38,6 +39,12 @@
inherit system;
overlays = [
inputs.rust-overlay.overlays.default
(final: prev: {
# NOTE: use legacyPackages to prevent importing everything on latest nixpkgs
# we should use this because we all know teej develops against
# latest Plenary
vimPlugins = inputs.nixpkgs-latest-vimplugins.legacyPackages.${system}.vimPlugins;
})
];
};
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
Expand Down Expand Up @@ -76,6 +83,50 @@
};

packages.default = self'.packages.all;
# for parallel along with our overlay
packages.sg-nvim = self'.packages.all;

packages.neovim-with-sg = let
inherit (self'.packages) sg-nvim;
plug = pkgs.vimPlugins;
cfg = pkgs.neovimUtils.makeNeovimConfig {
withNodeJs = true;
plugins = [
{plugin = plug.plenary-nvim;}
{plugin = sg-nvim;}
];
# TODO: alternative way is to add to LUA_CPATH, correctness unknown.
customRC = ''
lua <<EOF
package.cpath = package.cpath .. ";${sg-nvim}/lib/*.so;${sg-nvim}/lib/*.dylib"
EOF
'';
# `-u` prevents `-l` to go on happy route. We will instead use
# `$VIMINIT` for sandboxed neovim even in the impure shell
wrapRc = false;
};
vimrc-drv = pkgs.writeTextFile {
name = "init.vim";
text = cfg.neovimRcContent;
};
cfg-set-viminit =
cfg
// {
wrapperArgs =
(pkgs.lib.escapeShellArgs cfg.wrapperArgs)
+ " "
+ "--set VIMINIT \':source ${vimrc-drv}\'"
+ " "
+ ''--suffix PATH : "${pkgs.lib.makeBinPath [self'.packages.sg-nvim]}"'';
};
in
pkgs.wrapNeovimUnstable pkgs.neovim.unwrapped cfg-set-viminit;

apps.neovim-with-sg = {
type = "app";
program = self'.packages.neovim-with-sg;
};
apps.default = self'.apps.neovim-with-sg;

pre-commit = {
settings = {
Expand Down
Loading