1# pkgs.snapTools {#sec-pkgs-snapTools}
2
3`pkgs.snapTools` is a set of functions for creating Snapcraft images. Snap and Snapcraft is not used to perform these operations.
4
5## The makeSnap Function {#ssec-pkgs-snapTools-makeSnap-signature}
6
7`makeSnap` takes a single named argument, `meta`. This argument mirrors [the upstream `snap.yaml` format](https://docs.snapcraft.io/snap-format) exactly.
8
9The `base` should not be specified, as `makeSnap` will force set it.
10
11Currently, `makeSnap` does not support creating GUI stubs.
12
13## Build a Hello World Snap {#ssec-pkgs-snapTools-build-a-snap-hello}
14
15The following expression packages GNU Hello as a Snapcraft snap.
16
17``` {#ex-snapTools-buildSnap-hello .nix}
18let
19 inherit (import <nixpkgs> { }) snapTools hello;
20in snapTools.makeSnap {
21 meta = {
22 name = "hello";
23 summary = hello.meta.description;
24 description = hello.meta.longDescription;
25 architectures = [ "amd64" ];
26 confinement = "strict";
27 apps.hello.command = "${hello}/bin/hello";
28 };
29}
30```
31
32`nix-build` this expression and install it with `snap install ./result --dangerous`. `hello` will now be the Snapcraft version of the package.
33
34## Build a Graphical Snap {#ssec-pkgs-snapTools-build-a-snap-firefox}
35
36Graphical programs require many more integrations with the host. This example uses Firefox as an example because it is one of the most complicated programs we could package.
37
38``` {#ex-snapTools-buildSnap-firefox .nix}
39let
40 inherit (import <nixpkgs> { }) snapTools firefox;
41in snapTools.makeSnap {
42 meta = {
43 name = "nix-example-firefox";
44 summary = firefox.meta.description;
45 architectures = [ "amd64" ];
46 apps.nix-example-firefox = {
47 command = "${firefox}/bin/firefox";
48 plugs = [
49 "pulseaudio"
50 "camera"
51 "browser-support"
52 "avahi-observe"
53 "cups-control"
54 "desktop"
55 "desktop-legacy"
56 "gsettings"
57 "home"
58 "network"
59 "mount-observe"
60 "removable-media"
61 "x11"
62 ];
63 };
64 confinement = "strict";
65 };
66}
67```
68
69`nix-build` this expression and install it with `snap install ./result --dangerous`. `nix-example-firefox` will now be the Snapcraft version of the Firefox package.
70
71The specific meaning behind plugs can be looked up in the [Snapcraft interface documentation](https://docs.snapcraft.io/supported-interfaces).