diff --git a/flake.nix b/flake.nix index 144a267d4..902364d35 100644 --- a/flake.nix +++ b/flake.nix @@ -58,6 +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" + ''; + }; in { packages.default = nixd; @@ -72,49 +111,13 @@ devShells.default = nixdMono.overrideAttrs shellOverride; - 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.nvim = mkDevShell { + cmd = "nvim-lsp"; + editor = import ./nixd/docs/editors/nvim-lsp.nix { inherit pkgs; }; }; - devShells.vscodium = pkgs.mkShell { - nativeBuildInputs = [ - nixd - pkgs.nixfmt-rfc-style - (import ./nixd/docs/editors/vscodium.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..3f8f4d8f0 --- /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" + } + } + } + } +} 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" <