From f34d07dd57bf0df4d0695a1067b3c12307f2bd5e Mon Sep 17 00:00:00 2001 From: Archit Gupta Date: Sat, 29 Jun 2024 16:49:38 -0700 Subject: [PATCH] Document defining packages for a subset of systems --- API_GUIDE.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/API_GUIDE.md b/API_GUIDE.md index 94ffcfb..3b24fb6 100644 --- a/API_GUIDE.md +++ b/API_GUIDE.md @@ -365,7 +365,9 @@ and have build checks in `checks.${system}`. `package` can be set to a package definition, and will set `packages.default`. -`packages` can be set to attrs of package definitions. +`packages` can be set to attrs of package definitions. If it is a function, it +will additionally get a `system` arg in addition to module args, to allow +conditionally including package definitions depending on the system. By default, the `packages.default` package's name (its attribute name in the package set and overlay) is automatically determined from the derivation's @@ -451,6 +453,26 @@ To use the first example, but manually specify the package name: } ``` +To add a package only for certain systems, you can take `system` as an arg as +follows: + +```nix +{ + inputs.flakelight.url = "github:nix-community/flakelight"; + outputs = { flakelight, ... }: + flakelight ./. { + packages = { system, ... }: if (system == "x86_64-linux") then { + pkg1 = { stdenv }: + stdenv.mkDerivation { + name = "pkg1"; + src = ./.; + installPhase = "make DESTDIR=$out install"; + }; + } else { }; + }; +} +``` + ### devShell ```