Giter VIP home page Giter VIP logo

Comments (5)

utybo avatar utybo commented on July 30, 2024 1

Here's an almost transparent workaround:

In .vscode/settings.json:

{
  "terminal.integrated.automationProfile.linux": {
    "path": "${workspaceRoot}/.vscode/nix-shell-or-bash.sh",
    "env": {
      "PROJ_DIR": "${workspaceRoot}"
    }
  }
}

Then, in .vscode/nix-shell-or-bash.sh (don't forget to chmod +x the file!)

#!/bin/sh
echo $PROJ_DIR
shift # ignore the initial -c added by VS Code

# The condition may be wrong because I'm not sure if Nix (!= NixOS) users have this file
if [ -e /run/current-system/sw/bin/nix-shell ]; then
    # A nix-shell is a available
    if [ -e "$PROJ_DIR/.envrc" ]; then
        # Use direnv (usually faster than nix-shell)
        direnv exec $PROJ_DIR $@
    else # TODO you could add an elif for a flake.nix file and launch nix develop instead
        # Use nix-shell
        nix-shell --run "$@"
    fi
else
    # For people not using NixOS
    bash -c "$@"
fi

from nix-env-selector.

arrterian avatar arrterian commented on July 30, 2024

Hi @bcardiff the extension doesn't affect tasks for now :(

from nix-env-selector.

leiflm avatar leiflm commented on July 30, 2024

What might be an entry point to solve this is the configuration option terminal.integrated.automationShell.linux. But nix-shell is not a POSIX compliant shell i.e. it does not handle -c well. Furthermore is it not possible to specify additional arguments to vscode to handle this. Obviously one can resort to a wrapper, that filters the -c switch and then set this wrapper as the automation shell.

In the meanwhile, the following tasks.json snippet works without this extension.
CAUTION: This snippets assumes, that the nix expression file is called either shell.nix or default.nix:

        {
            "label": "make",
            "type": "shell",
            "linux": {
                "options": {
                    "shell": {
                        "executable": "/run/current-system/sw/bin/nix-shell",
                        "args": [
                            "--run",
                        ],
                    },
                },
            },
            "command": "make",
        },

The VSCode Team seems to focus on terminal profiles. Once these are referencable within tasks, a corresponding task template could be provided by this extension.

from nix-env-selector.

samuela avatar samuela commented on July 30, 2024

This is a huge pain esp. when dealing with non-type: "shell" tasks. Eg for vscode extension development, the main launch command looks like:

    {
      "name": "Run Extension",
      "type": "extensionHost",
      "request": "launch",
      "args": ["--extensionDevelopmentPath=${workspaceFolder}"],
      "outFiles": ["${workspaceFolder}/out/**/*.js"],
      "preLaunchTask": "${defaultBuildTask}",
    },

from nix-env-selector.

utybo avatar utybo commented on July 30, 2024

Is there any new workaround for this since the referenced issue has been closed?

from nix-env-selector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.