From eed951a3d7e7e336c58fe3c8e3b5f9639bbb9c3c Mon Sep 17 00:00:00 2001 From: Star Dorminey Date: Sat, 29 Mar 2025 03:49:18 +0000 Subject: [PATCH 1/3] Fix vscodium shell to work like nvim shell. Unlike the nvim shell, the vscodium shell didn't specify any nixd server settings, so the example `flake.nix` didn't work. Fixed this by: - Pulling vscodium's user settings.json into a separate file, and filling it with the same contents as the config elaborated in nvim-lsp.nix. - Moved dev shell generation in the nixd repo's `flake.nix` to a common `mkDevShell` function for both nvim and vscodium (since the `settings.json` is sepecific to the hardcoded `/tmp/NixOS_Home-Manager` path.) Ideally we'd read the nixd server settings from the same file for both nvim and vscodium, but I don't know Lua so I didn't want to touch it. --- .gitignore | 1 + flake.nix | 69 +++++++++++++------------- nixd/docs/editors/vscode-settings.json | 28 +++++++++++ nixd/docs/editors/vscodium.nix | 8 +-- 4 files changed, 65 insertions(+), 41 deletions(-) create mode 100644 nixd/docs/editors/vscode-settings.json diff --git a/.gitignore b/.gitignore index e39d0cf46..1e1884719 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ __pycache__ result result-* +.cache diff --git a/flake.nix b/flake.nix index 144a267d4..2546c523a 100644 --- a/flake.nix +++ b/flake.nix @@ -58,63 +58,64 @@ 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.default = nixdMono.overrideAttrs shellOverride; - - devShells.nvim = pkgs.mkShell { + mkDevShell = {cmd, editor}: pkgs.mkShell { nativeBuildInputs = [ nixd pkgs.nixfmt-rfc-style pkgs.git - (import ./nixd/docs/editors/nvim-lsp.nix { inherit pkgs; }) + editor ]; 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" + echo -e "\033[1;34mEntering the 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 + 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 + 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;33m'${cmd} 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; }) - ]; + in + { + packages.default = nixd; + overlayAttrs = { + inherit (config.packages) nixd; + }; + packages = { + inherit nixd nixf nixt; + }; + + devShells.llvm = nixdLLVM.overrideAttrs shellOverride; + + devShells.default = nixdMono.overrideAttrs shellOverride; + + devShells.nvim = mkDevShell { + cmd = "nvim-lsp"; + editor = import ./nixd/docs/editors/nvim-lsp.nix { inherit pkgs; }; + }; + devShells.vscodium = mkDevShell { + cmd = "codium-test"; + editor = import ./nixd/docs/editors/vscodium.nix { inherit pkgs; }; }; formatter = treefmtEval.config.build.wrapper; }; diff --git a/nixd/docs/editors/vscode-settings.json b/nixd/docs/editors/vscode-settings.json new file mode 100644 index 000000000..e65301f36 --- /dev/null +++ b/nixd/docs/editors/vscode-settings.json @@ -0,0 +1,28 @@ +{ + "security.workspace.trust.enabled": false, + "nix.enableLanguageServer": true, + "nix.serverPath": "nixd", + "nix.serverSettings": { + "nixd": { + "nixpkgs": { + "expr": "import { }" + }, + "formatting": { + "command": [ + "nixfmt" + ] + }, + "options": { + "nixos": { + "expr": "(builtins.getFlake \"/tmp/NixOS_Home-Manager\").nixosConfigurations.hostname.options" + }, + "home-manager": { + "expr": "(builtins.getFlake \"/tmp/NixOS_Home-Manager\").homeConfigurations.\"user@hostname\".options" + }, + "flake-parts": { + "expr": "let flake = builtins.getFlake (\"/tmp/NixOS_Home-Manager\"); in flake.debug.options // flake.currentSystem.options" + } + } + } + } +} \ No newline at end of file diff --git a/nixd/docs/editors/vscodium.nix b/nixd/docs/editors/vscodium.nix index 359ad53f1..72e238dc9 100644 --- a/nixd/docs/editors/vscodium.nix +++ b/nixd/docs/editors/vscodium.nix @@ -14,12 +14,6 @@ writeShellScriptBin "codium-test" '' set -e dir="''${XDG_CACHE_HOME:-~/.cache}/nixd-codium" ${coreutils}/bin/mkdir -p "$dir/User" - cat >"$dir/User/settings.json" < Date: Sat, 29 Mar 2025 04:03:44 +0000 Subject: [PATCH 2/3] Oops, format. --- flake.nix | 76 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/flake.nix b/flake.nix index 2546c523a..902364d35 100644 --- a/flake.nix +++ b/flake.nix @@ -58,43 +58,45 @@ hardeningDisable = [ "fortify" ]; }; treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix; - mkDevShell = {cmd, editor}: pkgs.mkShell { - nativeBuildInputs = [ - nixd - pkgs.nixfmt-rfc-style - pkgs.git - editor - ]; - 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 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'${cmd} flake.nix'\033[0m" - echo -e "\033[1;34mEnvironment setup complete.\033[0m" - ''; - }; + mkDevShell = + { cmd, editor }: + pkgs.mkShell { + nativeBuildInputs = [ + nixd + pkgs.nixfmt-rfc-style + pkgs.git + editor + ]; + 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 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'${cmd} flake.nix'\033[0m" + echo -e "\033[1;34mEnvironment setup complete.\033[0m" + ''; + }; in { packages.default = nixd; From 439243097276f85b0370d7becfec07f2f82d57e1 Mon Sep 17 00:00:00 2001 From: Star Dorminey Date: Tue, 8 Apr 2025 02:10:14 +0000 Subject: [PATCH 3/3] Minor tweaks for PR. --- .gitignore | 1 - nixd/docs/editors/vscode-settings.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 1e1884719..e39d0cf46 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,3 @@ __pycache__ result result-* -.cache diff --git a/nixd/docs/editors/vscode-settings.json b/nixd/docs/editors/vscode-settings.json index e65301f36..3f8f4d8f0 100644 --- a/nixd/docs/editors/vscode-settings.json +++ b/nixd/docs/editors/vscode-settings.json @@ -25,4 +25,4 @@ } } } -} \ No newline at end of file +}