How to install npm packages in NixOS?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite
3












In NixOS, I installed the package yarn as usual by running $ nix-env -i yarn. Now I am attempting to run yarn via $ yarn start. But this leads me to the following error.



$ yarn start
yarn start v0.20.3
$ webpack-dev-server --env dev
sh: webpack-dev-server: command not found
error Command failed with exit code 127.


When I try to install webpack-dev-server in my usual NixOS way I get a 'matches no derivations' error.



$ nix-env -i webpack-dev-server
error: selector ‘webpack-dev-server’ matches no derivations


I read that webpack-dev-server is an npm package, and am unsure of a couple questions regarding the relevance of that in this case.



  1. Does it make sense to use npm, a different package manager than nix,
    under Nix?

  2. If answer to (1) is yes, then how to install npm on NixOS? I do not
    see npm available when searching via nix-env, as $ nix-env -qa npm also matches no derivations.

What is the correct way to install webpack-dev-server on NixOS?




EDIT



I attempted to install webpack-dev-server following the commented link and was able to install node2nix, but am not able to follow through on step 2 listed in the readme there.



I located the file referenced in step 2 in /nix/store at



/nix/store/sgk7sxgqxrv2axkxjwc3y15apcqbrv1z-nixos-17.03.1482.1b57bf274a/nixos/pkgs/development/node-packages/node-packages.json


I can open that file to view the npm packages listed, but the permissions are read-only, even running with sudo -- so I would need to edit it's permissions in order to alter it.



It seems that I should not be editing this /nix/store file directly and should instead be manipulating it indirectly via nix. Am I correct that I should not be editing this file directly? If so, how else can I complete step 2 by using nix or something to add webpack-dev-server to it?










share|improve this question



















  • 1




    github.com/NixOS/nixpkgs/tree/master/pkgs/development/…
    – Emmanuel Rosa
    Jul 20 '17 at 23:37










  • @EmmanuelRosa thank you for the link; I attempted to follow the instructions there and updated this question according to the results of that attempt.
    – mherzl
    Jul 21 '17 at 3:33










  • /nix/store is read-only. You need to clone git repo and use -I nixpkgs=/path/to/repo for nix-* command
    – wizzup
    Jul 21 '17 at 4:21















up vote
6
down vote

favorite
3












In NixOS, I installed the package yarn as usual by running $ nix-env -i yarn. Now I am attempting to run yarn via $ yarn start. But this leads me to the following error.



$ yarn start
yarn start v0.20.3
$ webpack-dev-server --env dev
sh: webpack-dev-server: command not found
error Command failed with exit code 127.


When I try to install webpack-dev-server in my usual NixOS way I get a 'matches no derivations' error.



$ nix-env -i webpack-dev-server
error: selector ‘webpack-dev-server’ matches no derivations


I read that webpack-dev-server is an npm package, and am unsure of a couple questions regarding the relevance of that in this case.



  1. Does it make sense to use npm, a different package manager than nix,
    under Nix?

  2. If answer to (1) is yes, then how to install npm on NixOS? I do not
    see npm available when searching via nix-env, as $ nix-env -qa npm also matches no derivations.

What is the correct way to install webpack-dev-server on NixOS?




EDIT



I attempted to install webpack-dev-server following the commented link and was able to install node2nix, but am not able to follow through on step 2 listed in the readme there.



I located the file referenced in step 2 in /nix/store at



/nix/store/sgk7sxgqxrv2axkxjwc3y15apcqbrv1z-nixos-17.03.1482.1b57bf274a/nixos/pkgs/development/node-packages/node-packages.json


I can open that file to view the npm packages listed, but the permissions are read-only, even running with sudo -- so I would need to edit it's permissions in order to alter it.



It seems that I should not be editing this /nix/store file directly and should instead be manipulating it indirectly via nix. Am I correct that I should not be editing this file directly? If so, how else can I complete step 2 by using nix or something to add webpack-dev-server to it?










share|improve this question



















  • 1




    github.com/NixOS/nixpkgs/tree/master/pkgs/development/…
    – Emmanuel Rosa
    Jul 20 '17 at 23:37










  • @EmmanuelRosa thank you for the link; I attempted to follow the instructions there and updated this question according to the results of that attempt.
    – mherzl
    Jul 21 '17 at 3:33










  • /nix/store is read-only. You need to clone git repo and use -I nixpkgs=/path/to/repo for nix-* command
    – wizzup
    Jul 21 '17 at 4:21













up vote
6
down vote

favorite
3









up vote
6
down vote

favorite
3






3





In NixOS, I installed the package yarn as usual by running $ nix-env -i yarn. Now I am attempting to run yarn via $ yarn start. But this leads me to the following error.



$ yarn start
yarn start v0.20.3
$ webpack-dev-server --env dev
sh: webpack-dev-server: command not found
error Command failed with exit code 127.


When I try to install webpack-dev-server in my usual NixOS way I get a 'matches no derivations' error.



$ nix-env -i webpack-dev-server
error: selector ‘webpack-dev-server’ matches no derivations


I read that webpack-dev-server is an npm package, and am unsure of a couple questions regarding the relevance of that in this case.



  1. Does it make sense to use npm, a different package manager than nix,
    under Nix?

  2. If answer to (1) is yes, then how to install npm on NixOS? I do not
    see npm available when searching via nix-env, as $ nix-env -qa npm also matches no derivations.

What is the correct way to install webpack-dev-server on NixOS?




EDIT



I attempted to install webpack-dev-server following the commented link and was able to install node2nix, but am not able to follow through on step 2 listed in the readme there.



I located the file referenced in step 2 in /nix/store at



/nix/store/sgk7sxgqxrv2axkxjwc3y15apcqbrv1z-nixos-17.03.1482.1b57bf274a/nixos/pkgs/development/node-packages/node-packages.json


I can open that file to view the npm packages listed, but the permissions are read-only, even running with sudo -- so I would need to edit it's permissions in order to alter it.



It seems that I should not be editing this /nix/store file directly and should instead be manipulating it indirectly via nix. Am I correct that I should not be editing this file directly? If so, how else can I complete step 2 by using nix or something to add webpack-dev-server to it?










share|improve this question















In NixOS, I installed the package yarn as usual by running $ nix-env -i yarn. Now I am attempting to run yarn via $ yarn start. But this leads me to the following error.



$ yarn start
yarn start v0.20.3
$ webpack-dev-server --env dev
sh: webpack-dev-server: command not found
error Command failed with exit code 127.


When I try to install webpack-dev-server in my usual NixOS way I get a 'matches no derivations' error.



$ nix-env -i webpack-dev-server
error: selector ‘webpack-dev-server’ matches no derivations


I read that webpack-dev-server is an npm package, and am unsure of a couple questions regarding the relevance of that in this case.



  1. Does it make sense to use npm, a different package manager than nix,
    under Nix?

  2. If answer to (1) is yes, then how to install npm on NixOS? I do not
    see npm available when searching via nix-env, as $ nix-env -qa npm also matches no derivations.

What is the correct way to install webpack-dev-server on NixOS?




EDIT



I attempted to install webpack-dev-server following the commented link and was able to install node2nix, but am not able to follow through on step 2 listed in the readme there.



I located the file referenced in step 2 in /nix/store at



/nix/store/sgk7sxgqxrv2axkxjwc3y15apcqbrv1z-nixos-17.03.1482.1b57bf274a/nixos/pkgs/development/node-packages/node-packages.json


I can open that file to view the npm packages listed, but the permissions are read-only, even running with sudo -- so I would need to edit it's permissions in order to alter it.



It seems that I should not be editing this /nix/store file directly and should instead be manipulating it indirectly via nix. Am I correct that I should not be editing this file directly? If so, how else can I complete step 2 by using nix or something to add webpack-dev-server to it?







nixos npm






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 21 '17 at 3:37

























asked Jul 20 '17 at 22:19









mherzl

375318




375318







  • 1




    github.com/NixOS/nixpkgs/tree/master/pkgs/development/…
    – Emmanuel Rosa
    Jul 20 '17 at 23:37










  • @EmmanuelRosa thank you for the link; I attempted to follow the instructions there and updated this question according to the results of that attempt.
    – mherzl
    Jul 21 '17 at 3:33










  • /nix/store is read-only. You need to clone git repo and use -I nixpkgs=/path/to/repo for nix-* command
    – wizzup
    Jul 21 '17 at 4:21













  • 1




    github.com/NixOS/nixpkgs/tree/master/pkgs/development/…
    – Emmanuel Rosa
    Jul 20 '17 at 23:37










  • @EmmanuelRosa thank you for the link; I attempted to follow the instructions there and updated this question according to the results of that attempt.
    – mherzl
    Jul 21 '17 at 3:33










  • /nix/store is read-only. You need to clone git repo and use -I nixpkgs=/path/to/repo for nix-* command
    – wizzup
    Jul 21 '17 at 4:21








1




1




github.com/NixOS/nixpkgs/tree/master/pkgs/development/…
– Emmanuel Rosa
Jul 20 '17 at 23:37




github.com/NixOS/nixpkgs/tree/master/pkgs/development/…
– Emmanuel Rosa
Jul 20 '17 at 23:37












@EmmanuelRosa thank you for the link; I attempted to follow the instructions there and updated this question according to the results of that attempt.
– mherzl
Jul 21 '17 at 3:33




@EmmanuelRosa thank you for the link; I attempted to follow the instructions there and updated this question according to the results of that attempt.
– mherzl
Jul 21 '17 at 3:33












/nix/store is read-only. You need to clone git repo and use -I nixpkgs=/path/to/repo for nix-* command
– wizzup
Jul 21 '17 at 4:21





/nix/store is read-only. You need to clone git repo and use -I nixpkgs=/path/to/repo for nix-* command
– wizzup
Jul 21 '17 at 4:21











3 Answers
3






active

oldest

votes

















up vote
12
down vote













There are multiple ways to use npm packages through nix:



For my personal projects, I use nix-shell then within the shell I use npm scripts to prevent the need for npm global packages (like with gulp). The process looks something like this (and is probably very similar for yarn):



$ nix-shell -p nodejs-8_x
[nix-shell:yourproject]$ npm install # installs npm deps to project-local node_modules
[nix-shell:yourproject]$ npm exec (...) # using scripts configured in package.json


This works well for me since none of my packages have binary dependencies. This post describes the creation of a default.nix for your project so you won't have to specify dependencies for every invocation of nix-shell, but it's optional.



Another way is using npm2nix:



node2nix -i node-packages.json # creates ./default.nix
nix-shell # nix-shell will look for a default.nix, which above will have generated


Which will cause Nix to manage all npm packages in the project.



It may be a good idea to become familiar with nix-shell, since trying to install node packages / any dependency in your nix profile (through nix-env or nox) defeats the purpose of nix by polluting the "global" namespace.



Hope this helps!






share|improve this answer






















  • Could you expand on this with regards to packages using binding.gyp for example: github.com/mateogianolio/nblas
    – CMCDragonkai
    Dec 15 '17 at 7:36






  • 1




    I found out how to do it for binary packages. You need the nodePackages_6_x.node-gyp, and any other libraries like blas, then when it's all together, you can use npm install .... packages that use node-gyp.
    – CMCDragonkai
    Dec 15 '17 at 7:52






  • 1




    Regarding the first method, as an alternative to the npm scripts solution, I find adding global npm packages to the nix-shell effective, e.g. nix-shell -p nodejs-8_x nodePackages.grunt-cli. (Warning: nixos and node noob here.)
    – Ryne Everett
    Jan 28 at 18:29










  • The one thing I don't understand about the first method is how to actually install the package itself, i.e. where does the binary for the project's package.json bin end up?
    – Ryne Everett
    Jan 28 at 20:00










  • @ryne-everett If you run npm install, executables would be linked into node_modules/.bin. See here.
    – Luke Adams
    Feb 3 at 19:21


















up vote
5
down vote













For some reason I don't know, nodePackages is not in root namespace and can't be found by using nix-env -qa



use nix-env -qaPA 'nixos.nodePackages' to list for avaliable packages.



$ nix-env -qaPA 'nixos.nodePackages' | grep -i web
nixos.nodePackages.webdrvr node-webdrvr-2.43.0-1
nixos.nodePackages.webpack node-webpack-2.6.1


If there is no packages you want and you can't make your own, try request it on NixOS github.






share|improve this answer






















  • I am using just nix package manager and was able to make it work with: nix-env -f '<nixpkgs>' -qaPA nodePackages | grep tern
    – zaynetro
    Nov 14 at 12:52


















up vote
0
down vote













As an alternative, I also found CMCDragonkai's comment on the Nixpkgs issue #3393:




I just found out that you can change NPM's prefix directory. Something
like:



npm config set prefix '~/mutable_node_modules.


This allows you to use NPM's global installation.



So it's possible to work around the purely functional model, by
redirecting its outputs to somewhere that's not managed by Nix. But I
guess it defeats the purpose of using Nix. And not every single
software will support these types of configuration changes.



Still I feel it's very clunky having to switch between using nix-env
for normal global Node packages, and npm for development packages. I
guess that's why there's all those porting layers such as "npm2nix".







share|improve this answer




















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f379842%2fhow-to-install-npm-packages-in-nixos%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    12
    down vote













    There are multiple ways to use npm packages through nix:



    For my personal projects, I use nix-shell then within the shell I use npm scripts to prevent the need for npm global packages (like with gulp). The process looks something like this (and is probably very similar for yarn):



    $ nix-shell -p nodejs-8_x
    [nix-shell:yourproject]$ npm install # installs npm deps to project-local node_modules
    [nix-shell:yourproject]$ npm exec (...) # using scripts configured in package.json


    This works well for me since none of my packages have binary dependencies. This post describes the creation of a default.nix for your project so you won't have to specify dependencies for every invocation of nix-shell, but it's optional.



    Another way is using npm2nix:



    node2nix -i node-packages.json # creates ./default.nix
    nix-shell # nix-shell will look for a default.nix, which above will have generated


    Which will cause Nix to manage all npm packages in the project.



    It may be a good idea to become familiar with nix-shell, since trying to install node packages / any dependency in your nix profile (through nix-env or nox) defeats the purpose of nix by polluting the "global" namespace.



    Hope this helps!






    share|improve this answer






















    • Could you expand on this with regards to packages using binding.gyp for example: github.com/mateogianolio/nblas
      – CMCDragonkai
      Dec 15 '17 at 7:36






    • 1




      I found out how to do it for binary packages. You need the nodePackages_6_x.node-gyp, and any other libraries like blas, then when it's all together, you can use npm install .... packages that use node-gyp.
      – CMCDragonkai
      Dec 15 '17 at 7:52






    • 1




      Regarding the first method, as an alternative to the npm scripts solution, I find adding global npm packages to the nix-shell effective, e.g. nix-shell -p nodejs-8_x nodePackages.grunt-cli. (Warning: nixos and node noob here.)
      – Ryne Everett
      Jan 28 at 18:29










    • The one thing I don't understand about the first method is how to actually install the package itself, i.e. where does the binary for the project's package.json bin end up?
      – Ryne Everett
      Jan 28 at 20:00










    • @ryne-everett If you run npm install, executables would be linked into node_modules/.bin. See here.
      – Luke Adams
      Feb 3 at 19:21















    up vote
    12
    down vote













    There are multiple ways to use npm packages through nix:



    For my personal projects, I use nix-shell then within the shell I use npm scripts to prevent the need for npm global packages (like with gulp). The process looks something like this (and is probably very similar for yarn):



    $ nix-shell -p nodejs-8_x
    [nix-shell:yourproject]$ npm install # installs npm deps to project-local node_modules
    [nix-shell:yourproject]$ npm exec (...) # using scripts configured in package.json


    This works well for me since none of my packages have binary dependencies. This post describes the creation of a default.nix for your project so you won't have to specify dependencies for every invocation of nix-shell, but it's optional.



    Another way is using npm2nix:



    node2nix -i node-packages.json # creates ./default.nix
    nix-shell # nix-shell will look for a default.nix, which above will have generated


    Which will cause Nix to manage all npm packages in the project.



    It may be a good idea to become familiar with nix-shell, since trying to install node packages / any dependency in your nix profile (through nix-env or nox) defeats the purpose of nix by polluting the "global" namespace.



    Hope this helps!






    share|improve this answer






















    • Could you expand on this with regards to packages using binding.gyp for example: github.com/mateogianolio/nblas
      – CMCDragonkai
      Dec 15 '17 at 7:36






    • 1




      I found out how to do it for binary packages. You need the nodePackages_6_x.node-gyp, and any other libraries like blas, then when it's all together, you can use npm install .... packages that use node-gyp.
      – CMCDragonkai
      Dec 15 '17 at 7:52






    • 1




      Regarding the first method, as an alternative to the npm scripts solution, I find adding global npm packages to the nix-shell effective, e.g. nix-shell -p nodejs-8_x nodePackages.grunt-cli. (Warning: nixos and node noob here.)
      – Ryne Everett
      Jan 28 at 18:29










    • The one thing I don't understand about the first method is how to actually install the package itself, i.e. where does the binary for the project's package.json bin end up?
      – Ryne Everett
      Jan 28 at 20:00










    • @ryne-everett If you run npm install, executables would be linked into node_modules/.bin. See here.
      – Luke Adams
      Feb 3 at 19:21













    up vote
    12
    down vote










    up vote
    12
    down vote









    There are multiple ways to use npm packages through nix:



    For my personal projects, I use nix-shell then within the shell I use npm scripts to prevent the need for npm global packages (like with gulp). The process looks something like this (and is probably very similar for yarn):



    $ nix-shell -p nodejs-8_x
    [nix-shell:yourproject]$ npm install # installs npm deps to project-local node_modules
    [nix-shell:yourproject]$ npm exec (...) # using scripts configured in package.json


    This works well for me since none of my packages have binary dependencies. This post describes the creation of a default.nix for your project so you won't have to specify dependencies for every invocation of nix-shell, but it's optional.



    Another way is using npm2nix:



    node2nix -i node-packages.json # creates ./default.nix
    nix-shell # nix-shell will look for a default.nix, which above will have generated


    Which will cause Nix to manage all npm packages in the project.



    It may be a good idea to become familiar with nix-shell, since trying to install node packages / any dependency in your nix profile (through nix-env or nox) defeats the purpose of nix by polluting the "global" namespace.



    Hope this helps!






    share|improve this answer














    There are multiple ways to use npm packages through nix:



    For my personal projects, I use nix-shell then within the shell I use npm scripts to prevent the need for npm global packages (like with gulp). The process looks something like this (and is probably very similar for yarn):



    $ nix-shell -p nodejs-8_x
    [nix-shell:yourproject]$ npm install # installs npm deps to project-local node_modules
    [nix-shell:yourproject]$ npm exec (...) # using scripts configured in package.json


    This works well for me since none of my packages have binary dependencies. This post describes the creation of a default.nix for your project so you won't have to specify dependencies for every invocation of nix-shell, but it's optional.



    Another way is using npm2nix:



    node2nix -i node-packages.json # creates ./default.nix
    nix-shell # nix-shell will look for a default.nix, which above will have generated


    Which will cause Nix to manage all npm packages in the project.



    It may be a good idea to become familiar with nix-shell, since trying to install node packages / any dependency in your nix profile (through nix-env or nox) defeats the purpose of nix by polluting the "global" namespace.



    Hope this helps!







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Sep 2 '17 at 20:01

























    answered Jul 25 '17 at 20:55









    Luke Adams

    1213




    1213











    • Could you expand on this with regards to packages using binding.gyp for example: github.com/mateogianolio/nblas
      – CMCDragonkai
      Dec 15 '17 at 7:36






    • 1




      I found out how to do it for binary packages. You need the nodePackages_6_x.node-gyp, and any other libraries like blas, then when it's all together, you can use npm install .... packages that use node-gyp.
      – CMCDragonkai
      Dec 15 '17 at 7:52






    • 1




      Regarding the first method, as an alternative to the npm scripts solution, I find adding global npm packages to the nix-shell effective, e.g. nix-shell -p nodejs-8_x nodePackages.grunt-cli. (Warning: nixos and node noob here.)
      – Ryne Everett
      Jan 28 at 18:29










    • The one thing I don't understand about the first method is how to actually install the package itself, i.e. where does the binary for the project's package.json bin end up?
      – Ryne Everett
      Jan 28 at 20:00










    • @ryne-everett If you run npm install, executables would be linked into node_modules/.bin. See here.
      – Luke Adams
      Feb 3 at 19:21

















    • Could you expand on this with regards to packages using binding.gyp for example: github.com/mateogianolio/nblas
      – CMCDragonkai
      Dec 15 '17 at 7:36






    • 1




      I found out how to do it for binary packages. You need the nodePackages_6_x.node-gyp, and any other libraries like blas, then when it's all together, you can use npm install .... packages that use node-gyp.
      – CMCDragonkai
      Dec 15 '17 at 7:52






    • 1




      Regarding the first method, as an alternative to the npm scripts solution, I find adding global npm packages to the nix-shell effective, e.g. nix-shell -p nodejs-8_x nodePackages.grunt-cli. (Warning: nixos and node noob here.)
      – Ryne Everett
      Jan 28 at 18:29










    • The one thing I don't understand about the first method is how to actually install the package itself, i.e. where does the binary for the project's package.json bin end up?
      – Ryne Everett
      Jan 28 at 20:00










    • @ryne-everett If you run npm install, executables would be linked into node_modules/.bin. See here.
      – Luke Adams
      Feb 3 at 19:21
















    Could you expand on this with regards to packages using binding.gyp for example: github.com/mateogianolio/nblas
    – CMCDragonkai
    Dec 15 '17 at 7:36




    Could you expand on this with regards to packages using binding.gyp for example: github.com/mateogianolio/nblas
    – CMCDragonkai
    Dec 15 '17 at 7:36




    1




    1




    I found out how to do it for binary packages. You need the nodePackages_6_x.node-gyp, and any other libraries like blas, then when it's all together, you can use npm install .... packages that use node-gyp.
    – CMCDragonkai
    Dec 15 '17 at 7:52




    I found out how to do it for binary packages. You need the nodePackages_6_x.node-gyp, and any other libraries like blas, then when it's all together, you can use npm install .... packages that use node-gyp.
    – CMCDragonkai
    Dec 15 '17 at 7:52




    1




    1




    Regarding the first method, as an alternative to the npm scripts solution, I find adding global npm packages to the nix-shell effective, e.g. nix-shell -p nodejs-8_x nodePackages.grunt-cli. (Warning: nixos and node noob here.)
    – Ryne Everett
    Jan 28 at 18:29




    Regarding the first method, as an alternative to the npm scripts solution, I find adding global npm packages to the nix-shell effective, e.g. nix-shell -p nodejs-8_x nodePackages.grunt-cli. (Warning: nixos and node noob here.)
    – Ryne Everett
    Jan 28 at 18:29












    The one thing I don't understand about the first method is how to actually install the package itself, i.e. where does the binary for the project's package.json bin end up?
    – Ryne Everett
    Jan 28 at 20:00




    The one thing I don't understand about the first method is how to actually install the package itself, i.e. where does the binary for the project's package.json bin end up?
    – Ryne Everett
    Jan 28 at 20:00












    @ryne-everett If you run npm install, executables would be linked into node_modules/.bin. See here.
    – Luke Adams
    Feb 3 at 19:21





    @ryne-everett If you run npm install, executables would be linked into node_modules/.bin. See here.
    – Luke Adams
    Feb 3 at 19:21













    up vote
    5
    down vote













    For some reason I don't know, nodePackages is not in root namespace and can't be found by using nix-env -qa



    use nix-env -qaPA 'nixos.nodePackages' to list for avaliable packages.



    $ nix-env -qaPA 'nixos.nodePackages' | grep -i web
    nixos.nodePackages.webdrvr node-webdrvr-2.43.0-1
    nixos.nodePackages.webpack node-webpack-2.6.1


    If there is no packages you want and you can't make your own, try request it on NixOS github.






    share|improve this answer






















    • I am using just nix package manager and was able to make it work with: nix-env -f '<nixpkgs>' -qaPA nodePackages | grep tern
      – zaynetro
      Nov 14 at 12:52















    up vote
    5
    down vote













    For some reason I don't know, nodePackages is not in root namespace and can't be found by using nix-env -qa



    use nix-env -qaPA 'nixos.nodePackages' to list for avaliable packages.



    $ nix-env -qaPA 'nixos.nodePackages' | grep -i web
    nixos.nodePackages.webdrvr node-webdrvr-2.43.0-1
    nixos.nodePackages.webpack node-webpack-2.6.1


    If there is no packages you want and you can't make your own, try request it on NixOS github.






    share|improve this answer






















    • I am using just nix package manager and was able to make it work with: nix-env -f '<nixpkgs>' -qaPA nodePackages | grep tern
      – zaynetro
      Nov 14 at 12:52













    up vote
    5
    down vote










    up vote
    5
    down vote









    For some reason I don't know, nodePackages is not in root namespace and can't be found by using nix-env -qa



    use nix-env -qaPA 'nixos.nodePackages' to list for avaliable packages.



    $ nix-env -qaPA 'nixos.nodePackages' | grep -i web
    nixos.nodePackages.webdrvr node-webdrvr-2.43.0-1
    nixos.nodePackages.webpack node-webpack-2.6.1


    If there is no packages you want and you can't make your own, try request it on NixOS github.






    share|improve this answer














    For some reason I don't know, nodePackages is not in root namespace and can't be found by using nix-env -qa



    use nix-env -qaPA 'nixos.nodePackages' to list for avaliable packages.



    $ nix-env -qaPA 'nixos.nodePackages' | grep -i web
    nixos.nodePackages.webdrvr node-webdrvr-2.43.0-1
    nixos.nodePackages.webpack node-webpack-2.6.1


    If there is no packages you want and you can't make your own, try request it on NixOS github.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jul 21 '17 at 4:16

























    answered Jul 21 '17 at 4:09









    wizzup

    22018




    22018











    • I am using just nix package manager and was able to make it work with: nix-env -f '<nixpkgs>' -qaPA nodePackages | grep tern
      – zaynetro
      Nov 14 at 12:52

















    • I am using just nix package manager and was able to make it work with: nix-env -f '<nixpkgs>' -qaPA nodePackages | grep tern
      – zaynetro
      Nov 14 at 12:52
















    I am using just nix package manager and was able to make it work with: nix-env -f '<nixpkgs>' -qaPA nodePackages | grep tern
    – zaynetro
    Nov 14 at 12:52





    I am using just nix package manager and was able to make it work with: nix-env -f '<nixpkgs>' -qaPA nodePackages | grep tern
    – zaynetro
    Nov 14 at 12:52











    up vote
    0
    down vote













    As an alternative, I also found CMCDragonkai's comment on the Nixpkgs issue #3393:




    I just found out that you can change NPM's prefix directory. Something
    like:



    npm config set prefix '~/mutable_node_modules.


    This allows you to use NPM's global installation.



    So it's possible to work around the purely functional model, by
    redirecting its outputs to somewhere that's not managed by Nix. But I
    guess it defeats the purpose of using Nix. And not every single
    software will support these types of configuration changes.



    Still I feel it's very clunky having to switch between using nix-env
    for normal global Node packages, and npm for development packages. I
    guess that's why there's all those porting layers such as "npm2nix".







    share|improve this answer
























      up vote
      0
      down vote













      As an alternative, I also found CMCDragonkai's comment on the Nixpkgs issue #3393:




      I just found out that you can change NPM's prefix directory. Something
      like:



      npm config set prefix '~/mutable_node_modules.


      This allows you to use NPM's global installation.



      So it's possible to work around the purely functional model, by
      redirecting its outputs to somewhere that's not managed by Nix. But I
      guess it defeats the purpose of using Nix. And not every single
      software will support these types of configuration changes.



      Still I feel it's very clunky having to switch between using nix-env
      for normal global Node packages, and npm for development packages. I
      guess that's why there's all those porting layers such as "npm2nix".







      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        As an alternative, I also found CMCDragonkai's comment on the Nixpkgs issue #3393:




        I just found out that you can change NPM's prefix directory. Something
        like:



        npm config set prefix '~/mutable_node_modules.


        This allows you to use NPM's global installation.



        So it's possible to work around the purely functional model, by
        redirecting its outputs to somewhere that's not managed by Nix. But I
        guess it defeats the purpose of using Nix. And not every single
        software will support these types of configuration changes.



        Still I feel it's very clunky having to switch between using nix-env
        for normal global Node packages, and npm for development packages. I
        guess that's why there's all those porting layers such as "npm2nix".







        share|improve this answer












        As an alternative, I also found CMCDragonkai's comment on the Nixpkgs issue #3393:




        I just found out that you can change NPM's prefix directory. Something
        like:



        npm config set prefix '~/mutable_node_modules.


        This allows you to use NPM's global installation.



        So it's possible to work around the purely functional model, by
        redirecting its outputs to somewhere that's not managed by Nix. But I
        guess it defeats the purpose of using Nix. And not every single
        software will support these types of configuration changes.



        Still I feel it's very clunky having to switch between using nix-env
        for normal global Node packages, and npm for development packages. I
        guess that's why there's all those porting layers such as "npm2nix".








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        toraritte

        17310




        17310



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f379842%2fhow-to-install-npm-packages-in-nixos%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?