1
1
mirror of https://github.com/oxalica/nil.git synced 2024-11-25 07:45:26 +03:00
nil/flake.nix

188 lines
6.0 KiB
Nix
Raw Normal View History

rec {
2022-08-04 10:53:05 +03:00
description = "Language Server for Nix Expression Language";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.flake-utils.follows = "flake-utils";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, flake-utils, nixpkgs, rust-overlay }:
2022-09-24 16:09:35 +03:00
let
2023-02-26 01:30:07 +03:00
inherit (builtins) substring;
inherit (nixpkgs) lib;
2024-05-30 19:15:55 +03:00
# For rustfmt and fuzz.
nightlyVersion = "2024-05-01";
2023-02-26 01:30:07 +03:00
mtime = self.lastModifiedDate;
date = "${substring 0 4 mtime}-${substring 4 2 mtime}-${substring 6 2 mtime}";
rev = self.rev or (lib.warn "Git changes are not committed" (self.dirtyRev or "dirty"));
2023-02-26 01:30:07 +03:00
mkNil = { rustPlatform, nixVersions, ... }:
2022-09-24 16:09:35 +03:00
rustPlatform.buildRustPackage {
pname = "nil";
version = "unstable-${date}";
src = self;
2023-04-20 18:34:09 +03:00
cargoLock = {
lockFile = ./Cargo.lock;
2023-05-01 20:26:16 +03:00
allowBuiltinFetchGit = false;
2023-04-20 18:34:09 +03:00
};
nativeBuildInputs = [ (nixVersions.latest or nixVersions.unstable) ];
2022-09-03 23:53:31 +03:00
CFG_RELEASE = "git-${rev}";
meta = {
inherit description;
homepage = "https://github.com/oxalica/nil";
license = with lib.licenses; [ mit asl20 ];
2023-10-09 04:27:59 +03:00
mainProgram = "nil";
};
2022-09-24 16:09:35 +03:00
};
2023-02-26 01:30:07 +03:00
mkCocNil = { runCommand, nodejs, esbuild }:
runCommand "coc-nil-unstable-${date}" {
nativeBuildInputs = [ nodejs esbuild ];
src = ./editors/coc-nil;
} ''
cp -r --no-preserve=all $src ./source
cd source
npm run build --offline
mkdir -p $out
cp -rt $out lib package{,-lock}.json
'';
2022-09-24 16:09:35 +03:00
in
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
rustPkgs = rust-overlay.packages.${system};
2022-09-03 23:53:31 +03:00
clippyFlags = lib.concatStringsSep " " [
"-D" "warnings"
"-D" "clippy::dbg_macro"
2023-03-10 10:59:30 +03:00
"-D" "clippy::todo"
"-D" "clippy::doc_markdown"
2023-03-10 10:54:19 +03:00
"-D" "clippy::manual-let-else"
"-D" "clippy::missing-panics-doc"
"-D" "clippy::semicolon_if_nothing_returned"
2023-03-10 10:59:30 +03:00
"-D" "clippy::uninlined_format_args"
2023-09-08 15:54:38 +03:00
# FIXME: https://github.com/rust-lang/rust-clippy/issues/11436
"-A" "clippy::missing_panics_doc"
];
2022-09-24 16:09:35 +03:00
pre-commit = pkgs.writeShellScriptBin "pre-commit" ''
set -e
die() { echo "$*" >&2; exit 1; }
2022-09-05 21:16:00 +03:00
if git_dir="$(git rev-parse --show-toplevel)"; then
cd "$git_dir"
fi
cargo fmt --all --check \
2022-09-24 16:09:35 +03:00
|| die 'Format failed'
cargo clippy --workspace --all-targets -- ${clippyFlags} \
|| die 'Clippy failed'
2023-02-26 01:30:07 +03:00
( cd editors/coc-nil; npm run lint )
2022-09-24 16:09:35 +03:00
'';
2022-09-24 16:09:35 +03:00
in
2023-02-14 18:48:32 +03:00
rec {
2023-02-26 01:30:07 +03:00
packages = rec {
2022-09-24 16:09:35 +03:00
default = nil;
2023-02-26 01:30:07 +03:00
nil = pkgs.callPackage mkNil { };
coc-nil = pkgs.callPackage mkCocNil { };
2022-08-04 10:53:05 +03:00
};
devShells.without-rust = pkgs.mkShell {
2023-02-14 18:48:32 +03:00
nativeBuildInputs = with pkgs; [
2022-09-24 16:09:35 +03:00
# Override the stable rustfmt.
2024-05-30 19:15:55 +03:00
rustPkgs."rust-nightly_${nightlyVersion}".availableComponents.rustfmt
2023-02-14 18:48:32 +03:00
# Don't include `nix` by default. If would override user's (newer
# or patched) one, cause damage or misbehavior due to version
# mismatch.
# If you do want a locked one, use `devShells.full` below.
2023-02-26 01:30:07 +03:00
nodejs
watchman # Required by coc.nvim for file watching.
2023-02-26 01:30:07 +03:00
2022-09-24 16:09:35 +03:00
jq
pre-commit
nixpkgs-fmt
2022-09-28 13:17:33 +03:00
(import ./dev/nvim-lsp.nix { inherit pkgs; })
2022-09-24 16:09:35 +03:00
(import ./dev/vim-coc.nix { inherit pkgs; })
2022-09-28 13:17:33 +03:00
(import ./dev/vim-lsp.nix { inherit pkgs; })
2022-09-24 16:09:35 +03:00
] ++ lib.optionals (lib.meta.availableOn stdenv.hostPlatform vscodium) [
(import ./dev/vscodium.nix { inherit pkgs; })
2023-01-19 10:35:03 +03:00
] ++ lib.optionals (lib.meta.availableOn stdenv.hostPlatform gdb) [
gdb
2022-09-24 16:09:35 +03:00
];
2022-09-24 16:09:35 +03:00
RUST_BACKTRACE = "short";
NIXPKGS = nixpkgs;
CLIPPY_FLAGS = clippyFlags;
2022-08-04 10:53:05 +03:00
2022-09-24 16:09:35 +03:00
# bash
shellHook = ''
export NIL_PATH="$(cargo metadata --format-version=1 | jq -r .target_directory)/debug/nil"
2023-02-26 01:30:07 +03:00
export COC_NIL_PATH="$(realpath ./editors/coc-nil)"
2022-09-24 16:09:35 +03:00
'';
};
2022-08-09 10:14:02 +03:00
devShells.default = devShells.without-rust.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs ++ [
# Follows nixpkgs's version of rustc.
(let vers = lib.splitVersion pkgs.rustc.version; in
rustPkgs."rust_${lib.elemAt vers 0}_${lib.elemAt vers 1}_${lib.elemAt vers 2}".override {
extensions = [ "rust-src" ];
})
];
});
2023-02-14 18:48:32 +03:00
# See comments above.
devShells.full = devShells.default.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs ++ [
(pkgs.nixVersions.latest or pkgs.nixVersions.unstable).out
2023-02-14 18:48:32 +03:00
];
});
2022-09-24 16:09:35 +03:00
devShells.fuzz = pkgs.mkShell {
2024-05-30 19:15:55 +03:00
packages = with pkgs; [
rustPkgs."rust-nightly_${nightlyVersion}"
2022-09-24 16:09:35 +03:00
cargo-fuzz
llvmPackages_14.llvm
jq
gnugrep
];
RUST_BACKTRACE = "short";
2022-08-09 12:01:01 +03:00
2022-09-24 16:09:35 +03:00
# bash
shellHook = ''
export CARGO_TARGET_DIR=~/.cache/targets-syntax
'';
};
})
2023-02-26 01:30:07 +03:00
// {
2022-09-24 16:09:35 +03:00
overlays = {
2023-02-26 03:28:32 +03:00
default = lib.composeExtensions self.overlays.nil self.overlays.coc-nil;
2022-09-24 16:09:35 +03:00
nil = final: prev: {
nil = final.callPackage mkNil { };
2022-08-09 10:14:02 +03:00
};
2023-02-26 01:30:07 +03:00
coc-nil = final: prev: {
vimPlugins = prev.vimPlugins or { } // {
coc-nil = final.callPackage mkCocNil { };
};
};
2022-09-24 16:09:35 +03:00
};
};
2022-08-04 10:53:05 +03:00
}