Skip to content

Fix vscodium shell to work like nvim shell. #665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
87 changes: 45 additions & 42 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
};
Expand Down
28 changes: 28 additions & 0 deletions nixd/docs/editors/vscode-settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"security.workspace.trust.enabled": false,
"nix.enableLanguageServer": true,
"nix.serverPath": "nixd",
"nix.serverSettings": {
"nixd": {
"nixpkgs": {
"expr": "import <nixpkgs> { }"
},
"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"
}
}
}
}
}
8 changes: 1 addition & 7 deletions nixd/docs/editors/vscodium.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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" <<EOF
{
"security.workspace.trust.enabled": false,
"nix.enableLanguageServer": true,
"nix.serverPath": "nixd",
}
EOF
cp ${./vscode-settings.json} "$dir/User/settings.json"
${codium}/bin/codium --user-data-dir "$dir" "$@"
''