Nixpkgs/Create and debug packages: Difference between revisions
imported>Fadenb m Syntax highlighting all the code |
imported>Fadenb m use correct syntaxhighlight lexer |
||
| Line 33: | Line 33: | ||
'''example: list all available software''' from the local repository | '''example: list all available software''' from the local repository | ||
$NIXREPOS/nixpkgs | $NIXREPOS/nixpkgs | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
$ nix-env -f $NIXPKGS -qaP '*' | $ nix-env -f $NIXPKGS -qaP '*' | ||
</syntaxhighlight> | </syntaxhighlight> | ||
'''example: install software from local repository''' | '''example: install software from local repository''' | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
$ nix-env -f $NIXPKGS -i python-urlgrabber | $ nix-env -f $NIXPKGS -i python-urlgrabber | ||
</syntaxhighlight> | </syntaxhighlight> | ||
'''example: update the system''' based on your local '''$NIXREPOS''' | '''example: update the system''' based on your local '''$NIXREPOS''' | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
$ nixos-rebuild -I nixos=$NIXPKGS/nixos -I nixpkgs=$NIXPKGS switch | $ nixos-rebuild -I nixos=$NIXPKGS/nixos -I nixpkgs=$NIXPKGS switch | ||
</syntaxhighlight> | </syntaxhighlight> | ||
'''example: build an expression and put the output in to `pwd`/results''' | '''example: build an expression and put the output in to `pwd`/results''' | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
$ nix-build $NIXPKGS -A irssi | $ nix-build $NIXPKGS -A irssi | ||
</syntaxhighlight> | </syntaxhighlight> | ||
'''example: get an environment which is used to build irssi (also see nix-shell)''' | '''example: get an environment which is used to build irssi (also see nix-shell)''' | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
$ nix-build $NIXPKGS --run-env -A irssi | $ nix-build $NIXPKGS --run-env -A irssi | ||
</syntaxhighlight> | </syntaxhighlight> | ||
'''example: get a persistent environment which is used to build irssi''' | '''example: get a persistent environment which is used to build irssi''' | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
$ nix-build $NIXPKGS --run-env -A irssi --add-root | $ nix-build $NIXPKGS --run-env -A irssi --add-root | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 65: | Line 65: | ||
You have forked the relevant nix repository, but you will want to track changes in the upstream nix repo too. You can add a remote, and a corresponding branch for this. | You have forked the relevant nix repository, but you will want to track changes in the upstream nix repo too. You can add a remote, and a corresponding branch for this. | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
git remote add upstream https://github.com/NixOS/nixpkgs.git | $ git remote add upstream https://github.com/NixOS/nixpkgs.git | ||
</syntaxhighlight> | </syntaxhighlight> | ||
You can create a branch to track the upstream master branch: | You can create a branch to track the upstream master branch: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
$ git checkout -b upstream-master upstream/master | $ git checkout -b upstream-master upstream/master | ||
$ git pull | $ git pull | ||
| Line 78: | Line 78: | ||
This will put you into a branch with all the latest changes. Hydra, the build farm, regularly creates binaries, but, since people are constantly contributing to the nix repositories, it is usually the case that there are changes in the master branch which have not yet made it into the binary channel. To take advantage of available binaries you can switch to the revision which produced the binaries in your current system and apply your changes from there. You can use `nixos-version` to see the relevant short revision hash: | This will put you into a branch with all the latest changes. Hydra, the build farm, regularly creates binaries, but, since people are constantly contributing to the nix repositories, it is usually the case that there are changes in the master branch which have not yet made it into the binary channel. To take advantage of available binaries you can switch to the revision which produced the binaries in your current system and apply your changes from there. You can use `nixos-version` to see the relevant short revision hash: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
$ nixos-version | $ nixos-version | ||
14.11pre52727.5d97886 (Caterpillar) | 14.11pre52727.5d97886 (Caterpillar) | ||
| Line 85: | Line 85: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
$ nixos-version | $ nixos-version | ||
13.07pre4871_18de9f6-3c35dae (Aardvark) | 13.07pre4871_18de9f6-3c35dae (Aardvark) | ||
| Line 92: | Line 92: | ||
This string shows the Nixos release number (13.07pre4871) followed by the nixos revision used to produce your current system (18de9f6) followed by the nixpkgs revision (3c35dae). | This string shows the Nixos release number (13.07pre4871) followed by the nixos revision used to produce your current system (18de9f6) followed by the nixpkgs revision (3c35dae). | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
$ git branch | $ git branch | ||
upstream-master | upstream-master | ||
| Line 102: | Line 102: | ||
After making some changes you can commit them into your local repo: | After making some changes you can commit them into your local repo: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
$ git add foo | $ git add foo | ||
$ git commit | $ git commit | ||
| Line 108: | Line 108: | ||
Then you push your changes to your fork: | Then you push your changes to your fork: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
$ git push origin my-new-pkg | $ git push origin my-new-pkg | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 115: | Line 115: | ||
If some time has passed since you have created your fork, you will want to merge your changes with upstream and test that it still works. | If some time has passed since you have created your fork, you will want to merge your changes with upstream and test that it still works. | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
git fetch upstream | $ git fetch upstream | ||
git merge upstream | $ git merge upstream | ||
</syntaxhighlight> | </syntaxhighlight> | ||
If your merge then fails because someone else has made the same change (for example, someone else also packaged a library you have just packed for the program you want to get into nixpkgs), then you can do this: | If your merge then fails because someone else has made the same change (for example, someone else also packaged a library you have just packed for the program you want to get into nixpkgs), then you can do this: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
git rebase -i HEAD~10 | $ git rebase -i HEAD~10 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 130: | Line 130: | ||
Next you have to test if your program works with the library packaged from someone else, then do: | Next you have to test if your program works with the library packaged from someone else, then do: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
git checkout master | $ git checkout master | ||
git log --stat | $ git log --stat | ||
</syntaxhighlight> | </syntaxhighlight> | ||
and pick the commit where the library was added. Finally cherry-pick that commit into your branch: | and pick the commit where the library was added. Finally cherry-pick that commit into your branch: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
git checkout my-new-pkg | $ git checkout my-new-pkg | ||
git cherry-pick 5d97886a6a545fb20495e0837cc50fa63d2a80e1 | $ git cherry-pick 5d97886a6a545fb20495e0837cc50fa63d2a80e1 | ||
</syntaxhighlight> | </syntaxhighlight> | ||