Nixpkgs: Add Visual Studio Code editor

Created on 1 Apr 2016  Â·  19Comments  Â·  Source: NixOS/nixpkgs

That's a code editor, developed by Microsoft.
There's already syntax highlighting for nix in vscode, but the vscode package itself is missing.

I got it working, but there are multiple alternatives how to package it:

  • download the binary directly, patchelf it, license = MS's unfree license
  • download the sources, compile them, during which the binary dependency electron is downloaded by their install script, patchelf the electron dependency, license = MIT
  • download the sources, compile them, adapt their install script to use electron from the nixpkgs repository (which is compiled itself, need to change the nixpkgs electron expression to do patchelf instead of wrapProgram with LD_LIBRARY_PATH), license = MIT
    Problem: vscode requires specific electron version - have a separate electron-vscode expression for that?

Wrapping electron with LD_LIBRARY_PATH env var is not possible, since vscode and electron modify the user environment (see https://github.com/Microsoft/vscode/issues/1033).
For licensing terms, see license explanation.
One (major) drawback of the FOSS version is that the extension manager is missing, which lets you conveniently install additional plugins. However, it can be easily enabled, by modifying a configuration file. Seems like that is allowed for the FOSS version.

Which alternative to choose? Is there another?

Patchelf looks something like this:

patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) --set-rpath /nix/store/<hash>-env-atom/lib64:/nix/store/<hash>-env-atom/lib:/run/opengl-driver/lib:/run/opengl-driver-32/lib:/path/to/root/of/binary /path/to/root/of/binary/code

For atom-env, refer to electron's nix expression.

package (new)

Most helpful comment

Thanks to combined effort (#14891), vscode-1.0.0 should work now.
Assuming you have a nixpkgs channel setup which tracks the nixpkgs-unstable channel, and you have { allowUnfree = true; } inside your .nixpkgs/config.nix, you can install it via nix-env -iA nixpkgs.vscode.

All 19 comments

In general, building everything from source is preferred.

But, good luck with that ;)

On Fri, Apr 1, 2016, 7:20 AM VladimĂ­r ÄŚunát [email protected]
wrote:

In general, building everything from source is preferred.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
https://github.com/NixOS/nixpkgs/issues/14354#issuecomment-204253041

I'm :-1: on building from source on this one. The extension gallery only works with the unfree version, and without it, the editor is just a glorified notepad.

Ah sorry for the misunderstanding, the (vital) extension manager can be enabled by adding merely 3 lines to a configuration file (I've somehow skipped that while skimming over the linked issue). Building everything from source is indeed the best option here.

Amazing how some people can't just answer a simple yes/no question. Thank you very much for clarifying, and for packaging!

Oh noes! The hydra build for vscode is complaining while trying to download external dependencies with npm:

npm ERR! fetch failed https://registry.npmjs.org/...

I fear that this is by design and that a clean nix derivation may not access external resources, except for what has been defined as inputs (expression parameters + src files).

How should this be solved?
The node dependencies are shrinkwraped, that means the exact versions are specified for each (sub)dependency, which should produce a deterministic build. Is there some way to have npm install those dependency and let nix enumerate and hash the whole node_modules folder as a src dependency?
If there is no workaround, it will have to be repackaged as a binary :(

Thanks to combined effort (#14891), vscode-1.0.0 should work now.
Assuming you have a nixpkgs channel setup which tracks the nixpkgs-unstable channel, and you have { allowUnfree = true; } inside your .nixpkgs/config.nix, you can install it via nix-env -iA nixpkgs.vscode.

What worked for me was:

  • manually creating folder/file ~/.config/nixpkgs/config.nix and adding { allowUnfree = true; } to it
  • ~/.nix-channels needs to have channel https://nixos.org/channels/nixos-unstable nixos to get latest version of VS Code
  • run nix-channel --update after modifying the ~/.nix-channels file
  • running nix-env -f '<nixpkgs>' -iA vscode to install it
  • change KDE command line to code --user-data-dir=~/.config/Code/

Thanks to the helpful people in Freenode #nixos: rycee, Fare, sphalerite

Is vscode no longer in nixpkgs? (Well, I get it in unstable but I don't see it at https://nixos.org/nixos/packages.html.)

@sid-kap I installed it yesterday latest version using nix-env -i vscode-1.19.2
But for some reason it does not appear listed on the website search.

It's marked as unfree, and therefore hidden by default.

I discovered that vs code was available on nix from this thread. If it's hidden on the website search, how should I have discovered it?

nix search

It all needs to be searchable from the website. The website is the natural way to search and list packages, and is the de-facto standard.

De-facto standard
If a programming language has a package manager, it is the de-facto standard to put it online. So, too, must OSes with package managers but no App store. It is an industry-wide expectation.

The terminal is an inappropriate place to browse packages.
Use of substring and fuzzy search are not appropriate, if such a project has many plugins with its root-name in it, for example, "gnome". Search for a "gnome" package; if there was a package called "gnome" you would never find it among all the similar names. (assuming it doesn't get sorted at the top).

vscode is not listed there because it is unfree. NixOS by default is a free software distribution.

vscode is not listed there because it is unfree. NixOS by default is a free software distribution.

(there are two ways your comment could be interpreted. I'm assuming the more controversial one, since it's 50/50)

You need to attract people to the OS. People use non-free software. Free/non-free is for the end-user to decide, not to be enforced by the distro. You're creating a very bad relationship between the distro and the end user. You live in a world full of non-free software. If you want to get rid of it, you must provide a better experience than the non-free software, and if you fail to do so, you must embrace each user's right to choose non-free software. It is not the distro's right to tell users what they can or cannot run on their system, or pose an unreasonable obstruction to those who wish to run non-free software (such as removing non-free software from search results). The free software community complains that Apple and Microsoft do this. The fact that they do the same is hypocritical.

I came across this issue in a web search for “nixpkgs vscode unfree” in the hope to find clarification. The licensing issue is now clear to me: Microsoft offers only an unfree build of their otherwise free code. To help future visitors I post this here, since it’s what Startpage/DDG point to.

It appears the _vscodium_ package in Nixpkgs outputs a free build of VS Code, under the MIT license. There are some differences in the final product but those are only cosmetic, removal of telemetry, and the name of the executable. It also seems to be entirely up-to-date with the unfree version.

It would be nice if this somehow showed up if you searched for “vscode” in the packages page. Of course it doesn’t now, since “vscode” is not a substring of “vscodium”.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

teto picture teto  Â·  3Comments

edolstra picture edolstra  Â·  3Comments

rzetterberg picture rzetterberg  Â·  3Comments

retrry picture retrry  Â·  3Comments

matthiasbeyer picture matthiasbeyer  Â·  3Comments