How to use Nix to set up a development environment?

Let's say I need PostgreSQL 9.6.3 and Ruby 2.3.1 and other tools. I cannot find a tutorial explaining what I need to do.

From the Nix manual, I seem to need to write a Nix expression to install the necessary dependencies, but I cannot jump from:

{ stdenv, fetchurl, perl }: stdenv.mkDerivation { name = "hello-2.1.1"; builder = ./builder.sh; src = fetchurl { url = ftp://ftp.nluug.nl/pub/gnu/hello/hello-2.1.1.tar.gz; md5 = "70c9ccf9fac07f762c24f2df2290784d"; }; inherit perl; } 

to an expression that installs the correct versions of PostgreSQL and Ruby. It is completely incomprehensible to me where to even put the file that PostgreSQL and Ruby installs, or how to run one file in a given directory.

Can someone provide pointers to such lessons or point me in the right direction?

+5
source share
1 answer

You can use nix-shell for this. It turns you into a shell tuned for a given nix expression. Initially, this expression could simply be on the lines buildInputs = [ pkgs.ruby ]; , and you can develop it. There are a number of useful articles on the web written by nix users that give more examples of using nix-shell, like this garbas.si

It may also be helpful for you to get a better understanding of how nix packages work. There is a separate nixpkgs manual , which is described in more detail using nix to create package expressions. A quick snapshot of the third section should be helpful to give a little more insight. There is also a chapter on using nix with ruby ​​bundler, which may be useful for you. Again, there are articles that give more examples of its use, for example, one of stesie.imtqy.com .

If you need postgresql to work in your environment, nix cannot handle this for you; its function is solely to create and manage packages, and not to activate them. You can simply activate postgres manually, use the nix-shell hook, or create some other integration with nix, but I think the most reliable option is to use a Linux distribution built on top of Nix - NixOS . NixOS integrates with nix packages and manages the services provided by the packages. You can create a NixOS configuration with postgres enabled and an existing development environment. This utility from github.com/chrisfarms may also be of interest.

+11
source

Source: https://habr.com/ru/post/1269168/


All Articles