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

Simplified nix flake for build, dev shell, and cached build #74

Open
wants to merge 1 commit into
base: main
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ dist
lsp-ai.log
.vsix
lsp-ai-chat.md
result
100 changes: 100 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
description = "LSP-AI: Open-source language server for AI-powered functionality";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
};

outputs =
{
self,
nixpkgs,
flake-utils,
rust-overlay,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
config.allowUnfree = true;
};
rustVersion = pkgs.rust-bin.stable.latest.default;

commonBuildInputs = with pkgs; [
openssl
zlib
];

commonNativeBuildInputs = with pkgs; [
pkg-config
cmake
rustVersion
perl
];

in
rec {
packages = rec {
default = pkgs.rustPlatform.buildRustPackage {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main package. Essentially when running nix build locally, the default entry is the starting point. The devPackage and devShells are more of conveniences for being dropped into a shell with all needed dependencies, but still track a cached build at /tmp/.cargo so during the dev cycle, one can run cargo commands as they please with the necessary caches.

pname = "lsp-ai";
version = "0.7.0";

src = ./.;

cargoLock = {
lockFile = ./Cargo.lock;
allowBuiltinFetchGit = true;
};

nativeBuildInputs = commonNativeBuildInputs;
buildInputs = commonBuildInputs;

doCheck = false;
Copy link
Contributor Author

@ProjectInitiative ProjectInitiative Sep 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doCheck = false;
Disables all testing. See nixpkgs implementation to see how to disable individual tests. As this nix flake is most likely not going to be integrated into any CI, I think it is okay to disable them for now since the goal is just for folks who want to pull and have a dev env/build from source avenue. Suggestions welcome.


meta = with pkgs.lib; {
description = "An open-source language server that serves as a backend for AI-powered functionality";
homepage = "https://github.com/SilasMarvin/lsp-ai";
license = licenses.mit;
maintainers =
[
# Add maintainers here
];
};
};

devPackage = default.overrideAttrs (oldAttrs: {
name = "lsp-ai-dev";

buildPhase = ''
export CARGO_HOME="/tmp/.cargo"
export RUSTUP_HOME="/tmp/.rustup"
cargo build
'';

installPhase = ''
mkdir -p $out/bin
cp target/debug/lsp-ai $out/bin/
'';
});
};

devShells.default = pkgs.mkShell {
inputsFrom = [ packages.default ];
packages = with pkgs; [
rust-analyzer
clippy
rustfmt
];

shellHook = ''
export CARGO_HOME="/tmp/.cargo"
export RUSTUP_HOME="/tmp/.rustup"
'';
};
}
);
}