Skip to content
Merged
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
6 changes: 1 addition & 5 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
meson,
ninja,
nix,
nixpkgs-fmt,
pkg-config,
nlohmann_json,
python312,
Expand All @@ -29,10 +28,7 @@ stdenv.mkDerivation {
pkg-config
];

nativeCheckInputs = [
lit
nixpkgs-fmt
];
nativeCheckInputs = [ lit ];

buildInputs = [
nix
Expand Down
201 changes: 104 additions & 97 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,105 +12,112 @@
};
};

outputs = { nixpkgs, flake-parts, treefmt-nix, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.flake-parts.flakeModules.easyOverlay
inputs.flake-root.flakeModule
];
perSystem = { config, pkgs, ... }:
let
inherit (pkgs) nixVersions llvmPackages_16 callPackage stdenv;
nix = nixVersions.nix_2_19;
llvmPackages = llvmPackages_16;
nixf = callPackage ./libnixf { };
nixt = callPackage ./libnixt {
inherit nix;
};
nixd = callPackage ./nixd {
inherit nix nixf nixt;
inherit llvmPackages;
};
nixdMono = callPackage ./. {
inherit nix llvmPackages;
};
nixdLLVM = nixdMono.override {
stdenv = if stdenv.isDarwin then stdenv else llvmPackages.stdenv;
};
regressionDeps = with pkgs; [
clang-tools
nixpkgs-fmt
lit
];
shellOverride = old: {
nativeBuildInputs = old.nativeBuildInputs ++ regressionDeps;
shellHook = ''
export PATH="${pkgs.clang-tools}/bin:$PATH"
export NIX_SRC=${nix.src}
export NIX_PATH=nixpkgs=${nixpkgs}
'';
hardeningDisable = [ "fortify" ];
};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
{
packages.default = nixd;
overlayAttrs = {
inherit (config.packages) nixd;
};
packages = { inherit nixd nixf nixt; };
outputs =
{
nixpkgs,
flake-parts,
treefmt-nix,
...
}@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.flake-parts.flakeModules.easyOverlay
inputs.flake-root.flakeModule
];
perSystem =
{ config, pkgs, ... }:
let
inherit (pkgs)
nixVersions
llvmPackages_16
callPackage
stdenv
;
nix = nixVersions.nix_2_19;
llvmPackages = llvmPackages_16;
nixf = callPackage ./libnixf { };
nixt = callPackage ./libnixt { inherit nix; };
nixd = callPackage ./nixd {
inherit nix nixf nixt;
inherit llvmPackages;
};
nixdMono = callPackage ./. { inherit nix llvmPackages; };
nixdLLVM = nixdMono.override { stdenv = if stdenv.isDarwin then stdenv else llvmPackages.stdenv; };
regressionDeps = with pkgs; [
clang-tools
lit
nixfmt-rfc-style
];
shellOverride = old: {
nativeBuildInputs = old.nativeBuildInputs ++ regressionDeps;
shellHook = ''
export PATH="${pkgs.clang-tools}/bin:$PATH"
export NIX_SRC=${nix.src}
export NIX_PATH=nixpkgs=${nixpkgs}
'';
hardeningDisable = [ "fortify" ];
};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
{
packages.default = nixd;
overlayAttrs = {
inherit (config.packages) nixd;
};
packages = {
inherit nixd nixf nixt;
};

devShells.llvm = nixdLLVM.overrideAttrs shellOverride;
devShells.llvm = nixdLLVM.overrideAttrs shellOverride;

devShells.default = nixdMono.overrideAttrs shellOverride;
devShells.default = nixdMono.overrideAttrs shellOverride;

devShells.nvim = pkgs.mkShell {
nativeBuildInputs = [
nixd
pkgs.nixpkgs-fmt
pkgs.git
(import ./nixd/docs/editors/nvim-lsp.nix { inherit pkgs; })
];
inputsFrom = [
config.flake-root.devShell
];
shellHook = ''
echo -e "\n\033[1;31mDuring the first time nixd launches, the flake inputs will be fetched from the internet, this is rather slow.\033[0m"
echo -e "\033[1;34mEntering the nvim test environment...\033[0m"
cd $FLAKE_ROOT
export GIT_REPO=https://github.com/nix-community/nixd.git
export EXAMPLES_PATH=nixd/docs/examples
export WORK_TEMP=/tmp/NixOS_Home-Manager
if [ -d "$WORK_TEMP" ]; then
rm -rf $WORK_TEMP
fi
mkdir -p $WORK_TEMP
cp -r $EXAMPLES_PATH/NixOS_Home-Manager/* $WORK_TEMP/ 2>/dev/null
if [[ $? -ne 0 ]]; then
export GIT_DIR=$WORK_TEMP/.git
export GIT_WORK_TREE=/tmp/NixOS_Home-Manager
git init
git config core.sparseCheckout true
git remote add origin $GIT_REPO
echo "$EXAMPLES_PATH/NixOS_Home-Manager/" >$GIT_DIR/info/sparse-checkout
git pull origin main
cp $GIT_WORK_TREE\/$EXAMPLES_PATH/NixOS_Home-Manager/* $GIT_WORK_TREE 2>/dev/null
rm -rf $GIT_WORK_TREE/nixd
fi
cd $WORK_TEMP
echo -e "\033[1;32mNow, you can edit the nix file by running the following command:\033[0m"
echo -e "\033[1;33m'nvim-lsp flake.nix'\033[0m"
echo -e "\033[1;34mEnvironment setup complete.\033[0m"
'';
};
devShells.vscodium = pkgs.mkShell {
nativeBuildInputs = [
nixd
pkgs.nixpkgs-fmt
(import ./nixd/docs/editors/vscodium.nix { inherit pkgs; })
];
devShells.nvim = pkgs.mkShell {
nativeBuildInputs = [
nixd
pkgs.nixfmt-rfc-style
pkgs.git
(import ./nixd/docs/editors/nvim-lsp.nix { inherit pkgs; })
];
inputsFrom = [ config.flake-root.devShell ];
shellHook = ''
echo -e "\n\033[1;31mDuring the first time nixd launches, the flake inputs will be fetched from the internet, this is rather slow.\033[0m"
echo -e "\033[1;34mEntering the nvim test environment...\033[0m"
cd $FLAKE_ROOT
export GIT_REPO=https://github.com/nix-community/nixd.git
export EXAMPLES_PATH=nixd/docs/examples
export WORK_TEMP=/tmp/NixOS_Home-Manager
if [ -d "$WORK_TEMP" ]; then
rm -rf $WORK_TEMP
fi
mkdir -p $WORK_TEMP
cp -r $EXAMPLES_PATH/NixOS_Home-Manager/* $WORK_TEMP/ 2>/dev/null
if [[ $? -ne 0 ]]; then
export GIT_DIR=$WORK_TEMP/.git
export GIT_WORK_TREE=/tmp/NixOS_Home-Manager
git init
git config core.sparseCheckout true
git remote add origin $GIT_REPO
echo "$EXAMPLES_PATH/NixOS_Home-Manager/" >$GIT_DIR/info/sparse-checkout
git pull origin main
cp $GIT_WORK_TREE\/$EXAMPLES_PATH/NixOS_Home-Manager/* $GIT_WORK_TREE 2>/dev/null
rm -rf $GIT_WORK_TREE/nixd
fi
cd $WORK_TEMP
echo -e "\033[1;32mNow, you can edit the nix file by running the following command:\033[0m"
echo -e "\033[1;33m'nvim-lsp flake.nix'\033[0m"
echo -e "\033[1;34mEnvironment setup complete.\033[0m"
'';
};
devShells.vscodium = pkgs.mkShell {
nativeBuildInputs = [
nixd
pkgs.nixfmt-rfc-style
(import ./nixd/docs/editors/vscodium.nix { inherit pkgs; })
];
};
formatter = treefmtEval.config.build.wrapper;
};
formatter = treefmtEval.config.build.wrapper;
};
systems = nixpkgs.lib.systems.flakeExposed;
};
systems = nixpkgs.lib.systems.flakeExposed;
};
}
6 changes: 3 additions & 3 deletions nixd/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ For vscode users you should write `settings.json`[^settings] like this:
"nixd": {
"formatting": {
// This is the default if ommited.
"command": [ "nixpkgs-fmt" ]
"command": [ "nixfmt" ]
},
"options": {
// By default, this entriy will be read from `import <nixpkgs> { }`
Expand Down Expand Up @@ -94,7 +94,7 @@ nvim_lsp.nixd.setup({
expr = "import <nixpkgs> { }",
},
formatting = {
command = { "nixpkgs-fmt" },
command = { "nixfmt" },
},
options = {
nixos = {
Expand Down Expand Up @@ -130,7 +130,7 @@ nvim_lsp.nixd.setup({
},
"formatting": {
// Which command you would like to do formatting
"command": [ "nixpkgs-fmt" ]
"command": [ "nixfmt" ]
},
// Tell the language server your desired option set, for completion
// This is lazily evaluated.
Expand Down
49 changes: 24 additions & 25 deletions nixd/docs/editors/nvim-lsp.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{ pkgs ? import <nixpkgs> { } }:
{
pkgs ? import <nixpkgs> { },
}:
let
neovim = pkgs.neovim.override {
configure = {
Expand All @@ -9,9 +11,7 @@ let
'';

packages.myPlugins.start = with pkgs.vimPlugins; [
(nvim-treesitter.withPlugins (parsers: [
parsers.nix
]))
(nvim-treesitter.withPlugins (parsers: [ parsers.nix ]))
friendly-snippets
luasnip
nvim-cmp
Expand Down Expand Up @@ -107,7 +107,7 @@ let
globalstatus = true,
},
})
----------------------
-- About bufferline --
----------------------
Expand Down Expand Up @@ -368,7 +368,7 @@ let
expr = "import <nixpkgs> { }",
},
formatting = {
command = { "nixpkgs-fmt" },
command = { "nixfmt" },
},
options = {
nixos = {
Expand Down Expand Up @@ -401,77 +401,76 @@ let
},
})
vim.cmd([[ colorscheme nord ]])
local keymap = vim.keymap.set
-- Lsp finder
-- Find the symbol definition, implementation, reference.
-- If there is no implementation, it will hide.
-- When you use action in finder like open, vsplit, then you can use <C-t> to jump back.
keymap("n", "gh", "<cmd>Lspsaga lsp_finder<CR>", { silent = true, desc = "Lsp finder" })
-- Code action
keymap("n", "<leader>ca", "<cmd>Lspsaga code_action<CR>", { silent = true, desc = "Code action" })
keymap("v", "<leader>ca", "<cmd>Lspsaga code_action<CR>", { silent = true, desc = "Code action" })
-- Rename
keymap("n", "gr", "<cmd>Lspsaga rename<CR>", { silent = true, desc = "Rename" })
-- Rename word in whole project
keymap("n", "gr", "<cmd>Lspsaga rename ++project<CR>", { silent = true, desc = "Rename in project" })
-- Peek definition
keymap("n", "gD", "<cmd>Lspsaga peek_definition<CR>", { silent = true, desc = "Peek definition" })
-- Go to definition
keymap("n", "gd", "<cmd>Lspsaga goto_definition<CR>", { silent = true, desc = "Go to definition" })
-- Show line diagnostics
keymap("n", "<leader>sl", "<cmd>Lspsaga show_line_diagnostics<CR>", { silent = true, desc = "Show line diagnostics" })
-- Show cursor diagnostics
keymap(
"n",
"<leader>sc",
"<cmd>Lspsaga show_cursor_diagnostics<CR>",
{ silent = true, desc = "Show cursor diagnostic" }
)
-- Show buffer diagnostics
keymap("n", "<leader>sb", "<cmd>Lspsaga show_buf_diagnostics<CR>", { silent = true, desc = "Show buffer diagnostic" })
-- Diagnostic jump prev
keymap("n", "[e", "<cmd>Lspsaga diagnostic_jump_prev<CR>", { silent = true, desc = "Diagnostic jump prev" })
-- Diagnostic jump next
keymap("n", "]e", "<cmd>Lspsaga diagnostic_jump_next<CR>", { silent = true, desc = "Diagnostic jump next" })
-- Goto prev error
keymap("n", "[E", function()
require("lspsaga.diagnostic"):goto_prev({ severity = vim.diagnostic.severity.ERROR })
end, { silent = true, desc = "Goto prev error" })
-- Goto next error
keymap("n", "]E", function()
require("lspsaga.diagnostic"):goto_next({ severity = vim.diagnostic.severity.ERROR })
end, { silent = true, desc = "Goto next error" })
-- Toggle outline
keymap("n", "ss", "<cmd>Lspsaga outline<CR>", { silent = true, desc = "Toggle outline" })
-- Hover doc
keymap("n", "K", "<cmd>Lspsaga hover_doc ++keep<CR>", { silent = true, desc = "Hover doc" })
-- Incoming calls
keymap("n", "<Leader>ci", "<cmd>Lspsaga incoming_calls<CR>", { silent = true, desc = "Incoming calls" })
-- Outgoing calls
keymap("n", "<Leader>co", "<cmd>Lspsaga outgoing_calls<CR>", { silent = true, desc = "Outgoing calls" })
-- Float terminal
keymap("n", "<A-d>", "<cmd>Lspsaga term_toggle<CR>", { silent = true, desc = "Float terminal" })
keymap("t", "<A-d>", "<cmd>Lspsaga term_toggle<CR>", { silent = true, desc = "Float terminal" })
'';

in
pkgs.runCommand "nvim-lsp" { } ''
mkdir -p $out/bin
Expand Down
2 changes: 1 addition & 1 deletion nixd/docs/nixd-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"formatting": {
"command": {
"description": "Which command you would like to do formatting",
"default": "nixpkgs-fmt",
"default": "nixfmt",
"type": "string"
}
},
Expand Down
Loading