Nixについて

C1d2f103212bb3539c800ed39b4a8a75?s=47 mt_caret
October 08, 2017

 Nixについて

C1d2f103212bb3539c800ed39b4a8a75?s=128

mt_caret

October 08, 2017
Tweet

Transcript

  1. 2.
  2. 11.
  3. 15.

    Nix(パッケージマネージャ) $ nix-env -i hello #インストール $ hello $ nix-env

    -e hello #アンインストール $ nix-env --rollback $ nix-env --list-generations
  4. 18.

    Nix(言語)の文法 let x = 4; # 変数束縛(宣言/初期化) f = num:

    num + 1; # 関数 in f x # 関数適用(呼び出し)
  5. 19.

    Nix(言語)の文法 let set = { num = 5; str =

    "World!"; }; # 他言語でいうRecord, Hash, Dict list = [ 1 "hoge" 4 { foo = "bar"; }]; f = { num, str }: "Hello, ${str}"; in [ set.num (head list) (f set) ] 評価すると => [ 5 1 "Hello, World!" ]
  6. 20.

    純粋関数型 - 関数の戻り値は引数から一意に定まる - 副作用を持たない let sum = 0; function

    calc_sum(num) { sum += num; return sum; } console.log(calc_sum(5)); //=> 5 console.log(calc_sum(5)); //=> 10 console.log(calc_sum(5)); //=> 15
  7. 21.

    遅延評価 式の評価(計算)を行う時、式の結果を利用 するまで評価(計算)をしない ex: f (1 + 2)の場合はf (1 +

    2)を必要とする (例えば出力等で)まで1 + 2の計算も、fへ の適用も行われない ex: let x = 5 / 0; in “this works!”
  8. 23.

    Nix(言語)の文法もうすこし let set = { a = "a"; b =

    { c = "c"; }; }; abc = with set; [ a b (with b; c) ]; in abc 評価すると => [ "a" { c = "c"; } "c" ]
  9. 25.

    Derivation(パッケージ)とRealization Derivationは特定のattributeを持ったSet nix-repl> d = derivation { name = “myname”;

    builder = “mybuilder”; system = “mysystem”; } nix-repl> d /nix/store/9r1...3yn-hoge.drv => /nix/store/9r1...3yn-hoge ex. $ ppsh < /nix/store/9r1...3yn-hoge.drv
  10. 27.

    例: GNU HelloのNix式 { stdenv, fetchurl }: stdenv.mkDerivation rec {

    name = "hello-2.10"; src = fetchurl { url = "mirror://gnu/hello/${name}.tar.gz"; sha256 = "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"; }; doCheck = true; meta = { description = "A program that produces a familiar, friendly greeting"; longDescription = '' GNU Hello is a program that prints "Hello, world!" when you run it. It is fully customizable. ''; homepage = http://www.gnu.org/software/hello/manual/; license = stdenv.lib.licenses.gpl3Plus; maintainers = [ stdenv.lib.maintainers.eelco ]; platforms = stdenv.lib.platforms.all; }; }
  11. 29.

    Nixpkgs (https://github.com/NixOS/nixpkgs) 例のようなNix式が大量に集まったレポジトリ パッケージの数は > 8000 ex: $ nix-instantiate --eval

    --expr "with builtins; length (attrNames (import <nixpkgs> {}))" 普段使うソフトウェアは大体ある (chromium, vlc, libreoffice, etc.)
  12. 38.

    NixOSのコンフィグ hardware = { cpu.intel.updateMicrocode = true; opengl.extraPackages = with

    pkgs; [ vaapiIntel ]; trackpoint = { enable = true; emulateWheel = true; speed = 250; sensitivity = 140; }; pulseaudio.enable = true; };
  13. 39.

    NixOSのコンフィグ networking = { hostName = "dn"; networkmanager.enable = true;

    extraHosts = '' #0.0.0.0 twitter.com 0.0.0.0 tweetdeck.twitter.com ''; };
  14. 40.

    NixOSのコンフィグ virtualisation = { libvirtd = { enable = true;

    enableKVM = true; }; docker.enable = true; lxd.enable = true; };
  15. 41.

    NixOSのコンフィグ services.xserver = { autorun = true; defaultDepth = 24;

    enable = true; videoDrivers = [ "intel" ]; displayManager = { lightdm = { enable = true; background = "${background}"; }; }; windowManager = { default = "xmonad"; xmonad = { enable = true; enableContribAndExtras = true; }; }; ...
  16. 42.

    NixOSのコンフィグ users = { extraUsers.delta = { isNormalUser = true;

    uid = 1000; extraGroups = [ "wheel" "networkmanager" "libvirtd" "docker" "lxd" ]; hashedPassword = "..."; }; defaultUserShell = "${pkgs.zsh}/bin/zsh"; mutableUsers = false; };
  17. 45.
  18. 46.
  19. 47.

    参考文献 - https://nixos.org/nixpkgs/manual/ - https://nixos.org/nix/manual/ - https://learnxinyminutes.com/docs/nix/ - https://nixos.org/nixos/nix-pills/index.html -

    https://github.com/NixOS/nixpkgs/issues/25371 - http://blog.timsears.com/posts/morenix.html - https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/hello/default.nix - https://github.com/Tokyo-NixOS/presentations - https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/trivial-builders.nix - https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh - https://nixos.org/nixops/manual/ - https://www.youtube.com/watch?v=w1radFbG1GU