Chaker Benhamed
Home | |
Package web application with Nix
almost 4 years ago.
Currently I am doing an internship in one of the main companies that support the Nix ecosystem (Nix, NixOS, Hydra, NixOps... ). For my Internship I am creating an Internal web application to standardize the process of benchmarking company's applications.
For the backend I am building a REST API with Pyramid and cornice. Since the main goal of project aside from the application it self is to give me the chance to dive deep in the Nix expression language and packaging applications with the nix package manager.
Here I will try to comment my experience packaging the application with Nix.
Actually the backend is the easy part. Since building it is straight froward as building a python package with Nix.
First you need to create setup.py
file.
from setuptools import setup, find_packages setup(name='my_awesome_backend', version='0.0', description='My awesome backend', packages=find_packages(), )
And then in your default.nix
{ pkgs ? import <nixpkgs> {} , my_awesome_backend ? ./. , version ? "Alpha" }: { API = pkgs.pythonPackages.buildPythonPackage { name = "my-awesome-backend-${version}"; src = my_awesome_backend; buildInputs = with pkgs ;[ pythonPackages.pyramid ]; }; }
You can enter nix-shell
with Pyramid installed.
It just create a python derivation that contain the source code of your application and pythonPackages.pyramid
as dependency. In Nix all python packages are under pythonPackges
variable.
let say we want to add pytest
for TDD (Long live TDD). we add it in the buildInputs
array.
buildInputs = with pkgs ;[ pythonPackages.pyramid pythonPackages.pytest ];
We can keep it DRY by using
buildInputs = with pkgs.pythonPackages ;[ pyramid pytest ];
To search for other python packages you can check the search page in Nixos site.
Package managers first goal is to solve Dependency hell
. But when you mix package managers.. Here things get little bit ugly. I was using AngularJS Then I moved to React. But I will only be talking about packaging the frontend built with Angular.
For that I will take the Angular-seed project as an example.
The Angualr seed project use two package managers. NPM and Bower. I wanted to be able to get all dependencies just by entering a nix-shell.
to be continued