packaging - Tokyo-NixOS/Tokyo-NixOS-Meetup-Wiki GitHub Wiki
ããã±ãŒãžã¯Nix Expressionã§å®çŸ©ãããŸãã
Nix Expressionã¯ããã±ãŒãžãäœãã¬ã·ããšãèããããŸãã
ããã±ãŒãžãããã±ãŒãžã¬ããžããªïŒnixpkgsïŒãåç¬ãã¡ã€ã«ã§ç®¡çã§ããŸãã
ã§ã¯æ©éããã±ãŒãžãå®çŸ©ããNix Expressionã確èªããŸãããã
{ stdenv, fetchurl }:
stdenv.mkDerivation {
name = "hello-2.10";
src = fetchurl {
url = "mirror://gnu/hello/hello-2.10.tar.gz";
sha256 = "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i";
};
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;
};
}
Nixèšèªã«æ £ããŠããªããšããªããããã«ããã§ããã ããã§å€§äºãªãã€ã³ãã¯ããã±ãŒãžå®çŸ©ã¯é¢æ°ã§ããããšã§ãã
è¡ããšã確èªããŸãããããŸãã¯
{ stdenv, fetchurl }:
Nixèšèªã®é¢æ°ã®æžãæ¹ã§ãã{
ãš}
ã«å²ãŸããã®ã¯é¢æ°ã®åŒæ°ã:
ã®åŸã¯é¢æ°ã®æ¬äœãšãªããŸãã
äŸãã°ã{ a, b }: a + b
ã¯a
ãšb
ã足ãé¢æ°ã«ãããŸãã
ãã®é¢æ°ã®åŒæ°ã¯stdenv
ãšfetchurl
ã§ãããŸã
ã
-
stdenv
ã¯standard environment(æšæºç°å¢)ã®ç¥ã§ãããŸããããã±ãŒãžããã«ãã§ããäžè¬ããŒã«ãå«ããŸãã -
fetchurl
ã¯urlãšããã·ã¥ã§æãããã¡ã€ã«ãããŠã³ããŒãã§ããé¢æ°ãfetchurl
以å€ã«ã¯GitHubãããã¡ã€ã«ãããŠã³ããŒãããfetchFromGitHub
ãªã©ã®é¢æ°ããããŸãã
ã§ã¯äžè¡ç®ã¯stdenv
ãšfetchurl
åŒæ°ããã£ãé¢æ°ãå®çŸ©ããŸãã
次ã®è¡ã¯
stdenv.mkDerivation {
ãšãªããŸãã
åŒæ°ã§æž¡ãããstdenv
ãå©çšããŸãã
stdenv
ã¯ã»ããã§ãããŸãïŒã»ããã¯äžè¬ã®ããŒããªã¥ãŒããŒã¿æ§é ã§ãããŸãïŒã
Nixèšèªã§ã¯s.k
ã¯s
ã»ããã®k
ããŒã®ããªã¥ãŒãè¿ããŸãã
ã»ããã¯{}
ã§å®çŸ©ã§ããŸããäŸ:{ a = 1; x = "foo"; }
ãã»ããã¯é¢æ°ã®é ã«ãã䌌ãŠããŸãããå¥ãªãã®ãšãªããŸãã®ã§ééããªãããã«æ³šæããŸãããã
mkDerivation
ã¯stdenv
ã§å®çŸ©ãããé¢æ°ã§ãã
mkDerivation
ã®åŒæ°ã¯ç¹å®ãªããŒããã£ãã»ããã§ãçµæã¯derivation(å°åº)ã§ãããŸãã
å°åºã¯å€å°ãããã¥ããæŠå¿µã§ããã®ã§ãä»ã®ãšããã¯ç°¡åã«ããã±ãŒãžã¬ã·ããšãã«ããããããã±ãŒãžã®äžéçãªç©ãšèããã°ããã§ãã
ã¡ãªã¿ã«ãmkDerivation
ã®mk
ã¯makeã®ç¥ã§ãã£ãŠãmkDerivation
ãå°åºçæããšæå³ããŸãã
æçã®äŸããç¶ããŸããšãããªæãã«ãªããŸã
{ ãããã³, è²·ãç©ãã }:
æçãäœã {
# ãããã
}
ãŸã äºè¡ç®ã§ããã説æã¯ã»ãŒå®äºããŠããŸãã
ã®ããã¯mkDerivation
ã®åŒæ°ã®åœ¢åŒã ãã§ãã
mkDerivation
ã®åŒæ°ã»ããã«å€ãã®ãªãã·ã§ã³ããããŸãã
ãã¹ãŠããããå¿
èŠã¯ãªãã§ãããåºæ¬ãããããšããã±ãŒãžã¯äœããããã
å¿ é ãªé ç®ã¯2ã€ã ãã§ã:
-
name
: ããã±ãŒãžã®åå(ããŒãžã§ã³ãå«ã) -
src
: ããã±ãŒãžã®ãœãŒã¹ãã¡ã€ã«
äžè¬çãªmakeç³»ããã±ãŒãžã§ããã°ããã®2ã€ãå®çŸ©ããã ãã§èªåçã«ããã±ãŒãžããã«ããããŸãïŒ
ã§ã¯äŸã®ããã±ãŒãžã§ãã®ããŒã確èªããŸããã:
name = "hello-2.10";
â»: Nixèšèªã§ã¯ã»ããå
ã®;
ã¯ããŒããªã¥ãŒãã¢ã®ã»ãã¬ãŒã¿ãŒãšãªããŸãã
äœãããã±ãŒãžã®ååã¯hello-2.10
ã§ãããšæå³ããŸãã
ããŒãžã§ã³çªå·ãšååãåããæžãæ¹ããã䜿ãããŠããŸããhello-2.10
ã®å Žåã¯ãã®ããã«ãªããŸãã
version = "2.10";
name = "hello-${version}";
â»: name
ãversion
ã®äžã«æžãå Žåã¯rec
ããŒã¯ãŒãã䜿ã£ãŠååž°ã»ãããšå®£èšããå¿
èŠããããŸã: rec { name = "hello-${version}"; version = "2.10"; }
次ã¯src
ããŒã§ããsrc
ã¯ããã±ãŒãžã®ãœãŒã¹ãã¡ã€ã«ãå®çŸ©ããŸãã
ããŒã«ã«ãã¡ã€ã«ãå®çŸ©ããäºãã§ããŸããã倧æµã®å Žåã¯ããããããœãŒã¹ãååŸããŸãã
src = fetchurl {
url = "mirror://gnu/hello/hello-2.10.tar.gz";
sha256 = "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i";
};
hello
ã®å Žåã¯src
ã®å€ã¯fetchurl
é¢æ°ãšãã®åŒæ°ãšãªããŸãã
fetchurl
é¢æ°ã¯urlãšããã·ã¥ãå©çšããurlã«è©²åœãããã¡ã€ã«ãããŠã³ããŒãããŠãããŠã³ããŒããããã¡ã€ã«ã®ããã·ã¥ãåŒæ°ã®ããã·ã¥ãšæ¯èŒããŸãã
ãœãŒã¹ãããã°ãNixã¯æšæºæ¹æ³ã§configure
ãšmake
ããããã±ãŒãžããã«ããšã€ã³ã¹ããŒã«ããŸãã
äŸã§æ®ãã®ããŒã¯meta
ãšãªããŸãã
meta
ã¯ã»ããã§ãã£ãŠãããã±ãŒãžã®ã¡ã¿æ
å ±ã宣èšããŸãã
ã¡ã¿æ
å ±ã¯ãã«ãã«åœ±é¿ãã»ãšãã©ããªãã§ãäž»ã«å€éšããŒã«ãšé£æºã«äœ¿ãããŠããŸãã
ã§ã¯hello
ã§èšå®ãããŠããmeta
ã®ããŒã確èªããŸããã:
-
description
: ããã±ãŒãžã®äžè¡çŽ¹ä» -
longDescription
: ããã±ãŒãžã®è©³çŽ°çŽ¹ä» -
homepage
: ããã±ãŒãžã®ããŒã ããŒãž -
license
: ããã±ãŒãžã®ã©ã€ã»ã³ã¹ -
maintainers
: ããã±ãŒãžã®ã¡ã³ãã -
platforms
: ããã±ãŒãžã察å¿ãããã©ãããã©ãŒã
ã§ã¯æåŸã«ã®ãäžåºŠhello
ã®Nix Expressionã確èªããŸããã
# stdenvãšfetchurlåŒæ°ã®é¢æ°ãå®çŸ©
{ stdenv, fetchurl }:
# stdenv.mkDerivationé¢ããåŒã³åºããã»ãããåŒæ°ã§æž¡ããŸã
stdenv.mkDerivation rec {
# ããã±ãŒãžåãšããŒãžã§ã³
name = "hello-2.10";
# ãœãŒã¹ãã¡ã€ã«ãfetchurlé¢æ°ã§ååŸ
src = fetchurl {
# rec ã§ååž°ã»ããã䜿ãããã«nameããŒãåç
§ã§ããŸã
url = "mirror://gnu/hello/${name}.tar.gz";
sha256 = "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i";
};
# ããã±ãŒãžã®ã¡ã¿æ
å ±
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;
};
}
hello
ã¯ãšãŠãåçŽãªããã±ãŒãžã§ãã£ãŠãæšæºãã«ãã«ãã¹ãŠããŸããããŠããã«ãã§ããŸããããç°¡åã«è¡ããªãããã±ãŒãžãå€ããããŸãã
ãã®ããmkDerivation
ã«æž¡ãã»ããã«ã¯ãããããªãªãã·ã§ã³ããããŸãã(ããã¥ã¡ã³ããŒã·ã§ã³)
ãã¹ãŠã®ãªãã·ã§ã³ã説æãããšéã«æ··ä¹±ããã®ã§ããŸãã¯åºæ¬ã®ä»çµã¿ã玹ä»ããŸãã
ãã«ãã¯ãã§ãŒãºã§å¥ããŠããŸããæžããã§ãŒã¹ã¯ãã«ãã®äžã€ã®æ®µéã管çããŸãã
æšæºãã§ãŒãºã¯:
- 解åãã§ãŒã¹(
unpackPhase
): ãœãŒã¹ãã¡ã€ã«ã解åãããã§ãŒãº - ããããã§ãŒãº(
patchPhase
): ãœãŒã¹ãã¡ã€ã«ãããããããã§ãŒãº - èšå®ãã§ãŒãº(
configurePhase
): ãœãŒã¹ãã¡ã€ã«ããã«ãæºåããŸããããã©ã«ãã§ã¯./configure
ãå®è¡ããŸãã - ãã«ããã§ãŒãº(
buildPhase
): ãœãŒã¹ãã¡ã€ã«ãã³ã³ãã€ã«ããŸããããã©ã«ãã§ã¯make
ãå®è¡ããŸãã - ãã§ãã¯ãã§ãŒãº(
checkPhase
):doCheck
ããŒãtrue
ã®å Žåã¯ãã«ãããã§ãã¯ããŸããããã©ã«ãã§ã¯å®è¡ãããªããã§ãŒãºã - ã€ã³ã¹ããŒã«ãã§ãŒãº(
installPhase
): Nixã¹ãã¢ã«ããã±ãŒãžãã€ã³ã¹ããŒã«ãããã§ãŒãºãããã©ã«ãã§ã¯make install
ãå®è¡ããŸãã - ãã£ãã¯ã¹ãã§ãŒãº(
fixupPhase
): ããã±ãŒãžã«Nixå°çšã®ä¿®æ£ãããŸãã - é
åžãã§ãŒãº(
distributionPhase
):doDist
ããŒãtrue
ã®å Žåã«é åžçšã®ãã¡ã€ã«ãäœæãããã§ãŒã¹ã§ããããã©ã«ãã§ã¯å®è¡ãããŸããã
ãã¹ãŠã®ãã§ãŒãºã¯ãã§ãŒãºçèåãšãã§ãŒãºå®è¡åŸã®ããã¯ããããŸããäŸãã°unpackPhase
ã®å Žåã¯preUnpack
ãšpostUnpack
ãå©çšã§ããŸãã
åãã§ãŒãºã«ã¯å°çšãªããŒããããŸãããã®äžã§ãã䜿ããã®ã¯
-
patchPhase
:-
patches
: åœãŠããããã®é åã§ããããŒã«ã«ãã¡ã€ã«ãšãããã¯ãŒã¯ããããŠããŒããããã¡ã€ã«ãå©çšã§ããŸã``` patches = [ ./my-patch.patch (fetchpatch { name = ...; url = ...; sha256= ...; }) ]; ```
-
-
buildPhase
:-
makeFlags
:make
ã«æž¡ããã©ã°``` makeFlags = [ "-DBUILD_icons=TRUE" "-DBUILD_plasma=TRUE" ]; ```
-
äŸåé¢ä¿ã¯buildInputs
ããŒã§ç®¡çããŸãã
äŸãã°ããã±ãŒãžã«gtk
äŸåãè¿œå ããå Žåã¯é¢æ°é ãšbuildInputs
ã«gtk
ãè¿œå ããã°ããã§ãã(meta
çç¥)
{ stdenv, fetchurl, gtk }:
stdenv.mkDerivation rec {
name = "hello-2.10";
src = fetchurl {
url = "mirror://gnu/hello/${name}.tar.gz";
sha256 = "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i";
};
buildInputs = [ gtk ];
}
ããŸã«ãœãŒã¹ä»¥å€ã«ããŒã¿ãã¡ã€ã«ãå¿
èŠãšããããã±ãŒãžããããŸãããã®å Žåã§ã¯let
ãå©çšãããã®ããŒã¿ãã¡ã€ã«æ
å ±ãmkDerivation
ã®ã¹ã³ãŒãã«ãã£ãŠããã該åœãã§ãŒãºã§å©çšããŸãã
fcitx-mozc
ããã±ãŒãžããã®äŸ:
{ clangStdenv, fetchFromGitHub, fetchurl, fetchpatch, fetchsvn, gyp, which, ninja,
python, pkgconfig, protobuf, gtk, zinnia, qt4, libxcb, tegaki-zinnia-japanese,
fcitx, gettext }:
let
japanese_usage_dictionary = fetchsvn {
url = "http://japanese-usage-dictionary.googlecode.com/svn/trunk";
rev = "10";
sha256 = "0pyrpz9c8nxccwpgyr36w314mi8h132cis8ijvlqmmhqxwsi30hm";
};
icons = fetchurl {
url = "http://download.fcitx-im.org/fcitx-mozc/fcitx-mozc-icon.tar.gz";
sha256 = "10bdjn481jsh32vll7r756l392anz44h6207vjqwby3rplk31np1";
};
in clangStdenv.mkDerivation rec {
name = "fcitx-mozc-${version}";
version = "2.17.2313.102";
src = fetchFromGitHub {
owner = "google";
repo = "mozc";
rev = "3306d3314499a54a4064b8b80bbc1bce3f6cfac4";
sha256 = "0l7mjlnbm6i1ipni8pg9ym5bjg3rzkaxi9xwmsz2lddv348sqii2";
};
nativeBuildInputs = [ gyp which ninja python pkgconfig ];
buildInputs = [ protobuf gtk zinnia qt4 libxcb fcitx gettext ];
postUnpack = ''
rmdir $sourceRoot/src/third_party/japanese_usage_dictionary/
ln -s ${japanese_usage_dictionary} $sourceRoot/src/third_party/japanese_usage_dictionary
tar -xzf ${icons} -C $sourceRoot
'';
japanese_usage_dictionary
ãšicons
ã¯src
ãšå¥å§çž®ãã¡ã€ã«ãšãªããŸãããããã±ãŒãžãã«ãã«ã¯å¿
èŠã§ãã
src
ã解åããåŸã«ãpostUnpack
ã§japanese_usage_dictionary
ããã«ããã©ã«ããŒã«ãªã³ã¯ããã¢ã€ã³ã³
ãã£ãããã¡ã€ã«ããã«ããã©ã«ããŒã«è§£åããŸãã
ããã±ãŒãžãäœæããåã«ã¯ããã±ãŒãžãnixpkgsã§ååšããªãã®ã確èªããŸãããã
äœæã«ã¯2ã€ã®æ¹æ³ããããŸã
- ããŒã«ã«nixpkgsã¯ããŒã³ãå©çš: ã¬ããžããªã®æºåã®æéããããŸãããããŒã«ãªã¯ãšã¹ãããããã§ã
- åç¬ããã±ãŒãž: ç°¡åã«äœããŸãããPRãããéã«ã¬ããžããªã®ã¯ããŒã³ã®é¢ãã®é ã®ä¿®æ£ãå¿ èŠãšãªããŸã
åå¿è ã«åã£ãŠäžçªãªåç¬ããã±ãŒãžã®æ¹æ³ãã玹ä»ããŸãã
å©ç¹ãšããŠã¯
- é¢æ°é ãã·ã³ãã«ã§æžã
- Nix expressionã ãã§ããã±ãŒãžããã«ãã§ããŸã
hello
ããã±ãŒãžã®åç¬ããŒãžã§ã³ãèŠãŸããã
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
stdenv.mkDerivation rec {
name = "hello-2.10";
src = fetchurl {
url = "mirror://gnu/hello/${name}.tar.gz";
sha256 = "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i";
};
}
â» åç¬ããã±ãŒãžã¯å€éšããŒã«ã®ã®é£æºã¯ãªãã®ã§ãmeta
ããŒã¯å¿
èŠå
ã§ãã
ãã®Nix expressionãhello.nix
ã«ä¿åããŠãnix-build hello.nix
ãå®è¡ããã°ãããã±ãŒãžããã«ãã§ããŸãã
ãã«ããããçµæã¯nix-build
ãå®è¡ããããã©ã«ããŒã«result
ãšèšã£ãNixã¹ãã¢ããã±ãŒãžãžã®ãªã³ã¯ãäœããŸãã
å®è¡å¯èœããã°ã©ã ã¯./result/bin/
以äžã«å
¥ã£ãŠããŸãã®ã§ãå®è¡ãè©ŠããŸãããã
nixpkgs
ã§ã®ããã±ãŒãžã®æžãæ¹ãšæ¯ã¹ãŠãé¢æ°é ããå€ãããªãã§ãã
ã§ã¯åæããŸããã:
{ pkgs ? import <nixpkgs> {} }:
å€å°ãããã«ããã®ã§ãæ¬åŒ§ãã€ããŸããã
{ pkgs ? ((import <nixpkgs>) {}) }:
ãã®çãèšè¿°ã§ããããããã£ãŠããŸãã
ãŸãã¯{ pkgs }:
ã¯pkgs
ãåŒæ°ãå©çšããé¢æ°é ã§ãïŒé¢æ°é ã¯ã»ãããšç°ãªã£ãŠ:
ãã€ããŠããŸãïŒ
é¢æ°é ã§{ var ? "value" }:
ã¯var
åŒæ°ã«"value"
ããã©ã«ãå€ãèšå®ããŸããèšãæ¹ãå€ããŠãvar
ãæž¡ãããŠããªãå Žåã«var
ã"value"
ã«ããŸãã
ä»åã®äŸã§ã¯pkgs
åŒæ°ã®ããã©ã«ãããªã¥ãŒãimport <nixpkgs> {}
ã«ããŸãã
import <nixpkgs> {}
ã«åªå
ãè¡šãæ¬åŒ§ãã€ãããš((import <nixpkgs>) {})
ã«ãªããŸãã
import
ã¯Nixã®ãã«ãã€ã³é¢æ°ã§ãããŸããimport
ã§Nix Expressionãæåéãã«ã€ã³ããŒãã§ããŸãã
<nixpkgs>
ã¯ç¹å¥çç¥ã§ãããNIX_PATH
ç°å¢å€æ°ã§å®çŸ©ãããnixpkgs
ãæããŸãã
<nixpkgs>
ã®ãã¹ã¯æ¬¡ã®ã³ãã³ãã§ç¢ºèªã§ããŸã:
# echo $NIX_PATH
ã§import
é¢æ°ã¯ãã¹ããã©ã«ããŒãæž¡ãããæã«default.nix
ãèªã¿èŸŒã¿ãŸãã®ã§ãNIX_PATH
ã®default.nix
ãã€ã³ããŒãããŸãã
æåŸã®ããŒãã¯((import <nixpkgs>) {})
ã®{}
ã§ããã€ã³ããŒããããdefault.nix
ã¯é¢æ°ã§ããããã«åŒæ°ãæž¡ããªããšçµæãåž°ã£ãŠããªãã§ãã
ç¹å¥ãªåŒæ°ãæž¡ãå¿
èŠã¯å
ã®ã§ã空ã»ãã{}
ãæž¡ããŸãã
説æã倧åé·ããªããŸããããäžèšã§ãŸãšãããš{ pkgs ? import <nixpkgs> {} }:
ã¯pkgs
åŒæ°ã«nixpkgs
ãèªã¿èŸŒãŸããŸãã
次ã®è¡ã«åºãŠããwith pkgs;
ã¯pkgs
ã®ããŒã次ã®expressionã®ã¹ã³ãŒãã«å
±æããŸãã
ç°¡åã«ãããŸããšstdenv
ãšfetchurl
ãpkgs
ã«å«ãŸããŠããã®ã§ãwith
ã®ãããã§pkgs.stdenv.mkDerivation
ãpkgs.fetchurl
ãæžãå¿
èŠããªããpkgs
ãçç¥ã§ããŸãã
åç¬ããã±ãŒãžã®äœæãçµãã£ãããnixpkgs
ã«ç»é²ããäºã¯ã§ããŸãã
ãŸãã¯ããŒã«ã«ã«nixpkgs
ã®ã¯ããŒã³ãäœããŸã:
# git clone https://github.com/NixOS/nixpkgs.git
# cd nixpkgs
nixpkgs
ã«ã¯Nixã§å©çšãã¹ãŠã®ããã±ãŒãžãšNixOSé¢é£ã®ãœãŒã¹ã³ãŒãã管çãããŠããŸãã
ãããã¬ãã«ãã©ã«ããŒã¯
-
doc
:nixpkgs
ã®ããã¥ã¡ã³ããŒã·ã§ã³ -
lib
: Nixèšèªã®ã©ã€ãã©ãªé¢æ° -
maintainers
: ã¡ã³ããçšã®ã¹ã¯ãªããç -
nixos
: NixOSé¢é£ã³ãŒã -
pkgs
: ããã±ãŒãž
ããã±ãŒãžã¯pkg
ãã©ã«ããŒã®äžã«å
¥ããŸããpkg
以äžã¯ã«ããŽãªæ¯ã«ãã©ã«ããŒããããŸãã
ããã±ãŒãžãã©ã®ãã©ã«ããŒã«çœ®ãã«ã«ãŒã«ãææ§ã§ãäžçªã«ã³ã¿ã³ã®ã¯äŒŒãããã±ãŒãžãæ¢ãããã®ããã±ãŒãžãšåãã«ããŽãªã«çœ®ãã°è¯ãã§ãã
äŸãšããŠã¯å
çšã®åç¬ããã±ãŒãžãå©çšããŸãã
hello
ã¯ãã§ã«nixpkgs
ã«ååšããŸãã®ã§ãããã±ãŒãžåãmy-hello
ã«å€æŽããŸãã
my-hello.nix
:
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
stdenv.mkDerivation rec {
name = "my-hello-2.10";
src = fetchurl {
url = "mirror://gnu/hello/${name}.tar.gz";
sha256 = "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i";
};
}
ããŒã«ãªã¯ãšã¹ãã®ããã«ããã±ãŒãžå°çšãã©ã³ããäœããŸããã:
# git checkout -b pkg/my-hello
hello
ã¯pkgs/applications/misc/
ã®äžã«ãããŸãã®ã§ãmy-hello
ãåæ§ã«pkgs/applications/misc/
ã«çœ®ããŸãããã
ãŸãã¯ãã©ã«ããŒãäœããŸãã
# mkdir pkgs/applications/misc/my-hello/
nixpkgs
ã§ã¯ããã±ãŒãžã®Nix expressionåãdefault.nix
ã«ãã決ãŸãããããŸãã
# cp my-hello.nix pkgs/applications/misc/my-hello/default.nix
次ã®ã¹ãããã¯my-hello
ãããã±ãŒãžãªã¹ãã«ç»é²ããŸããnixpkgs
ã®ããã±ãŒãžãªã¹ãã¯pkgs/top-level/all-packages.nix
ã«ãããŸãã
ããã±ãŒãžãªã¹ãã¯ç¬æžã§ãããæžãããã±ãŒãžã¯ããŒã§ãããŸãã æžãæ¹ã¯:
ã㌠= callPackage ãã¹ åŒæ°;
callPackage
ã¯import
ã®æ§ã«Nix expressionãã€ã³ããŒãããä»ã®ããã±ãŒãžãèªã¿èŸŒãã Nix expressionã®ã¹ã³ãŒãã«å
±æããŸãã
hello
ããã±ãŒãžã®èšè¿°ã確èªããŸããã
hello = callPackage ../applications/misc/hello { };
my-hello
ã®ããã±ãŒãžå®çŸ©
my-hello = callPackage ../applications/misc/my-hello { };
æ®ãã¯my-hello
ã®Nix expressionã®é¢æ°é ã®ä¿®æ£ãšmeta
ããŒã®è¿œå ã
åç¬ããã±ãŒãžã®é¢æ°é ã¯
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
callPackage
ã®ãããã§pkgs
ã®ãã¹ãŠã®ããŒã¯é¢æ°é ã§å©çšã§ããŸãã
ãã®ããNix Expressionã«å©çšããããã±ãŒãžãé¢æ°é ã«å
¥ããã°ããã§ãã
my-hello
ã¯stdenv
ãšfetchurl
ãå©çšããŸãã®ã§ã次ã®ããã«é¢æ°é ãä¿®æ£ããŸãã
{ stdenv, fetchurl }:
â» with pkgs;
ã¯äžèŠãšãªããŸãã®ã§ãè¡ããšãåé€ããŸãã
åŸã¯mkDerivation
ã®meta
ãè¿œå ããã°å®æããŸãã
hello
ããã±ãŒãžã®meta
ã»ããã確èªããŸããã
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;
};
license
ã«èšå®ããã¯stdenv.lib.licenses
ã»ããã®ããŒãšãªããŸããã©ã€ã»ã³ã¹äžèŠ§ã¯lib/licenses.nix
ã§ç¢ºèªã§ããŸãã
maintainers
ã¯ããã±ãŒãžã¡ã³ããã®ãªã¹ããšãªããŸããèªåãã¡ã³ããã«èšå®ããå Žåã¯lib/maintainers.nix
ã«èªåã®æ
å ±ãè¿œå ããå¿
èŠããããŸãã
platforms
ã¯ããã±ãŒãžã察å¿ãããã©ãããã©ãŒã ã«ãªããŸãããã©ãããã©ãŒã äžèŠ§ã¯lib/platforms.nix
ã§ç¢ºèªã§ããŸãã
ããã±ãŒãžãå®æããŸããããnix-build
ã³ãã³ãã§ãã«ãã§ããŸãã
nixpkgs
ã®ã«ãŒããã©ã«ããŒã«
# nix-build -A my-hello