Search code examples
shellelixirelixir-mixnixos

run commands using default.nix file


I've got the following default.nix file:

with import <nixpkgs> {}; {
   pullapiEnv = stdenv.mkDerivation {
     name = "pullapi";
     buildInputs = [ elixir ];
   };
 }

Which is great, and works with nix-shell inside my repo, however how do run I commands during the shell setup? I'd like to run

mix deps.get
mix test

upon each nix-shell execution.


Solution

  • As per wizzup's comment, this was solved using shellHook:

    #default.nix
    with import <nixpkgs> {}; {
       pullapiEnv = stdenv.mkDerivation {
         name = "pullapi";
         buildInputs = [ elixir ];
         shellHook = ''
         mix deps.get
         mix compile
         mix test
         '';
       };
    }