\section{Pylightnix for Nix users}

\begin{itemize}

  \item Like Nix, Pylightnix offers purely-functional solution for data
    deployment problem.

  \item Like Nix, Pylightnix allows user to describe and run two-phased build
    processes in a controllable and reproducible manner.

  \item Unlike Nix, pylightnix doesn't aim at providing operating system-wide package
    manager. Instead it tries to provide a reliable API for application-wide
    storage for immutable objects, which could be a backbone for some package
    manager, but also could be used for other tasks, such as data science
    experiment management.

  \item Unlike Nix, Pylightnix doesn't provide neither interpeter for separate
    configuration language, nor build isolation. Both instantiation and
    realization phases are to be defined in Python. There are certain mechanisms
    to increase safety, like the recursion checker, but in general, users are
    to take their responsibility of not breaking the concepts.

  \item Unlike Nix, Pylightnix is aware of non-deterministic builds, which allows
    it to cover a potentially larger set of use cases.

\end{itemize}

\par

\begin{tabular}{|p{0.5\textwidth}|p{0.5\textwidth}|}

\hline

\multicolumn{1}{|c|}{\textbf{Nix}} &
\multicolumn{1}{|c|}{\textbf{Pylightnix}}

\\
\hline

\tiny
\begin{pythoncode}
{ pkgs? import <nixpkgs> {}
, stdenv ? pkgs.stdenv
}:

let
  version = "2.10";
  url = "mirror://gnu/hello/hello-\${version}.tar.gz";
  sha256 = "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i";
in
with pkgs;
stdenv.mkDerivation rec {
  name = "hello";
  src = fetchurl { inherit url sha256; };

  buildInputs = [ gnutar ];

  buildCommand = ''
    tar -xzf $src
    cd hello-2.10
    ./configure --prefix=$out
    make
    make install
  '';
}
\end{pythoncode}

&

\tiny
\begin{pyblock}[stdout][]
from tempfile import TemporaryDirectory
from shutil import copytree
from os import getcwd, chdir, system
from os.path import join
from pylightnix import (
  Registry, DRef, RRef, Config, RefPath,
  mkconfig, Path, Build, build_outpath, mkdrv,
  build_wrapper, match_latest, dirrw, mklens,
  instantiate, realize1, fetchurl, selfref)

version = '2.10'
url = f'http://ftp.gnu.org/gnu/hello/hello-{version}.tar.gz'
sha256 = '31e066137a962676e89f69d1b65382de95a7ef7d914b8cb956f41ea72e0f516b'

def stage_hello(m:Registry)->DRef:

  def _config()->Config:
    name:str = 'hello-bin'
    src:RefPath = fetchurl(r, name='hello-src',
                              url=url,
                              sha256=sha256)
    out_bin = [selfref, 'usr', 'bin', 'hello']
    return locals()

  def _make(b:Build)->None:
    o:Path = build_outpath(b)
    with TemporaryDirectory() as tmp:
      copytree(join(mklens(b).src.syspath, f'hello-{version}'), join(tmp,'src'))
      dirrw(Path(join(tmp,'src')))
      cwd = getcwd()
      try:
        chdir(join(tmp,'src'))
        system('./configure --prefix=/usr')
        system('make')
        system(f'make install DESTDIR={o}')
      finally:
        chdir(cwd)

  return mkdrv(r, mkconfig(_config()),
                  match_latest(),
                  build_wrapper(_make))
\end{pyblock}

\normalsize

\\

% Nix comments

% Here goes reference to a line \ref{myline}.

&

% Pylightnix comments

\\

\hline
\end{tabular}

