electron_31-bin: mark as insecure because it's EOL
[NixPkgs.git] / nixos / doc / manual / configuration / adding-custom-packages.section.md
blobf2012d9c2462679375d75db768b396644de85f1a
1 # Adding Custom Packages {#sec-custom-packages}
3 It's possible that a package you need is not available in NixOS. In that
4 case, you can do two things. Either you can package it with Nix, or you can try
5 to use prebuilt packages from upstream. Due to the peculiarities of NixOS, it
6 is important to note that building software from source is often easier than
7 using pre-built executables.
9 ## Building with Nix {#sec-custom-packages-nix}
11 This can be done either in-tree or out-of-tree. For an in-tree build, you can
12 clone the Nixpkgs repository, add the package to your clone, and (optionally)
13 submit a patch or pull request to have it accepted into the main Nixpkgs
14 repository. This is described in detail in the [Nixpkgs
15 manual](https://nixos.org/nixpkgs/manual). In short, you clone Nixpkgs:
17 ```ShellSession
18 $ git clone https://github.com/NixOS/nixpkgs
19 $ cd nixpkgs
20 ```
22 Then you write and test the package as described in the Nixpkgs manual.
23 Finally, you add it to [](#opt-environment.systemPackages), e.g.
25 ```nix
27   environment.systemPackages = [ pkgs.my-package ];
29 ```
31 and you run `nixos-rebuild`, specifying your own Nixpkgs tree:
33 ```ShellSession
34 # nixos-rebuild switch -I nixpkgs=/path/to/my/nixpkgs
35 ```
37 The second possibility is to add the package outside of the Nixpkgs
38 tree. For instance, here is how you specify a build of the
39 [GNU Hello](https://www.gnu.org/software/hello/) package directly in
40 `configuration.nix`:
42 ```nix
44   environment.systemPackages =
45     let
46       my-hello = with pkgs; stdenv.mkDerivation rec {
47         name = "hello-2.8";
48         src = fetchurl {
49           url = "mirror://gnu/hello/${name}.tar.gz";
50           hash = "sha256-5rd/gffPfa761Kn1tl3myunD8TuM+66oy1O7XqVGDXM=";
51         };
52       };
53     in
54     [ my-hello ];
56 ```
58 Of course, you can also move the definition of `my-hello` into a
59 separate Nix expression, e.g.
61 ```nix
63   environment.systemPackages = [ (import ./my-hello.nix) ];
65 ```
67 where `my-hello.nix` contains:
69 ```nix
70 with import <nixpkgs> {}; # bring all of Nixpkgs into scope
72 stdenv.mkDerivation rec {
73   name = "hello-2.8";
74   src = fetchurl {
75     url = "mirror://gnu/hello/${name}.tar.gz";
76     hash = "sha256-5rd/gffPfa761Kn1tl3myunD8TuM+66oy1O7XqVGDXM=";
77   };
79 ```
81 This allows testing the package easily:
83 ```ShellSession
84 $ nix-build my-hello.nix
85 $ ./result/bin/hello
86 Hello, world!
87 ```
89 ## Using pre-built executables {#sec-custom-packages-prebuilt}
91 Most pre-built executables will not work on NixOS. There are two notable
92 exceptions: flatpaks and AppImages. For flatpaks see the [dedicated
93 section](#module-services-flatpak). AppImages can run "as-is" on NixOS.
95 First you need to enable AppImage support: add to `/etc/nixos/configuration.nix`
97 ```nix
99   programs.appimage.enable = true;
100   programs.appimage.binfmt = true;
104 Then you can run the AppImage "as-is" or with `appimage-run foo.appimage`.
106 If there are shared libraries missing add them with
108 ```nix
110   programs.appimage.package = pkgs.appimage-run.override {
111     extraPkgs = pkgs: [
112       # missing libraries here, e.g.: `pkgs.libepoxy`
113     ];
114   }
118 To make other pre-built executables work on NixOS, you need to package them
119 with Nix and special helpers like `autoPatchelfHook` or `buildFHSEnv`. See
120 the [Nixpkgs manual](https://nixos.org/nixpkgs/manual) for details. This
121 is complex and often doing a source build is easier.