ryan4yin / nixos-and-flakes-book

:hammer_and_wrench: :heart: Want to know NixOS & Flakes in detail? Looking for a beginner-friendly tutorial? Then you've come to the right place! 想要学习使用 NixOS 与 Flakes 吗?在寻找一份新手友好的教程?那你可来对地方了!
https://nixos-and-flakes.thiscute.world
Creative Commons Attribution Share Alike 4.0 International
2.07k stars 105 forks source link

Update overriding.md #22

Closed alexvanaxe107 closed 1 year ago

alexvanaxe107 commented 1 year ago

The override is not a funcion. It is an attribute.

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nixos-and-flakes-book ✅ Ready (Inspect) Visit Preview Aug 2, 2023 3:56pm
ryan4yin commented 1 year ago

@alexvanaxe107 According to the nixpkgs's official docs https://nixos.org/manual/nixpkgs/stable/#sec-pkg-override, override is indeed a function:

The function override is usually available for all the derivations in the nixpkgs expression (pkgs).

It is used to override the arguments passed to a function. 

Of course, the override function is an attribute of any derivation too. I don't think this change is necessary, but thank you for your contribution anyway.

alexvanaxe107 commented 1 year ago

@alexvanaxe107 According to the nixpkgs's official docs https://nixos.org/manual/nixpkgs/stable/#sec-pkg-override, override is indeed a function:

The function override is usually available for all the derivations in the nixpkgs expression (pkgs).

It is used to override the arguments passed to a function. 

Of course, the override function is an attribute of any derivation too. I don't think this change is necessary, but thank you for your contribution anyway.

No Problem. It is really ambiguous, and can be considered a function since It is an attribute that stores a function. The problem is that on nix, we don't call a function with name.function AFAIK, but name function (With space instead of dot).

In this guide he explains why it is an attribute and not a function/method. https://nixos.org/guides/nix-pills/override-design-pattern#id1430

But since in the official docs it treat as a method, I agree with you to let the way it is.

But thanks a lot for your book, it helps a lot newcomers.

ryan4yin commented 1 year ago

In this guide he explains why it is an attribute and not a function/method. https://nixos.org/guides/nix-pills/override-design-pattern#id1430

Yeah, Nix Pills says:

Note: that .override is not a "method" in the OO sense as you may think. Nix is a functional language. That .override is simply an attribute of a set.

I think you may have mixed up the concepts of method and function, function is just a general term suitable for any programming language.

According to Method (computer programming) - Wikipedia:

A method in object-oriented programming (OOP) is a procedure associated with an object, and generally also a message.

And https://en.wikipedia.org/wiki/Function_(computer_programming)

In computer programming, a function or subroutine is a sequence of program instructions that performs a specific task, packaged as a unit. This unit can then be used in programs wherever that particular task should be performed.

Generally speaking, it is not ambiguous for us to say that override is a function(but it will be a mistake to say override is a method of a derivation).