16 Feb 2025 |
antifuchs | * nixpkgs.lib.callPackageWith, that’s the one | 03:55:04 |
| * Charles RsTFM | 03:55:23 |
antifuchs | I’m not sure it’s documented 😭 | 03:55:44 |
Charles | https://nixos.org/manual/nixpkgs/unstable/#function-library-lib.customisation.callPackageWith ? | 03:56:13 |
antifuchs | Hah, oops! There we go | 03:56:23 |
raitobezarius | In reply to @charles:computer.surgery i was gonna go for builtins.functionArgs and doing it manually, but that sounds possibly better This man is going to reinvent nixpkgs if left alone | 03:56:42 |
Charles | yes | 03:56:51 |
raitobezarius | 2muchinthefuture | 03:57:08 |
Charles | in reality i'm just trying to make my dotfiles good | 03:57:34 |
Charles | using my new sprinkles thingy | 03:58:00 |
raitobezarius | Excited for the sprinkles RFC | 04:00:13 |
Charles | i briefly considered trying to write a lix plugin that provided a builtins.newSprinkle function | 04:00:48 |
Charles | also i'm not sure if callPackageWith fits the bill here because i need to combine it with the scope.callPackage too somehow | 04:03:01 |
antifuchs | Ah, hmm, yeah that’s an issue | 04:06:29 |
antifuchs | Oh wait, isn’t example 254 exactly that? | 04:07:53 |
Charles | kinda | 04:08:34 |
antifuchs | ETOOFUNCTIONAL for my brain atm | 04:08:37 |
Charles | 254 uses callPackageWith to construct the value for newScope , but i want to use an existing other value for that | 04:09:10 |
Charles | e.g. nixpkgs.newScope | 04:09:15 |
Charles | so... this works:
callPackage = fn: args:
scope.callPackage
fn
(args // (
let
loadedFn = if builtins.isFunction fn
then fn
else if builtins.isPath fn
then import fn
else builtins.throw "???";
requiresSprinkle = builtins.hasAttr
"sprinkle"
(builtins.functionArgs loadedFn);
in
if requiresSprinkle
then { sprinkle = self; }
else {}
));
| 04:24:48 |
Charles | now i'm getting infinite recursion presumably because i have packages like { foo }: (foo.override { bar = true; }) that retain the same name in my newly created scope from their original scope, but what's weird is that this wasn't happening before | 04:27:35 |
Charles | maybe makeScope is the wrong abstraction and i need to use callPackageWith manually, i dunno | 04:28:45 |
antifuchs | Yeah, possibly. I’m not sure what the value of the scope is considering you can also do mutually-dependent packages with callPackageWith. Maybe eval speed | 04:32:05 |
Charles | tbh i think the point of makeScope is to avoid this exact infinite recursion issue i'm hitting | 04:33:17 |
llakala | In reply to @charles:computer.surgery
makeScopedPackagesFromDirectoryRecursive = newScope: directory:
nixpkgs.lib.customisation.makeScope newScope (scope:
nixpkgs.lib.filesystem.packagesFromDirectoryRecursive {
inherit directory;
callPackage = fn: args:
scope.callPackage
fn
(args // { sprinkle = self; });
}
);
not to interrupt but i have to share this extremely long function name i just wrote
I wrote something similar which may be helpful as a reference | 04:33:28 |
llakala | https://github.com/llakala/llakaLib/blob/main/lib/collectDirectoryPackages.nix | 04:34:06 |
Charles | oh interesting | 04:34:31 |
llakala | the noogle documentation here is also really good | 04:34:48 |
llakala | here's a usage example https://github.com/llakala/llakaLib/blob/2512d32d7812b62d27d9a63017fa1e4c91214d90/flake.nix#L42 | 04:35:42 |
Charles | oh i think i get it, this is very clever | 04:37:03 |