diff --git a/default.nix b/default.nix index ab6e0babb..26eff4b52 100644 --- a/default.nix +++ b/default.nix @@ -8,7 +8,6 @@ meson, ninja, nix, - nixpkgs-fmt, pkg-config, nlohmann_json, python312, @@ -29,10 +28,7 @@ stdenv.mkDerivation { pkg-config ]; - nativeCheckInputs = [ - lit - nixpkgs-fmt - ]; + nativeCheckInputs = [ lit ]; buildInputs = [ nix diff --git a/flake.nix b/flake.nix index 2fcfe2020..66a478326 100644 --- a/flake.nix +++ b/flake.nix @@ -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; + }; } diff --git a/nixd/docs/configuration.md b/nixd/docs/configuration.md index 9def02e25..bfad71978 100644 --- a/nixd/docs/configuration.md +++ b/nixd/docs/configuration.md @@ -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 { }` @@ -94,7 +94,7 @@ nvim_lsp.nixd.setup({ expr = "import { }", }, formatting = { - command = { "nixpkgs-fmt" }, + command = { "nixfmt" }, }, options = { nixos = { @@ -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. diff --git a/nixd/docs/editors/nvim-lsp.nix b/nixd/docs/editors/nvim-lsp.nix index 2dac06c33..b2d0e2f57 100644 --- a/nixd/docs/editors/nvim-lsp.nix +++ b/nixd/docs/editors/nvim-lsp.nix @@ -1,4 +1,6 @@ -{ pkgs ? import { } }: +{ + pkgs ? import { }, +}: let neovim = pkgs.neovim.override { configure = { @@ -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 @@ -107,7 +107,7 @@ let globalstatus = true, }, }) - + ---------------------- -- About bufferline -- ---------------------- @@ -368,7 +368,7 @@ let expr = "import { }", }, formatting = { - command = { "nixpkgs-fmt" }, + command = { "nixfmt" }, }, options = { nixos = { @@ -401,33 +401,33 @@ 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 to jump back. keymap("n", "gh", "Lspsaga lsp_finder", { silent = true, desc = "Lsp finder" }) - + -- Code action keymap("n", "ca", "Lspsaga code_action", { silent = true, desc = "Code action" }) keymap("v", "ca", "Lspsaga code_action", { silent = true, desc = "Code action" }) - + -- Rename keymap("n", "gr", "Lspsaga rename", { silent = true, desc = "Rename" }) -- Rename word in whole project keymap("n", "gr", "Lspsaga rename ++project", { silent = true, desc = "Rename in project" }) - + -- Peek definition keymap("n", "gD", "Lspsaga peek_definition", { silent = true, desc = "Peek definition" }) - + -- Go to definition keymap("n", "gd", "Lspsaga goto_definition", { silent = true, desc = "Go to definition" }) - + -- Show line diagnostics keymap("n", "sl", "Lspsaga show_line_diagnostics", { silent = true, desc = "Show line diagnostics" }) - + -- Show cursor diagnostics keymap( "n", @@ -435,43 +435,42 @@ let "Lspsaga show_cursor_diagnostics", { silent = true, desc = "Show cursor diagnostic" } ) - + -- Show buffer diagnostics keymap("n", "sb", "Lspsaga show_buf_diagnostics", { silent = true, desc = "Show buffer diagnostic" }) - + -- Diagnostic jump prev keymap("n", "[e", "Lspsaga diagnostic_jump_prev", { silent = true, desc = "Diagnostic jump prev" }) - + -- Diagnostic jump next keymap("n", "]e", "Lspsaga diagnostic_jump_next", { 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", "Lspsaga outline", { silent = true, desc = "Toggle outline" }) - + -- Hover doc keymap("n", "K", "Lspsaga hover_doc ++keep", { silent = true, desc = "Hover doc" }) - + -- Incoming calls keymap("n", "ci", "Lspsaga incoming_calls", { silent = true, desc = "Incoming calls" }) - + -- Outgoing calls keymap("n", "co", "Lspsaga outgoing_calls", { silent = true, desc = "Outgoing calls" }) - + -- Float terminal keymap("n", "", "Lspsaga term_toggle", { silent = true, desc = "Float terminal" }) keymap("t", "", "Lspsaga term_toggle", { silent = true, desc = "Float terminal" }) ''; - in pkgs.runCommand "nvim-lsp" { } '' mkdir -p $out/bin diff --git a/nixd/docs/nixd-schema.json b/nixd/docs/nixd-schema.json index 9a3751d75..c1a91ffbf 100644 --- a/nixd/docs/nixd-schema.json +++ b/nixd/docs/nixd-schema.json @@ -43,7 +43,7 @@ "formatting": { "command": { "description": "Which command you would like to do formatting", - "default": "nixpkgs-fmt", + "default": "nixfmt", "type": "string" } }, diff --git a/nixd/include/nixd/Controller/Configuration.h b/nixd/include/nixd/Controller/Configuration.h index 48b8f5be4..36d5c653a 100644 --- a/nixd/include/nixd/Controller/Configuration.h +++ b/nixd/include/nixd/Controller/Configuration.h @@ -13,7 +13,7 @@ namespace nixd { // NOLINTBEGIN(readability-identifier-naming) struct Configuration { struct Formatting { - std::vector command = {"nixpkgs-fmt"}; + std::vector command = {"nixfmt"}; } formatting; struct OptionProvider { diff --git a/nixd/tools/nixd/test/format.md b/nixd/tools/nixd/test/format.md deleted file mode 100644 index 9c66183ca..000000000 --- a/nixd/tools/nixd/test/format.md +++ /dev/null @@ -1,62 +0,0 @@ -# RUN: nixd --lit-test < %s | FileCheck %s - -<-- initialize(0) - -```json -{ - "jsonrpc":"2.0", - "id":0, - "method":"initialize", - "params":{ - "processId":123, - "rootPath":"", - "capabilities":{ - }, - "trace":"off" - } -} -``` - -```json -{ - "jsonrpc":"2.0", - "method":"textDocument/didOpen", - "params":{ - "textDocument":{ - "uri":"file:///format.nix", - "languageId":"nix", - "version":1, - "text":"{ stdenv,\npkgs}: \n let x=1; in { y = x; }" - } - } -} -``` - -<-- textDocument/formatting - -```json -{ - "jsonrpc": "2.0", - "id": 2, - "method": "textDocument/formatting", - "params": { - "textDocument": { - "uri": "file:///format.nix" - }, - "options": { - "tabSize": 2, - "insertSpaces": true, - "trimTrailingWhitespace": true, - "insertFinalNewline": true - } - } -} -``` - -``` -CHECK: "newText": "{ stdenv\n, pkgs\n}:\nlet x = 1; in { y = x; }\n", -``` - -```json -{"jsonrpc":"2.0","method":"exit"} -``` diff --git a/treefmt.nix b/treefmt.nix index 00a70fc3f..945d7ff97 100644 --- a/treefmt.nix +++ b/treefmt.nix @@ -4,7 +4,7 @@ projectRootFile = "flake.nix"; programs = { clang-format.enable = true; - nixpkgs-fmt.enable = true; + nixfmt.enable = true; black.enable = true; }; }