diff --git a/builtinModules/packages.nix b/builtinModules/packages.nix index cdbaf13..1a38df1 100644 --- a/builtinModules/packages.nix +++ b/builtinModules/packages.nix @@ -5,8 +5,8 @@ { config, lib, inputs, flakelight, genSystems, ... }: let inherit (builtins) parseDrvName tryEval; - inherit (lib) filterAttrs findFirst mapAttrs mapAttrs' mkIf mkMerge - mkOption nameValuePair optionalAttrs; + 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; @@ -49,12 +49,14 @@ in getName = pkg: pkg.pname or (parseDrvName pkg.name).name; inherit (prev.stdenv.hostPlatform) system; baseNixpkgs = inputs.nixpkgs.legacyPackages.${system}; + mockPkgs = import ../misc/nameMockedPkgs.nix prev; 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 (mockPkgs.callPackage config.packages.default { })) (getName (baseNixpkgs.callPackage config.packages.default { })) (getName (import inputs.nixpkgs { inherit (prev.stdenv.hostPlatform) system; diff --git a/misc/nameMockedPkgs.nix b/misc/nameMockedPkgs.nix new file mode 100644 index 0000000..8bc0cd3 --- /dev/null +++ b/misc/nameMockedPkgs.nix @@ -0,0 +1,49 @@ +# flakelight -- Framework for simplifying flake setup +# Copyright (C) 2023 Archit Gupta +# 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; }; +})