forked from extern/flakelight
Speed up extracting default package pname
In order to speed up evalutation of flakes setting `packages.default`, this trys to compute the pname in multiple ways, ordered by speed. The pname can be set manually, which is fastest. To avoid computing a new nixpkgs and flakelight overlays, the second option just uses callPackage from stock nixpkgs. If that fails, the prior, most accurate, method is used which creates a new nixpkgs with all the overlays available.
This commit is contained in:
parent
82f9fe67c3
commit
4b9d78f35f
25
API_GUIDE.md
25
API_GUIDE.md
@ -288,6 +288,12 @@ and have build checks in `checks.${system}`.
|
|||||||
|
|
||||||
`packages` can be set to attrs of package definitions.
|
`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:
|
To set the default package, you can set the options as follows:
|
||||||
|
|
||||||
```nix
|
```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
|
`packages.${system}.pkg3` attributes, add `pkg1`, `pkg2`, and `pkg3` to
|
||||||
`overlays.default`, and export corresponding build checks.
|
`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
|
### devShell
|
||||||
|
|
||||||
The devshell options allow you to configure `devShells.${system}.default`. It is
|
The devshell options allow you to configure `devShells.${system}.default`. It is
|
||||||
|
@ -4,10 +4,10 @@
|
|||||||
|
|
||||||
{ config, lib, inputs, flakelight, genSystems, ... }:
|
{ config, lib, inputs, flakelight, genSystems, ... }:
|
||||||
let
|
let
|
||||||
inherit (builtins) parseDrvName;
|
inherit (builtins) parseDrvName tryEval;
|
||||||
inherit (lib) filterAttrs mapAttrs mapAttrs' mkIf mkMerge mkOption
|
inherit (lib) filterAttrs findFirst mapAttrs mapAttrs' mkIf mkMerge
|
||||||
nameValuePair optionalAttrs;
|
mkOption nameValuePair optionalAttrs;
|
||||||
inherit (lib.types) lazyAttrsOf nullOr uniq;
|
inherit (lib.types) lazyAttrsOf nullOr str uniq;
|
||||||
inherit (flakelight) supportedSystem;
|
inherit (flakelight) supportedSystem;
|
||||||
inherit (flakelight.types) overlay packageDef;
|
inherit (flakelight.types) overlay packageDef;
|
||||||
|
|
||||||
@ -26,6 +26,11 @@ in
|
|||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pname = mkOption {
|
||||||
|
type = nullOr str;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
|
||||||
packageOverlay = mkOption {
|
packageOverlay = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
type = uniq overlay;
|
type = uniq overlay;
|
||||||
@ -42,11 +47,21 @@ in
|
|||||||
packageOverlay = final: prev:
|
packageOverlay = final: prev:
|
||||||
let
|
let
|
||||||
getName = pkg: pkg.pname or (parseDrvName pkg.name).name;
|
getName = pkg: pkg.pname or (parseDrvName pkg.name).name;
|
||||||
defaultPkgName = getName (import inputs.nixpkgs {
|
inherit (prev.stdenv.hostPlatform) system;
|
||||||
inherit (prev.stdenv.hostPlatform) system;
|
baseNixpkgs = inputs.nixpkgs.legacyPackages.${system};
|
||||||
inherit (config.nixpkgs) config;
|
|
||||||
overlays = config.withOverlays ++ [ (final: _: genPkgs final) ];
|
defaultPkgName = findFirst (x: (tryEval x).success)
|
||||||
}).default;
|
(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
|
in
|
||||||
(optionalAttrs (config.packages ? default) {
|
(optionalAttrs (config.packages ? default) {
|
||||||
${defaultPkgName} = genPkg final config.packages.default;
|
${defaultPkgName} = genPkg final config.packages.default;
|
||||||
|
Loading…
Reference in New Issue
Block a user