Skip to content
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

feat: open terminal links for store paths in workspace #275

Closed
wants to merge 1 commit into from
Closed

feat: open terminal links for store paths in workspace #275

wants to merge 1 commit into from

Conversation

hall
Copy link
Collaborator

@hall hall commented Sep 9, 2022

These changes register a terminal link handler so that store paths can be handled as files relative to the workspace (if they exist in the workspace).

As it stands, this assumes the store is at /nix/store and that all paths are unix-style (which should cover most (all?) users but I can try to abstract those away if necessary).

fixes #272

dzmitry-lahoda
dzmitry-lahoda previously approved these changes Sep 9, 2022
@dzmitry-lahoda
Copy link

Done in 25.99s.
dz@dz-pc-11:~/github.com/nix-community/vscode-nix-ide$ vsce package 
 INFO  Detected presence of yarn.lock. Using 'yarn' instead of 'npm' (to override this pass '--no-yarn' on the command line).
 ERROR  Extension entrypoint(s) missing. Make sure these files exist and aren't ignored by '.vscodeignore':
  extension/dist/extension.js

no sure how to test, but seems like good solution

@hall
Copy link
Collaborator Author

hall commented Sep 9, 2022

no sure how to test

I generally just press F5 with the repo open in VSCode. Then you can open files to test functionality in the newly-created window. No worries if you're not able to though; I'll try to do some more rigorous testing over the weekend

src/extension.ts Outdated
@@ -5,6 +5,12 @@ import { startLinting } from "./linter";
import { config } from "./configuration";
import * as client from "./client";

const storeRegex = /\/nix\/store\/.{32}-[^/]*\/([^:]*)/g;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this store-path a configurable value?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may there is already nix env variable or nix conf file having the path? so when you run nix you run from that path and may be extensions can access it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's NIX_STORE_DIR; we could check that and then fallback to /nix/store.

@hall
Copy link
Collaborator Author

hall commented Sep 10, 2022

Marking as draft b/c I haven't done any semi-serious testing yet.

@hall
Copy link
Collaborator Author

hall commented Sep 10, 2022

Yep, need a better determinator than "file exists in workspace" because, of course, there's going to be similarly-named files across unrelated derivatives; for example, this flake

{
  outputs = { self, nixpkgs, ... }@inputs:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in
    {
      packages.${system}.default = pkgs.callPackage pkgs.hello { };
    };
}

throws the following error:

❯ nix eval .
error: getting status of '/nix/store/y4mxrg8c6l09lb2szl69vwl4f6441i5k-hello-2.12.1/default.nix': No such file or directory

which would open default.nix, if it existed, in the workspace (which is a completely unrelated file).

My first thought is that the local derivation is always called source (e.g., /nix/store/pa6a7a5b2iqvi5ra7z0vxr6mn343gw53-source) as that's what I've observed in passing; however, that's not the case in @dzmitry-lahoda's screenshot. So I think we need a way to determine the actual derivation path(s); hopefully there's a command which does exactly that.

@dzmitry-lahoda
Copy link

in rust, rust analyzer expands procedural macros and builds rs scripts. just to name something which doing ide level evaluation and expansion.

nix is lazy and side effect free. so it can be evaluated, including each src. actually flake check and nix show doing something like that.

so the only final fix is to evaluate whole tree. dump it to json. and use as virtual file tree.

will donate 10 DOT for such solution.

but can with current only root solution is ok if to provide not nix store config, but config for current root src. i can just make my root src to be in subfolder i need. so for most people in simple projects it will work without modification.

choose src or file from multiple on click does not feel good to go.

so current solution with env var for store location and per workspace src configuration can be great.

@dzmitry-lahoda
Copy link

default.nix, if it existed, in the workspace (which is a completely unrelated file).

oh. that is bad. ruins everything. so it needs evaluation of nix tree and deep integration with nix sql database.

afaik nix is lazy strict dynamics. but when its is evaluated it is not so dynamic.

so really this feature requires a step to real ide - building tree and linking it to "object" database.

@dzmitry-lahoda
Copy link

dz@dz-pc-11:~/github.com/ComposableFi/cosmoverse-demo$ nix show-derivation .#frontend-static
warning: Git tree '/home/dz/github.com/ComposableFi/cosmoverse-demo' is dirty
{
  "/nix/store/0l1hkkc1xa62p2zg3rd6c39dnmaznq4l-xcvm-dashboard-0.1.0.drv": {
    "outputs": {
      "out": {
        "path": "/nix/store/r0q82x2jq91yb6v61cnml5b9xfsxv7c2-xcvm-dashboard-0.1.0"
      }
    },
    "inputSrcs": [
      "/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh",
      "/nix/store/rzznbiy8j0381jlsk3la1njz5ql1na1q-frontend",
      "/nix/store/szyc8a0wsc42p6md02psn4i2smmw2z23-mkyarncache.js"
    ],
    "inputDrvs": {

flake package, app does not work (we need app because we debug). but at least we see src /nix/store/rzznbiy8j0381jlsk3la1njz5ql1na1q-frontend

@dzmitry-lahoda
Copy link

dz@dz-pc-11:~/github.com/ComposableFi/cosmoverse-demo$ ls /nix/store/rzznbiy8j0381jlsk3la1njz5ql1na1q-frontend -la
total 4884
dr-xr-xr-x   11 dz dz    4096 Jan  1  1970 .
drwxrwxr-x 2438 dz dz 4714496 Sep 10 17:14 ..
-r--r--r--    1 dz dz      29 Jan  1  1970 .eslintignore
-r--r--r--    1 dz dz    3160 Jan  1  1970 .eslintrc.json
-r--r--r--    1 dz dz      57 Jan  1  1970 .firebaserc
dr-xr-xr-x    3 dz dz    4096 Jan  1  1970 .husky
-r--r--r--    1 dz dz       8 Jan  1  1970 .nvmrc
-r--r--r--    1 dz dz      25 Jan  1  1970 .prettierignore
-r--r--r--    1 dz dz     390 Jan  1  1970 .prettierrc
-r--r--r--    1 dz dz    1181 Jan  1  1970 README.md
dr-xr-xr-x    6 dz dz    4096 Jan  1  1970 components
dr-xr-xr-x    2 dz dz    4096 Jan  1  1970 constants
dr-xr-xr-x    3 dz dz    4096 Jan  1  1970 context
-r--r--r--    1 dz dz     101 Jan  1  1970 firebase.json
dr-xr-xr-x    2 dz dz    4096 Jan  1  1970 hooks
-r--r--r--    1 dz dz     274 Jan  1  1970 lint-staged.config.js
-r--r--r--    1 dz dz     201 Jan  1  1970 next-env.d.ts
-r--r--r--    1 dz dz     202 Jan  1  1970 next.config.js
-r--r--r--    1 dz dz    2258 Jan  1  1970 package.json
dr-xr-xr-x    4 dz dz    4096 Jan  1  1970 pages
-r--r--r--    1 dz dz      77 Jan  1  1970 postcss.config.js
dr-xr-xr-x    5 dz dz    4096 Jan  1  1970 public
dr-xr-xr-x    2 dz dz    4096 Jan  1  1970 styles
-r--r--r--    1 dz dz    1599 Jan  1  1970 tailwind.config.js
-r--r--r--    1 dz dz     855 Jan  1  1970 tsconfig.json
dr-xr-xr-x    2 dz dz    4096 Jan  1  1970 utils
-r--r--r--    1 dz dz  164482 Jan  1  1970 yarn.lock

so pretty sure it is there.

but need to find out how to dump apps (likely flake also makes derivation of these). and then dump the tree. and then ls each src from that tree. and doing from time to time in background on inotify.

@dzmitry-lahoda
Copy link

i guess hydra CI/CD can do it to build DAG for workflows.

@dzmitry-lahoda
Copy link

not found, tried to search nix issues - no relevant. so seems like having such tools is going as deep into nix.

@dzmitry-lahoda
Copy link

so the problem is. if you run nix in console. how would nix in plugin access the same nix as in console? so it will need nix env selector dependency of some kind. or rely on that user did nix shell/develop and then code - so it uses same nix.

@hall
Copy link
Collaborator Author

hall commented Sep 13, 2022

I'll have to dig more into that approach to understand it better; so long as it can work with both flake and non-flake project, it could work.

As far as matching nix version, the extension can just use whatever is in PATH, no? If the user is loading a custom nix version in their project environment, ideally they'd also load vscode into that environment as any extension which tried to call any executable would have the same problem.

Some alternative approaches that come to mind:

  • let the user explicitly open the file in the workspace (such as through a select dialog or the context menu if Ability to contribute context menu entries for Terminal microsoft/vscode#79034 gets implemented).
  • match the files by contents; that is, if the file in the workspace and the file in the store have the same contents, open the file in the workspace. There are probably edgecases here that I haven't considered yet but the biggest thorn is that the paths nix prints are not guaranteed to exist (so that likely rules this one out).

@jnoortheen
Copy link
Collaborator

I like showing the select dialog idea.

  1. There should be a config about intercepting the terminal links. This is enabled by default. The user can disable if one is annoyed with the behaviour
  2. As you have told, we can show the dialog, with options open in workspace or the filesystem path if the file path is matching in the workspace as well.

@dzmitry-lahoda
Copy link

On flake.nix can run this

nix flake check --no-build --keep-going --allow-import-from-derivation  --show-trace --no-update-lock-file --fallback --debug --print-build-logs --keep-failed --impure --option sandbox relaxed

Gives some output of all within flake.nix. Not sure if can built on this. May be ask nix flake dump similar to check from nix team?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Path click navigate to current sources
3 participants