mirror of
https://github.com/nix-community/flakelight.git
synced 2025-02-16 17:30:57 +01:00
Use mocked builders to get default pkg name faster
Since evaluating pkgs is expensive, this speeds up evaluation of flakes with `packages.default` by attempting to get the name using a pkgs set containing only mocked builders that just return the name.
This commit is contained in:
parent
4b9d78f35f
commit
99d8fc8a85
@ -5,8 +5,8 @@
|
|||||||
{ config, lib, inputs, flakelight, genSystems, ... }:
|
{ config, lib, inputs, flakelight, genSystems, ... }:
|
||||||
let
|
let
|
||||||
inherit (builtins) parseDrvName tryEval;
|
inherit (builtins) parseDrvName tryEval;
|
||||||
inherit (lib) filterAttrs findFirst mapAttrs mapAttrs' mkIf mkMerge
|
inherit (lib) filterAttrs findFirst mapAttrs mapAttrs' mkIf mkMerge mkOption
|
||||||
mkOption nameValuePair optionalAttrs;
|
nameValuePair optionalAttrs;
|
||||||
inherit (lib.types) lazyAttrsOf nullOr str uniq;
|
inherit (lib.types) lazyAttrsOf nullOr str uniq;
|
||||||
inherit (flakelight) supportedSystem;
|
inherit (flakelight) supportedSystem;
|
||||||
inherit (flakelight.types) overlay packageDef;
|
inherit (flakelight.types) overlay packageDef;
|
||||||
@ -49,12 +49,14 @@ in
|
|||||||
getName = pkg: pkg.pname or (parseDrvName pkg.name).name;
|
getName = pkg: pkg.pname or (parseDrvName pkg.name).name;
|
||||||
inherit (prev.stdenv.hostPlatform) system;
|
inherit (prev.stdenv.hostPlatform) system;
|
||||||
baseNixpkgs = inputs.nixpkgs.legacyPackages.${system};
|
baseNixpkgs = inputs.nixpkgs.legacyPackages.${system};
|
||||||
|
mockPkgs = import ../misc/nameMockedPkgs.nix prev;
|
||||||
|
|
||||||
defaultPkgName = findFirst (x: (tryEval x).success)
|
defaultPkgName = findFirst (x: (tryEval x).success)
|
||||||
(throw ("Could not determine the name of the default package; " +
|
(throw ("Could not determine the name of the default package; " +
|
||||||
"please set the `pname` flakelight option to the intended name."))
|
"please set the `pname` flakelight option to the intended name."))
|
||||||
[
|
[
|
||||||
(assert config.pname != null; config.pname)
|
(assert config.pname != null; config.pname)
|
||||||
|
(getName (mockPkgs.callPackage config.packages.default { }))
|
||||||
(getName (baseNixpkgs.callPackage config.packages.default { }))
|
(getName (baseNixpkgs.callPackage config.packages.default { }))
|
||||||
(getName (import inputs.nixpkgs {
|
(getName (import inputs.nixpkgs {
|
||||||
inherit (prev.stdenv.hostPlatform) system;
|
inherit (prev.stdenv.hostPlatform) system;
|
||||||
|
49
misc/nameMockedPkgs.nix
Normal file
49
misc/nameMockedPkgs.nix
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
# flakelight -- Framework for simplifying flake setup
|
||||||
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
# This is a fake pkgs set to enable efficiently extracting a derivation's name
|
||||||
|
|
||||||
|
real:
|
||||||
|
let
|
||||||
|
inherit (real) lib;
|
||||||
|
|
||||||
|
callPackageWith = autoArgs: fn: args:
|
||||||
|
let
|
||||||
|
f = if lib.isFunction fn then fn else import fn;
|
||||||
|
fargs = lib.functionArgs f;
|
||||||
|
mock = lib.mapAttrs (_: _: { }) (lib.filterAttrs (_: v: !v) fargs);
|
||||||
|
in
|
||||||
|
f (mock // builtins.intersectAttrs fargs autoArgs // args);
|
||||||
|
in
|
||||||
|
lib.fix (self: {
|
||||||
|
pkgs = self;
|
||||||
|
lib = lib // { inherit callPackageWith; };
|
||||||
|
|
||||||
|
callPackage = callPackageWith self;
|
||||||
|
|
||||||
|
stdenv = real.stdenv // {
|
||||||
|
mkDerivation = args:
|
||||||
|
if lib.isFunction args then lib.fix args else args;
|
||||||
|
};
|
||||||
|
|
||||||
|
runCommandWith = { name, ... }: _: { inherit name; };
|
||||||
|
runCommand = name: _: _: { inherit name; };
|
||||||
|
runCommandLocal = name: _: _: { inherit name; };
|
||||||
|
runCommandCC = name: _: _: { inherit name; };
|
||||||
|
writeTextFile = { name, ... }: { inherit name; };
|
||||||
|
writeText = name: _: { inherit name; };
|
||||||
|
writeTextDir = path: _: { name = builtins.baseNameOf path; };
|
||||||
|
writeScript = name: _: { inherit name; };
|
||||||
|
writeScriptBin = name: _: { inherit name; };
|
||||||
|
writeShellScript = name: _: { inherit name; };
|
||||||
|
writeShellScriptBin = name: _: { inherit name; };
|
||||||
|
writeShellApplication = { name, ... }: { inherit name; };
|
||||||
|
writeCBin = pname: _: { inherit pname; };
|
||||||
|
concatTextFile = { name, ... }: { inherit name; };
|
||||||
|
concatText = name: _: { inherit name; };
|
||||||
|
concatScript = name: _: { inherit name; };
|
||||||
|
symlinkJoin = { name, ... }: { inherit name; };
|
||||||
|
linkFarm = name: _: { inherit name; };
|
||||||
|
linkFarmFromDrvs = name: _: { inherit name; };
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user