diff --git a/API_GUIDE.md b/API_GUIDE.md index 70814af..e13102c 100644 --- a/API_GUIDE.md +++ b/API_GUIDE.md @@ -288,6 +288,12 @@ and have build checks in `checks.${system}`. `packages` can be set to attrs of package definitions. +By default, the `packages.default` package's name (its attribute name in +the package set and overlay) is automatically determined from the derivation's +`pname`. In order to use a different attribute name from the package pname, +to set it in cases where it cannot be automatically determined, or to speed up +uncached evaluation, the flakelight `pname` option can be set. + To set the default package, you can set the options as follows: ```nix @@ -347,6 +353,25 @@ The above will export `packages.${system}.default`, `packages.${system}.pkg2`, `packages.${system}.pkg3` attributes, add `pkg1`, `pkg2`, and `pkg3` to `overlays.default`, and export corresponding build checks. +To use the first example, but manually specify the package name: + +```nix +{ + inputs.flakelight.url = "github:nix-community/flakelight"; + outputs = { flakelight, ... }: + flakelight ./. { + pname = "pkgs-attribute-name"; + package = { stdenv }: + stdenv.mkDerivation { + pname = "package-name"; + version = "0.0.1"; + src = ./.; + installPhase = "make DESTDIR=$out install"; + }; + }; +} +``` + ### devShell The devshell options allow you to configure `devShells.${system}.default`. It is diff --git a/builtinModules/packages.nix b/builtinModules/packages.nix index e00c8fc..cdbaf13 100644 --- a/builtinModules/packages.nix +++ b/builtinModules/packages.nix @@ -4,10 +4,10 @@ { config, lib, inputs, flakelight, genSystems, ... }: let - inherit (builtins) parseDrvName; - inherit (lib) filterAttrs mapAttrs mapAttrs' mkIf mkMerge mkOption - nameValuePair optionalAttrs; - inherit (lib.types) lazyAttrsOf nullOr uniq; + inherit (builtins) parseDrvName tryEval; + inherit (lib) filterAttrs findFirst mapAttrs mapAttrs' mkIf mkMerge + mkOption nameValuePair optionalAttrs; + inherit (lib.types) lazyAttrsOf nullOr str uniq; inherit (flakelight) supportedSystem; inherit (flakelight.types) overlay packageDef; @@ -26,6 +26,11 @@ in default = { }; }; + pname = mkOption { + type = nullOr str; + default = null; + }; + packageOverlay = mkOption { internal = true; type = uniq overlay; @@ -42,11 +47,21 @@ in packageOverlay = final: prev: let getName = pkg: pkg.pname or (parseDrvName pkg.name).name; - defaultPkgName = getName (import inputs.nixpkgs { - inherit (prev.stdenv.hostPlatform) system; - inherit (config.nixpkgs) config; - overlays = config.withOverlays ++ [ (final: _: genPkgs final) ]; - }).default; + inherit (prev.stdenv.hostPlatform) system; + baseNixpkgs = inputs.nixpkgs.legacyPackages.${system}; + + defaultPkgName = findFirst (x: (tryEval x).success) + (throw ("Could not determine the name of the default package; " + + "please set the `pname` flakelight option to the intended name.")) + [ + (assert config.pname != null; config.pname) + (getName (baseNixpkgs.callPackage config.packages.default { })) + (getName (import inputs.nixpkgs { + inherit (prev.stdenv.hostPlatform) system; + inherit (config.nixpkgs) config; + overlays = config.withOverlays ++ [ (final: _: genPkgs final) ]; + }).default) + ]; in (optionalAttrs (config.packages ? default) { ${defaultPkgName} = genPkg final config.packages.default;