Skip to content

Commit 7d198a8

Browse files
authored
build: add nix build scripts (#14)
* feat: nixify * chore: update docs
1 parent 6677097 commit 7d198a8

File tree

7 files changed

+380
-3
lines changed

7 files changed

+380
-3
lines changed

.gitignore

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
1-
/target
1+
# Created by https://www.toptal.com/developers/gitignore/api/rust,direnv
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=rust,direnv
23

4+
### Direnv ###
5+
.direnv
6+
.envrc
37
.env
8+
9+
### Pre-commit ###
10+
.pre-commit-config.yaml
11+
12+
### Rust ###
13+
# Generated by Cargo
14+
# will have compiled files and executables
15+
debug/
16+
target/
17+
18+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
19+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
20+
Cargo.lock
21+
22+
# These are backup files generated by rustfmt
23+
**/*.rs.bk
24+
25+
# MSVC Windows builds of rustc generate these, which store debugging information
26+
*.pdb
27+
28+
### Misc ###
429
data.db
530
data.db*
31+
32+
# End of https://www.toptal.com/developers/gitignore/api/rust,direnv

.rust-toolchain

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
[toolchain]
22
channel = "1.66"
3+
components = [ "clippy", "llvm-tools-preview", "rust-analyzer", "rust-src" ]
4+
profile = "default"

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ return {
5858
},
5959
}
6060
```
61+
62+
### Nix(OS)
63+
64+
The project is packaged as a [Nix Flake][nix-flakes]. Consume it as you normally would. In your Nix configuration,
65+
*make sure* that sg-nvim is included *both* as a Neovim plugin *and* as an environment/user package
66+
(because `sg-lsp` needs to be on your PATH).
67+
68+
See https://nixos.wiki/wiki/Neovim for more details on configuring neovim using Nix.
69+
Or see https://github.com/willruggiano/neovim.drv for a practical example.
70+
71+
For contributors and maintainers:
72+
73+
- There should be nothing to do, nix-related, when changes are made to the Rust project
74+
- If you're Nix savvy and want to contribute, it would be nice to use [crate2nix] instead
75+
of the generic `buildRustPackage`. A github workflow would be needed to autoupdate the
76+
generated crate2nix files.
77+
6178
### Setup:
6279

6380
```lua
@@ -83,3 +100,5 @@ nnoremap <space>ss <cmd>lua require('sg.telescope').fuzzy_search_results()<CR>
83100
- Demo v2: [YouTube](https://www.youtube.com/watch?v=RCyBnAx-4Q4)
84101
- Demo v1: [YouTube](https://youtu.be/iCdsD6MiLQs)
85102

103+
[nix-flakes]: https://nixos.wiki/wiki/Flakes
104+
[crate2nix]: https://github.com/kolloch/crate2nix

default.nix

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
lib,
3+
rustPlatform,
4+
toolchain,
5+
pkg-config,
6+
openssl,
7+
...
8+
}:
9+
rustPlatform.buildRustPackage {
10+
pname = "sg.nvim";
11+
version = "0.1.0";
12+
13+
src = ./.;
14+
cargoLock = {
15+
lockFile = ./Cargo.lock;
16+
};
17+
18+
nativeBuildInputs = [pkg-config toolchain];
19+
buildInputs = [openssl];
20+
21+
cargoBuildFlags = ["--workspace"];
22+
cargoTestFlags = ["--workspace"];
23+
24+
checkFlags = [
25+
"--skip=test::can_get_lines_and_columns"
26+
"--skip=test::create"
27+
];
28+
29+
postInstall = ''
30+
cp -R {lua,plugin} $out
31+
'';
32+
33+
meta = with lib; {
34+
description = "";
35+
homepage = "https://github.com/tjdevries/sg.nvim";
36+
license = licenses.unlicense;
37+
};
38+
}

flake.lock

Lines changed: 222 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
inputs = {
3+
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
4+
flake-parts.url = "github:hercules-ci/flake-parts";
5+
pre-commit-nix.url = "github:cachix/pre-commit-hooks.nix";
6+
rust-overlay.url = "github:oxalica/rust-overlay";
7+
};
8+
9+
outputs = {
10+
self,
11+
flake-parts,
12+
...
13+
} @ inputs:
14+
flake-parts.lib.mkFlake {inherit inputs;} {
15+
imports = [
16+
inputs.pre-commit-nix.flakeModule
17+
];
18+
19+
flake = {
20+
overlays.default = final: prev: {
21+
sg-nvim = self.packages."${prev.system}".default;
22+
};
23+
};
24+
25+
systems = ["x86_64-linux" "aarch64-darwin"];
26+
perSystem = {
27+
config,
28+
system,
29+
inputs',
30+
...
31+
}: let
32+
pkgs = import inputs.nixpkgs {
33+
inherit system;
34+
overlays = [
35+
inputs.rust-overlay.overlays.default
36+
];
37+
};
38+
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./.rust-toolchain;
39+
in {
40+
devShells.default = pkgs.mkShell {
41+
name = "sg.nvim";
42+
buildInputs = with pkgs; [
43+
openssl
44+
pkg-config
45+
toolchain
46+
];
47+
shellHook = ''
48+
${config.pre-commit.installationScript}
49+
'';
50+
};
51+
52+
formatter = pkgs.alejandra;
53+
54+
packages.default = pkgs.callPackage ./. {inherit toolchain;};
55+
56+
pre-commit = {
57+
settings = {
58+
hooks.alejandra.enable = true;
59+
hooks.rustfmt.enable = true;
60+
hooks.cargo-check.enable = true;
61+
};
62+
};
63+
};
64+
};
65+
}

0 commit comments

Comments
 (0)