# Is it possible for us to remove builtins.functionArgs?

**URL:** https://discourse.nixos.org/t/is-it-possible-for-us-to-remove-builtins-functionargs/51960
**Category:** Nixpkgs Architecture
**Created:** [September 11, 2024, 4:35am UTC](https://discourse.nixos.org/t/is-it-possible-for-us-to-remove-builtins-functionargs/51960 "2024-09-11T04:35:34Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![luochen1990](https://discourse.nixos.org/user_avatar/discourse.nixos.org/luochen1990/32/3092_2.png) [@luochen1990](https://discourse.nixos.org/u/luochen1990)
#### Post date: [September 11, 2024, 4:35am UTC](https://discourse.nixos.org/t/is-it-possible-for-us-to-remove-builtins-functionargs/51960/1 "2024-09-11T04:35:34Z")

</div>

The drawback of `builtins.functionArgs` is that when we write `{lib, pkgs, ...}@args: { x = args.x}`, if the function is called by `callPackage` or a similar mechanism that uses `builtins.functionArgs`, we actually cannot retrieve the `x` field as expected.

The difficulty in removing `builtins.functionArgs` lies in the fact that this built-in function is heavy used by [callPackage](https://nixos.org/guides/nix-pills/13-callpackage-design-pattern#implementing-callpackage).

A possible solution is to add `...` at the end of the parameter list of the code for all packages, like `{lib, pkgs, ...}: {}`, to avoid relying on `builtins.functionArgs`. I’m not sure if this is feasible or what potential issues might arise, so I’m initiating this discussion.

---

<div class="post-metadata">

### Author: ![jtojnar](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jtojnar/32/70_2.png) [@jtojnar](https://discourse.nixos.org/u/jtojnar)
#### Post date: [September 11, 2024, 5:44am UTC](https://discourse.nixos.org/t/is-it-possible-for-us-to-remove-builtins-functionargs/51960/2 "2024-09-11T05:44:51Z")

</div>

Also relevant, this deferred RFC: [[RFC 0058] Named Ellipses by deliciouslytyped · Pull Request #58 · NixOS/rfcs · GitHub](https://github.com/NixOS/rfcs/pull/58)

---

<div class="post-metadata">

### Author: ![Atemu](https://discourse.nixos.org/user_avatar/discourse.nixos.org/atemu/32/10383_2.png) [@Atemu](https://discourse.nixos.org/u/Atemu)
#### Post date: [September 12, 2024, 12:56am UTC](https://discourse.nixos.org/t/is-it-possible-for-us-to-remove-builtins-functionargs/51960/3 "2024-09-12T00:56:41Z")

</div>

I’d rather like to question the need for individual packages as function parameters; obviating `callPackage` entirely. Why couldn’t we just pass all `pkgs`?

The only thing it really affords us is to override the meaning of package names but the same could be achieved using `pkgs // { foo = ...; }` or overlays/extensions.

---

<div class="post-metadata">

### Author: ![roberth](https://discourse.nixos.org/user_avatar/discourse.nixos.org/roberth/32/5488_2.png) [@roberth](https://discourse.nixos.org/u/roberth)
#### Post date: [November 10, 2024, 9:00pm UTC](https://discourse.nixos.org/t/is-it-possible-for-us-to-remove-builtins-functionargs/51960/4 "2024-11-10T21:00:39Z")

</div>

Short answer: no. Removing a non-experimental builtin supported since `nixpkgs/lib/minver.nix` (2.3) breaks expressions. Makes talk of reproducibility kind of moot.

Long answer: `functionArgs` is an ugly capability that turns nice and simple laws into mere rules of thumb. One rule comes to mind, but there’s probably a lot more: eta expansion isn’t a guaranteed correct refactor: `functionArgs (x: f x)` is `{}` and often not equal to `functionArgs f`.  
So while we can’t remove it, we can choose not to use it.

I’ve played with that in [Single package fixpoint by roberth · Pull Request #296769 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/pull/296769), but I ended up using it anyway, because otherwise more boilerplate would be needed. I think the main thing that PR demonstrated wrt `functionArgs` is that we can have an incremental migration path to a different solution/solutions that solve the flaws of `callPackage`.

In `package.nix` files, you’d pick a new solutions like this:

```diff
-({ stdenv, fetchurl, zlib }:
+{ mkPackageWithDeps }: mkPackageWithDeps ({ stdenv, fetchurl, zlib }:

```

* * *

> [@Atemu](#):
>
> Why couldn’t we just pass all `pkgs`?

I believe one reason is cross compilation splicing, although that _seems_ solvable.  
The other one I believe is that doing overrides with `pkgs // { ... }` will produce many large attrsets, which is quite inefficient.  
An alternate representation like [feat: persistent lists by ConnorBaker · Pull Request #11767 · NixOS/nix · GitHub](https://github.com/NixOS/nix/pull/11767) or perhaps [[WIP] Lazy attribute names by infinisil · Pull Request #4154 · NixOS/nix · GitHub](https://github.com/NixOS/nix/pull/4154) might improve that.

---

<div class="post-metadata">

### Author: ![emily](https://discourse.nixos.org/user_avatar/discourse.nixos.org/emily/32/1628_2.png) [@emily](https://discourse.nixos.org/u/emily)
#### Post date: [November 10, 2024, 9:06pm UTC](https://discourse.nixos.org/t/is-it-possible-for-us-to-remove-builtins-functionargs/51960/5 "2024-11-10T21:06:46Z")

</div>

If we’re redesigning `callPackage`/`mkDerivation`, we don’t need splicing and shouldn’t propagate it. I link to [simpler, saner cross-compilation · Issue #227327 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/issues/227327) all the time these days, but it really is the ideal we should be approaching, and would certainly not require any `builtins.functionArgs`.

---

<div class="post-metadata">

### Author: ![Atemu](https://discourse.nixos.org/user_avatar/discourse.nixos.org/atemu/32/10383_2.png) [@Atemu](https://discourse.nixos.org/u/Atemu)
#### Post date: [November 10, 2024, 9:54pm UTC](https://discourse.nixos.org/t/is-it-possible-for-us-to-remove-builtins-functionargs/51960/6 "2024-11-10T21:54:00Z")

</div>

> [@roberth](#):
>
> I believe one reason is cross compilation splicing, although that _seems_ solvable.

Regardless of the simpler cross design @emily linked which I also support, you can also just make `pkgs` itself spliced and it should work the same. See [splice.nix: make `pkgs` `splicedPackages` by Artturin · Pull Request #349316 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/pull/349316)
