!9IQChSjwSHXPPWTa:lix.systems

Lix

808 Members
Lix user channel. Feel free to discuss on-topic issues here and give each other help. For matrix.to links to the rest of the Lix channels, see: https://wiki.lix.systems/books/lix-organisation/page/matrix-rooms235 Servers

Load older messages


SenderMessageTime
16 Feb 2025
@antifuchs:asf.computerantifuchsOh wait, isn’t example 254 exactly that?04:07:53
@charles:computer.surgeryCharleskinda04:08:34
@antifuchs:asf.computerantifuchsETOOFUNCTIONAL for my brain atm04:08:37
@charles:computer.surgeryCharles 254 uses callPackageWith to construct the value for newScope, but i want to use an existing other value for that 04:09:10
@charles:computer.surgeryCharles e.g. nixpkgs.newScope 04:09:15
@charles:computer.surgeryCharles

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:computer.surgeryCharles 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:computer.surgeryCharles maybe makeScope is the wrong abstraction and i need to use callPackageWith manually, i dunno 04:28:45
@antifuchs:asf.computerantifuchsYeah, possibly. I’m not sure what the value of the scope is considering you can also do mutually-dependent packages with callPackageWith. Maybe eval speed04:32:05
@charles:computer.surgeryCharles tbh i think the point of makeScope is to avoid this exact infinite recursion issue i'm hitting 04:33:17
@llakala:matrix.orgllakala
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:matrix.orgllakalahttps://github.com/llakala/llakaLib/blob/main/lib/collectDirectoryPackages.nix04:34:06
@charles:computer.surgeryCharlesoh interesting04:34:31
@llakala:matrix.orgllakalathe noogle documentation here is also really good04:34:48
@llakala:matrix.orgllakalahere's a usage example https://github.com/llakala/llakaLib/blob/2512d32d7812b62d27d9a63017fa1e4c91214d90/flake.nix#L4204:35:42
@charles:computer.surgeryCharlesoh i think i get it, this is very clever04:37:03
@charles:computer.surgeryCharles shouldn't localWrapper // pkgs be the other way aroudn? 04:37:48
@charles:computer.surgeryCharles * shouldn't localWrapper // pkgs be the other way around? 04:37:50
@llakala:matrix.orgllakalahmm will the order matter?04:38:03
@llakala:matrix.orgllakalaI guess maybe it will04:38:18
@llakala:matrix.orgllakalathat's smart04:38:20
@charles:computer.surgeryCharlesyes, values in the latter attrset with the same name take precedence04:38:20
@llakala:matrix.orgllakalawait yeah that's VERY smart04:38:30
@llakala:matrix.orgllakalaI'll make a note to fix that tomorrow, thanks :304:38:39
@charles:computer.surgeryCharles { a = "a"; } // { a = "b"; } -> { a = "b"; } for example 04:38:49
@charles:computer.surgeryCharles wait no actually i think localWrapper // pkgs is correct 04:40:45
@charles:computer.surgeryCharlesbecause if i try flipping them i get infinite recursion, but if i don't flip them, then it works04:41:00
@llakala:matrix.orgllakalait doesn't matter as much in this case, because merging with localWrapper results in a top-level attribute localPackages, e.g. ``` { pkgs, localPackages }: ``` but the only reason I HAD to create the localWrapper attribute was because of issues with shadowing, and swapping the order would've been an alternate way to fix it04:41:05
@charles:computer.surgeryCharles i'm not sure if it works as expected, but it at least evals 04:41:12
@llakala:matrix.orgllakala
In reply to @charles:computer.surgery
because if i try flipping them i get infinite recursion, but if i don't flip them, then it works
interesting
04:41:16

Show newer messages


Back to Room ListRoom Version: 10