Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a service be run in nix-shell

Tags:

nixos

I work under NixOS, and I love it so far.

For my coding projects, I'm trying to achieve separate development environments. So for example for my Scala/node.js project, I have written default.nix for nix-shell :

with import <nixpkgs> {}; {
    tarifs2Env = stdenv.mkDerivation {
        name = "webapp";
        buildInputs = with pkgs; [ 
            sbt 
            nodejs
            nodePackages.gulp
        ];

        shellHook = ''
        '';
    };
}

So far so good. Now I would like to add a database, posgtres for example. Is there a way to add a service to a nix-shell?

like image 987
KaC Avatar asked Sep 24 '16 13:09

KaC


People also ask

What is nix shell for?

Description. The command nix-shell will build the dependencies of the specified derivation, but not the derivation itself. It will then start an interactive shell in which all environment variables defined by the derivation path have been set to their corresponding values, and the script $stdenv/setup has been sourced.

Is nix slow?

Nix evaluation can be slow sometimes, but installation is generally relatively fast, since everything in Nix is fully parallelizable. It's generally several times faster than apt, for installs that involve multiple large downloads, for example, and historically it's also faster than pacman.

What is a nix derivation?

Derivations are the building blocks of a Nix system, from a file system view point. The Nix language is used to describe such derivations.

What is nix-ENV?

The command nix-env is used to manipulate Nix user environments. User environments are sets of software packages available to a user at some point in time. In other words, they are a synthesised view of the programs available in the Nix store.


1 Answers

I think https://github.com/chrisfarms/nixos-shell should do exactly what you're after. I've not used it myself but as I understand it works by taking a configuration.nix that describes the service(s) that you want then builds the config in an ephemeral NixOS container and drops you into a shell in the container.

like image 166
brocking Avatar answered Sep 27 '22 18:09

brocking