Nix development utils that will blow up your mind
Go to file
Jaka Hudoklin d14e37eb26 Merge pull request #6 from wmertens/patch-1
supervisord: shell wrapper improvements
2014-12-06 18:57:33 +01:00
nix-services supervisord: shell wrapper improvements 2014-12-03 12:17:41 +01:00
container.nix container: fix updating scripts 2014-05-23 19:18:46 +02:00
default.nix fix nix file name 2014-04-07 23:49:58 +02:00
README.md Example usage of supervisord.bin with nix-shell 2014-10-13 16:19:22 +02:00

========== nix-rehash

Nix development utils that will blow up your mind

reService - fullstack@dev

reService takes your nixos config of services and creates user-enabled supervisord config that you can use for development or deployment on non nixos systems. Having deterministic fullstack in development has never been more awesome.

  • Create default.nix

    { pkgs ? import <nixpkgs> {}
    , projectName ? "myProject"
    , nix-rehash ? import <nix-rehash> }:
      with pkgs.lib;
      with pkgs;
    
    let
      services = nix-rehash.reService {
        name = "${projectName}";
        configuration = let servicePrefix = "/tmp/${projectName}/services"; in [
          ({ config, pkgs, ...}: {
            services.postgresql.enable = true;
            services.postgresql.package = pkgs.postgresql92;
            services.postgresql.dataDir = "${servicePrefix}/postgresql";
          })
        ];
      };
    in myEnvFun {
      name = projectName;
      buildInputs = [ services ];
    }
    
  • install nix-env -f default.nix -i

  • load environemnt load-env-myProject

  • start services myProject-start-services, control services myProject-control-services, stop services myProject-stop-services

Now build this with hydra and pass the environment around :)

Alternative using nix-shell:

  • set buildInputs = [ services.config.supervisord.bin ];
  • run nix-shell
  • use supervisord and supervisorctl as you wish

reContain - heroku@home

reContain makes nixos enabled installable container that can auto-update itself. Now you can build container on hydra and auto update it on host machine. Staging or deployments have never been easier :)

  • Create default.nix

    { pkgs ? import <nixpkgs>
    , name ? "myProject"
    , nix-rehash ? import <nix-rehash> }:
      with pkgs.lib;
      with pkgs;
    
    {
      container = nix-rehash.reContain {
        inherit name;
        configuration = [{
        services.openssh.enable = true;
        services.openssh.ports = [ 25 ];
        users.extraUsers.root.openssh.authorizedKeys.keys = [ (builtins.readFile ./id_rsa.pub) ];
        }];
      };
    }
    
  • do nix-env [-f default.nix] -i myProject-container or build with hydra and add a channel

  • start container: sudo myProject-start-container

  • ssh to container: ssh localhost -p 25

  • enable auto updates with cron:

    * * * * * nix-env -i myProject-container && sudo $HOME/.nix-profile/bin/myProject-update-container
    
  • stop container: sudo myProject-stop-container