Aleksandar Topuzović
Nix is a purely functional package manager.
It is built using the Nix language
The Nix expression language is a pure, lazy, functional language.
The language was designed especially for the Nix Package Manager.
Types
Integers
Floats
URIs
Booleans
Lists
built into nix
nixos provided lib
It treats packages like values in purely functional programming languages.
Packages are built by functions that don’t have side-effects, and they never change after they have been built.
–
Nix stores packages in the Nix store, /nix/store
where
each package has its own unique subdirectory
/nix/store/b6gvzjyb2pg0kjfwrjmg1vfhh54ad73z-firefox-33.1/
Where b6gvzjyb2pg0kjfwrjmg1vfhh54ad73z
is a unique
identifier for the package that captures all its dependencies (it’s a
cryptographic hash of the package’s build dependency graph).
Nix’s purely functional approach ensures that installing or upgrading one package cannot break other packages.
This is because it won’t overwrite dependencies with newer versions that might cause breakage elsewhere.
It allows you to roll back to previous versions, and ensures that no package is in an inconsistent state during an upgrade.
Nix builds packages in isolation from each other.
This ensures that they are reproducible and don’t have undeclared dependencies, so if a package works on one machine, it will also work on another.
Nix makes it trivial to set up and share build environments for your projects, regardless of what programming languages and tools you’re using.
For instance, running the command “nix-shell ‘
Nix supports multi-user package management: multiple users can share a common Nix store securely, don’t need to have root privileges to install software, and can install and use different versions of a package.
A recipe how to build a package
{ nixpkgs ? <nixpkgs>
}:
let
pkgs = import nixpkgs {};
in
pkgs.stdenv.mkDerivation {
name = "my-loveley-cow";
phases = ["buildPhase"];
buildInputs = [ pkgs.cowsay ];
buildPhase = ''
mkdir $out
cowsay "Nix is awesome!" > $out/what.txt
'';
}
## Builders |
fetchurl |
nixpkgs/pkgs/build-support/fetchurl/default.nix |
Trivial builders |
nixpkgs/pkgs/build-support/trivial-builders.nix |
eg `writeTextFile`` |
Other |
pythonPackages.buildPythonPackage |
Nix is available on Linux (works on WSL) and Mac Os X
curl https://nixos.org/nix/install | sh
$ nix repl
Welcome to Nix version 2.3.2. Type :? for help.
nix-repl>
Nix package collection is a set of packages for the Nix package manager.
The power house of development using Nix.
A file usually called shell.nix
contains the declaration
of packages that are available to the user.
NixOS is a Linux distribution with a unique approach to package and configuration management. Built on top of the Nix package manager, it is completely declarative, makes upgrading systems reliable, and has many other advantages.
Host configuration defined in
/etc/nixos/configuration.nix
{ config, lib, pkgs, ... }:
{
imports = [
./hardware-configuration.nix
];
...
services.nginx = {
enable = true;
statusPage = true;
virtualHosts."www.topuzovic.net" = {
default = true;
enableACME = true;
addSSL = true;
};
};
...
}
NixOS has a modular system for declarative configuration. Each module handles a specific thing, modules can reuse other modules and can define options which are used by other modules
Channels is the method of specifying which version of NixOs to install.
There are 2 releases per year (eg. 19.03, 19.09) which correspond to channels.
eg. http://nixos.org/channels/nixos-19.09
NixOps is a tool for deploying NixOS machines in a network or cloud. It takes as input a declarative specification of a set of “logical” machines and then performs any necessary steps or actions to realise that specification: instantiate cloud machines, build and download dependencies, stop and start services, and so on.
A series of blog posts that provide a tutorial introduction into the Nix package manager and Nixpkgs package collection, in the form of short chapters called ‘pills’.
Based on the Nix package manager but packages are defined as native Guile (scheme) modules. Provides exclusively only free software.
An advanced distribution of the GNU operating system. It uses the Linux-libre kernel, and and GNU Shepherd init system.
Disnix is a distributed service deployment toolset whose main purpose is to deploy service oriented systems into networks of machines having various characteristics (such as operating systems) and is built on top of Nix
Hydra is a Nix-based continuous build system. Builds nixpkkgs.
cpkg is a build tool for C with a particular emphasis on cross compilation. It is configured using Dhall.
Some would say this is how nix would look with static types.
github.com/atopuzov
twitter.com/atopuzov