Skip to content

Latest commit

 

History

History
183 lines (121 loc) · 6.23 KB

source.markdown

File metadata and controls

183 lines (121 loc) · 6.23 KB

% Packaging 101 % Tokyo NixOS Meetup % 2016, 18 February

This month in Nix - 1

News from the front

This month in Nix - 2

NixOS Reddit selection

This month in Nix - 3

Mailing list selection

This month in Nix - 4

Tokyo NixOS Meetup activities

Understand Nix in 10 minuts

  • Nix: compiler for a functional package centric DSL
    • functional = lazy + pure + deterministic
    • pure = no missing dependency
    • deterministic = binary install for free
    • lazy = lightweight and fast
    • DSL = easy customization
    • package isolation = atomic upgrades + easy rollback + no Dependency hell + impossible to break system by installing a package
    • not limited to system packages, Nix can package almost anything (great packaging of hackage)
    • can be thought as "One package manager to rule them all" "Make on steroids"
  • NixOS: an OS is packages + configuration, NixOS is Nix extended with a configuration DSL (module system)
    • declarative configuration with typed properties
    • lightweight containers (based on systemd nspawn)
    • easy to add custom services

Packaging 101: packaging basics

  • Foreword:

  • Basic workflow:

    • get nixpkgs
    • create a package file in the somewhere in pkgs/
    • add the package entry in pkgs/top-level/all-packages.nix
    • build the package and test

Packaging 101: getting nixpkgs

  • go to github nixpkgs and click the Fork button

  • go to the forked repository and get the clone url

  • clone to a local machine

    $ git clone [email protected]:USER/nixpkgs.git
  • Or just clone the official nixpkgs if you have no github account or don't plan to submit PRs.

  • Exercices:

    • check the structure under the pkgs/.
    • check pkgs/top-level/all-packages.nix.

Packaging 101: create a custom hello package (derivation)

  • check the default hello package in pkgs/applications/misc/hello/default.nix

  • create a dedicated branch

    $ git checkout -b pkg/my-hello
  • create my-hello folder in misc

    $ mkdir pkgs/applications/misc/my-hello/
  • copy the hello derivation to my-hello

    $ cp pkgs/applications/misc/{,my-}hello/default.nix
  • edit pkgs/applications/misc/my-hello/default.nix and change the derivation name to my-hello

  • Exercices:

    • Find what meta maintainers and licence fields refer to.
    • Make yourself as the maintainer of my-hello.

Packaging 101: register the package to all-packages.nix

  • add a my-hello entry to all-packages.nix

  • Exercices

    • figure the relation between the package name, the package path and the all-packages.nix entry name.
    • move the version in a dedicated attribute.
      • (tip: check the tilda package)

Packaging 101: build the package

  • build the package

    $ nix-build -A my-hello
  • run it!

    $ ./result/bin/hello
  • Exercices:

    • Check and note the my-hello nix store hash.
      • (tip: result is a symlink to the store)
    • Change my-hello version to 2.9
      • (tip: man nix-prefetch-url).
    • Compare the first my-hello and 2.9 my-hello store hash.
    • Can you still run my-hello 2.10?

Packaging 101: Bonus Exercice

  • Find a package not yet available in nixpkgs and package it.

Meetup future

  • Any idea on how to improve the meetup?
  • Better times, better places?
  • 3 places: meetup, connpass, doorkeeper; Meetup currently as a the main place
  • more activities like OSC and other groups
  • evolve to a "NixOS user group"?

Useful links