From cba561d1a8b71d5bd9eb6d600feddfe106620eea Mon Sep 17 00:00:00 2001 From: Bobby Rong Date: Thu, 1 Jul 2021 19:35:48 +0800 Subject: nixos: nixos/doc/manual/configuration/adding-custom-packages.xml to CommonMark --- .../adding-custom-packages.section.xml | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 nixos/doc/manual/from_md/configuration/adding-custom-packages.section.xml (limited to 'nixos/doc/manual/from_md/configuration/adding-custom-packages.section.xml') diff --git a/nixos/doc/manual/from_md/configuration/adding-custom-packages.section.xml b/nixos/doc/manual/from_md/configuration/adding-custom-packages.section.xml new file mode 100644 index 00000000000..80e3aa69212 --- /dev/null +++ b/nixos/doc/manual/from_md/configuration/adding-custom-packages.section.xml @@ -0,0 +1,81 @@ +
+ Adding Custom Packages + + It’s possible that a package you need is not available in NixOS. In + that case, you can do two things. First, you can clone the Nixpkgs + repository, add the package to your clone, and (optionally) submit a + patch or pull request to have it accepted into the main Nixpkgs + repository. This is described in detail in the + Nixpkgs + manual. In short, you clone Nixpkgs: + + +$ git clone https://github.com/NixOS/nixpkgs +$ cd nixpkgs + + + Then you write and test the package as described in the Nixpkgs + manual. Finally, you add it to + environment.systemPackages, + e.g. + + +environment.systemPackages = [ pkgs.my-package ]; + + + and you run nixos-rebuild, specifying your own + Nixpkgs tree: + + +# nixos-rebuild switch -I nixpkgs=/path/to/my/nixpkgs + + + The second possibility is to add the package outside of the Nixpkgs + tree. For instance, here is how you specify a build of the + GNU + Hello package directly in + configuration.nix: + + +environment.systemPackages = + let + my-hello = with pkgs; stdenv.mkDerivation rec { + name = "hello-2.8"; + src = fetchurl { + url = "mirror://gnu/hello/${name}.tar.gz"; + sha256 = "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"; + }; + }; + in + [ my-hello ]; + + + Of course, you can also move the definition of + my-hello into a separate Nix expression, e.g. + + +environment.systemPackages = [ (import ./my-hello.nix) ]; + + + where my-hello.nix contains: + + +with import <nixpkgs> {}; # bring all of Nixpkgs into scope + +stdenv.mkDerivation rec { + name = "hello-2.8"; + src = fetchurl { + url = "mirror://gnu/hello/${name}.tar.gz"; + sha256 = "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"; + }; +} + + + This allows testing the package easily: + + +$ nix-build my-hello.nix +$ ./result/bin/hello +Hello, world! + +
-- cgit 1.4.1