Monday, November 10, 2014

Nix pill 17: nixpkgs, overriding packages

Welcome to the 17th Nix pill. In the previous 16th pill we have started to dive into the nixpkgs repository. Nixpkgs is a function, and we've looked at some parameters like system and config.

Today we'll talk about a special attribute: config.packageOverrides. Overriding packages in a set with fixed point can be considered another design pattern in nixpkgs.

Overriding a package


I recall the override design pattern from the nix pill 14. Instad of calling a function with parameters directly, we make the call (function + parameters) overridable.
We put the override function in the returned attribute set of the original function call.

Take for example graphviz. It has an input parameter xlibs. If it's null, then graphviz will build without X support.
$ nix-repl
nix-repl> :l <nixpkgs>
Added 4360 variables.
nix-repl> :b graphviz.override { xlibs = null; }
This will build graphviz without X support, it's as simple as that.

However let's say a package P depends on graphviz, how do we make P depend on the new graphviz without X support?

In an imperative world...


...you could do something like this:
pkgs = import <nixpkgs> {};
pkgs.graphviz = pkgs.graphviz.override { xlibs = null; };
build(pkgs.P)
Given pkgs.P depends on pkgs.graphviz, it's easy to build P with the replaced graphviz. On a pure functional language it's not that easy because you can assign to variables only once.

Fixed point


The fixed point with lazy evaluation is crippling but about necessary in a language like Nix. It lets us achieve something similar to what we'd do imperatively.
Follows the definition of fixed point in nixpkgs:
# Take a function and evaluate it with its own returned value.
fix = f: let result = f result; in result;
It's a function that accepts a function f, calls f result on the result just returned by f result and returns it. In other words it's f(f(f(....
At first sight, it's an infinite loop. With lazy evaluation it isn't, because the call is done only when needed.
nix-repl> fix = f: let result = f result; in result
nix-repl> pkgs = self: { a = 3; b = 4; c = self.a+self.b; }
nix-repl> fix pkgs
{ a = 3; b = 4; c = 7; }
Without the rec keyword, we were able to refer to a and b of the same set.
  1. First pkgs gets called with an unevaluated thunk (pkgs(pkgs(...)
  2. To set the value of c then self.a and self.b are evaluated.
  3. The pkgs function gets called again to get the value of a and b.
The trick is that c is not needed to be evaluated in the inner call, thus it doesn't go in an infinite loop.

Won't go further with the explanation here. A good post about fixed point and Nix can be found here.

Overriding a set with fixed point


Given that self.a and self.b refer to the passed set and not to the literal set in the function, we're able to override both a and b and get a new value for c:
nix-repl> overrides = { a = 1; b = 2; }
nix-repl> let newpkgs = pkgs (newpkgs // overrides); in newpkgs
{ a = 3; b = 4; c = 3; }
nix-repl> let newpkgs = pkgs (newpkgs // overrides); in newpkgs // overrides
{ a = 1; b = 2; c = 3; }
In the first case we computed pkgs with the overrides, in the second case we also included the overriden attributes in the result.

Overriding nixpkgs packages


We've seen how to override attributes in a set such that they get recursively picked by dependant attributes. This approach can be used for derivations too, after all nixpkgs is a giant set of attributes that depend on each other.

To do this, nixpkgs offers config.packageOverrides. So nixpkgs returns a fixed point of the package set, and packageOverrides is used to inject the overrides.

Create a config.nix file like this somewhere:
{
  packageOverrides = pkgs: {
    graphviz = pkgs.graphviz.override { xlibs = null; };
  };
}
Now we can build e.g. asciidocFull and it will automatically use the overridden graphviz:
nix-repl> pkgs = import <nixpkgs> { config = import ./config.nix; }
nix-repl> :b pkgs.asciidocFull
Note how we pass the config with packageOverrides when importing nixpkgs. Then pkgs.asciidocFull is a derivation that has graphviz input (pkgs.asciidoc is the lighter version and doesn't use graphviz at all).

Since there's no version of asciidoc with graphviz without X support in the binary cache, Nix will recompile the needed stuff for you.

The ~/.nixpkgs/config.nix file


In the previous pill we already talked about this file. The above config.nix that we just wrote could be the content of ~/.nixpkgs/config.nix.

Instead of passing it explicitly whenever we import nixpkgs, it will be automatically imported by nixpkgs.

Conclusion


We've learned about a new design pattern: using fixed point for overriding packages in a package set.

Whereas in an imperative setting, like with other package managers, a library is installed replacing the old version and applications will use it, in Nix it's not that straight and simple. But it's more precise.

Nix applications will depend on specific versions of libraries, hence the reason why we have to recompile asciidoc to use the new graphviz library.

The newly built asciidoc will depend on the new graphviz, and old asciidoc will keep using the old graphviz undisturbed.

Next pill


...we will stop diving nixpkgs for a moment and talk about store paths. How does Nix compute the path in the store where to place the result of builds? How to add files to the store for which we have an integrity hash?

Pill 18 is available for reading here.

To be notified about the new pill, stay tuned on #NixPills, follow @lethalman or subscribe to the nixpills rss.

20 comments:

CessationOfTime said...

Thanks for writing these pills, They helped me again today. You, or someone, should consider putting a book together. It would be a big improvement over Reynard's book.

Anonymous said...
This comment has been removed by the author.
Unknown said...

Hi Dear, have you been certainly visiting this site daily, if that's the case you then will certainly get good knowledge.

Carpenters Equipment

Unknown said...

Great post and creative ideas. I am happy to visit and read useful articles.I hope you continue to do the sharing through the post to the reader

For similar information about compter printer, ink & toner cartridges visit

Thanks- Supplydepot.com

Anonymous said...
This comment has been removed by the author.
Michael Jordan said...

HostOne is one of the leading providers of inexpensive Domain Name & Web hosting in Pakistan. , hosting 1000's of websites on Windows & Linux based servers. Through our superior network, world class support and innovative package, we provide a service literately like no other. Whether you are a developer, or new to the net, this our services get you everything you need and has helped us earn our solid reputation for quality and service.

Unknown said...

Thanks for sharing these great posts also check these articals
Zong monthly Whatsapp package
<-------------------------->
Mobilink free sms unlimited trick
<----------------------->
Telenor free sms unlimited trick
<-------------------------->
How to create a free website
<--------------------------->
How to check connected wifi password without root and without app
<---------------------------->
Mobilink Jazz free facebook with pictures latest trick
<---------------------------->
Zong free facebook with pics
<-------------------------->
Idea free internet and recharge 2018

คนสวย2019 said...

ฟิลเลอร์มีคุณลักษณะ



ยังไง





?
คุณลักษณะ



ของฟิลเลอร์ ช่วยสำหรับในการ







เก็บกัก



น้ำของชั้นผิวที่ได้รับการปรับแก้









หน้าตอบ ร่องปน



ลึก ฟิลเลอร์จะช่วยเติมเต็มช่องว่างให้กับเซลล์ผิวหนัง หรือเพิ่มขนาด





ให้กับผิว เทียบเคียง





ได้กับการตำหนิ





ดสปริงให้กับผิว ให้ผิวยืดหยุ่น เต่งตึงกระชับชั้นผิวเรียบเท่ากัน



ลดริ้วรอยเฉา





หร่น





ทำให้บริเวณใบหน้า



มอง



เด็กลงอย่างแจ่มแจ้ง





รวมถึง



การปรับรูปหน้า เติมเต็มรูปหน้าให้ได้ส่วน





ได้รูปเพิ่มขึ้น



แล้วก็







จะย่อยสลาย





ไปได้อย่างธรรมชาติ สำหรับหมอ



ผู้ที่มีความเชี่ยวชาญ







จะสามารถนำฟิลเลอร์ มาเติมเต็มได้ทุกส่วนของผิวฉีดฟิลเลอร์ปาก
ฉีดฟิลเลอร์ ที่ไหนดี
ฉีดฟิลเลอร์ กังนัม

joker slot said...

sexy baccarat
joker
pussy888
sexyslot casino

Madhu said...

click here to read more

kemika7384 said...

ปากทางเข้าเล่น Pussy888
แนวทางการเข้าเล่น ปากทางเข้า Pussy888 ผ่านวิถีทางต่างๆสำหรับคนใดที่กำลังมองหาปากทางเข้าเล่น วันนี้นั้นพวกเราได้จัดเตรียมกรรมวิธี และก็ กรรมวิธีเข้าเล่นเกมส์สล็อตออนไลน์ เกมส์ยิงปลา คาสิโนออนไลน์ไว้ตรงนี้แล้ว สำหรับท่านที่กำลังมองหาหนทางการเข้าเล่น โดยพวกเราขอชี้แจง ในขั้นตอนเนื้อหาของแต่ละอย่างเป็นหัวข้อ ดังนี้
1. เข้าผ่านหน้าเว็บของพวกเรา Pussy888
ปากทางเข้า Pussy888 เข้าผ่านหน้า เว็บของพุซซี่888 ได้โดยตรงเลน การเข้าผ่านที่หน้าเว็บของพวกเรา จะสามารถทำเป็นง่ายมากมากขึ้นเรื่อยๆ ตอนเช้าได้ผ่านทั้งยังทางคอมและก็โทรศัพท์เคลื่อนที่ เนื่องจากพวกเราได้ตระเตรียมพื้นที่ สำหรับล็อกอินเข้าระบบไว้ ในหน้าเว็บของพวกเราในทุกๆหน้า สามารถเข้าได้ผ่านจากทุกหน้าเว็บไซต์ ลิ้งค์ที่อยู่ด้านในเว็บนี้ ไม่ว่าจะอ่านข้อมูลที่ได้มาจากหน้าใดๆก็ตามช่องล็อกอินจะอยู่กับคุณไปในทุกๆหน้า ที่ท่านกำลังเปิดอ่าน ไม่ว่าจะเป็นผ่านมือถือ หรือ เครื่องพีซี แท็ปเล็ต ก็สามารถเข้าใช้งานได้ไม่ยาก
2. ดาวน์โหลด แอพพลิเคชั่น Pussy888
ดาวน์โหลดแอพพลิเคชั่นมาจัดตั้งให้เป็นระเบียบแล้ว ลำดับต่อไปก็จะเป็นการล็อกอินเข้าใช้งาน ปากทางเข้า Pussy888 มองหา icon รูป Pussy888 โดยเป็นไอค่อนตามแบบที่อยู่ในรูปภาพที่ปรากฏบนรูปข้างล่าง ให้เลือกที่ไอค่อนดังที่กล่าวมาแล้วข้างต้น แล้วก็จะเป็นการไปสู่ แอพพลิเคชั่น ภายหลังที่เข้าระบบในคราวแรก โดยที่ยังไม่เคยล็อกอินเข้าใช้งานมาก่อนเลย เมื่อเข้ามาในแอพพลิเคชั่น จะเป็นหน้าต่างหรือช่องให้กระทำการล็อกอิน โดยพวกเราก็กระทำการล็อกอินเข้าใช้งานเข้าไปด้วยรหัสที่สมัครไว้กับข้าราชการของเว็บ ถ้าท่านยังไม่มีรหัสสำหรับเข้าเล่น ติดต่อข้าราชการของพวกเราพอดีนี่ ลงทะเบียนสล็อต
ความพิเศษที่มีให้ สำหรับสมาชิกคนสำคัญ ทุกคน เพียงแต่ท่านสมัครเล่นเกมส์สล็อตออนไลน์ pussy888 กับพวกเราวันนี้ ก็ได้รับสิทธิพิเศษ VIP ไปเลย โบนัส 50% ตั้งแต่หนแรกที่สมัคร ฝากเพิ่มอย่างน้อยที่ 100 บาทขึ้นไป ก็ได้รับโบนัสพิเศษนี้แล้ว ความสนุกสนานที่ตื่นเต้นคุณ ในทุกวินาทีกับ เกมส์สล็อตที่นานัปการ ครบกว่า มากยิ่งกว่า ยอดเยี่ยมเกมส์สล็อตกว่า 200 เกมส์ให้ท่านได้ลุ้นมากยิ่งกว่า ที่เคย พิเศษแน่ๆ ลงทะเบียนเป็นสมาชิกใหม่เพียงแค่ 100 บาทวันนี้รับโบนัส 50% จากพวกเราไปโดยทันที สิทธิพิเศษ สำหรับสมาชิกใหม่แค่นั้น สมัครวันนี้รับไปเลยเต็มๆหรือจะเสนอแนะให้สหายได้สนุกสนาน สุดสนุก ตื่นเต้น ยิ่งไปอีกกับ โปรโมชั่น พิเศษสุดคุ้ม เมื่อเพื่อนพ้องได้โบนัส ผู้แนะนำก็ยังได้โบนัสอีกด้วย
พึงพอใจโปรโมชั่นพิเศษนี้ โปรดซักถามข้อมูลโบนัส เสนอแนะเพื่อนฝูงจากข้าราชการของพวกเรา ที่รอดูแล แล้วก็ อวย ความสบาย ให้แด่ท่าน ตลอด 1 วัน เว้นเสียแต่โปรชี้แนะเพื่อนฝูง รวมทั้ง โปรโมชั่นสมัครใหม่แล้ว พวกเรายังมีกิจกรรมใน เว็บให้ได้ร่วมบันเทิงใจอีกด้วย ไม่ว่าจะเปิด เพิ่มเติมทุกหน รับแต้มสะสมไว้แลกเปลี่ยนของขวัญใหญ่มากมาย เช่น ของขวัญใหม่สังสรรค์เว็บไซต์อย่างเป็นทางการ ด้วย รางวัล โทรศัพท์เคลื่อนที่ไอโฟน xs แบบใหม่ปัจจุบัน รวมทั้งของขวัญแบรนด์เนม ต่างๆเยอะแยะ อาทิเช่น โทรศัพท์ไอโฟน แก้วเยตำหนิ รวมทั้งของขวัญสมนาอีกเพียบเลย
918kiss
สล็อต
Pussy888

บาคาร่า said...

เพราะอะไรจำเป็นต้องเล่นเกม บาคาร่าออนไลน์
อย่างที่ทราบกันดีว่าเกมบาคาร่าออนไลน์เป็นเกมคาสิโนยอดนิยมรวมทั้งเป็นที่ชอบใจของเหล่านักเล่นเกมส์คาสิโนออนไลน์อย่างมากโดยเหตุนี้วันนี้ถ้าพึงพอใจหรือต้องการทดลองเข้ามาเล่นเกม บาคาร่าออนไลน์สามารถเข้ามาทำความรู้จักพื้นฐานถึงที่กะไว้เว็บไซต์คาสิโนของพวกเราเมื่อก่อนที่คุณจะไปเล่นเกมบาคาร่านั้นพวกเรามีเหตุมีผลที่จะบอกคุณได้ว่าเพราะเหตุใดคุณจำต้องเลือกมาเล่นเกมบาคาร่าออนไลน์กับเว็บไซต์คาสิโนของพวกเรา
เหตุผลที่คุณจำต้องเล่นเกมบาคาร่าออนไลน์กับเว็บไซต์พวกเรา
• เว็บไซต์คาสิโนของพวกเรามีเกมบาคาร่าออนไลน์ให้ท่านได้เลือกเล่นนานาประการต้นแบบ ที่สามารถจะช่วยทำให้ท่านได้รับความสนุกสนานร่าเริงความระทึกใจสำหรับในการเล่นเกมบาคาร่าที่แตกต่างออกไปโดยแบบเกมแต่ละแบบก็จะมีเงินรางวัลที่ต่างๆนาๆด้วยเหมือนกัน
• เกมบาคาร่าในเว็บไซต์ของพวกเรามีระบบระเบียบที่เสถียรเชื่อถือได้ไม่ต้องวิตกกังวลในเรื่องของข้อผิดพลาดของระบบเกมทำให้ท่านเชื่อมั่นได้เลยว่าเมื่อใดก็ตามคุณเล่นเกมบาคาร่ากับเว็บไซต์พวกเรา คุณจะได้รับการบริการที่เยี่ยมที่สุด
• บาคาร่าออนไลน์ในเว็บไซต์ของพวกเราคุณสามารถเข้ามาเล่นได้ตลอด 1 วันไม่มีทางหยุดมีบริการฝากถอนอัตโนมัติจ่ายจริงโอนเงินเร็วไม่ถึง 5 วินาที
• คุณจะได้รับโปรโมชั่นสำหรับเพื่อการเล่นเกมบาคาร่าที่นานัปการมากยิ่งกว่าเดิมทำให้ท่านได้โอกาสทำเงินจากการเล่นเกมบาคาร่าได้มากขึ้นกว่าเว็บไซต์คาสิโนอื่น
• เกมบาคาร่าเป็นเกมคาสิโนหนึ่งที่เล่นง่ายลักษณะของเกมไม่ยากเหลือเกินทำให้ผู้เล่นอีกทั้งหน้าเก่ารวมทั้งคนใหม่สามารถเข้ามาลงทะเบียนเป็นสมาชิกเล่นเกมบาคาร่ากับเว็บไซต์ของพวกเราได้
• คุณจะได้รับการเกื้อกูลในทุกๆขั้นตอนที่เข้ามาเล่นเกมบาคาร่าไม่ว่าจะเป็นตั้งแต่การถามไถ่เนื้อหาการลงทะเบียนเป็นสมาชิกการเล่นเกมหรือปัญหาที่เกิดขึ้นกับการฝากเบิกเงินรายได้น้อยสามารถจัดแจงให้ท่านได้ในที่เดียว
• คุณสามารถเลือกวางเดิมพันเกมบาคาร่าได้จากที่คุณปรารถนาโดยไม่จำเป็นต้องกลุ้มใจว่าถ้าเกิดคุณมีงบประมาณสำหรับการเล่นเกมน้อยจะไม่สามารถที่จะเข้ามาเล่นเกมบาคาร่ากับพวกเราได้น่าฟังเงินอย่างน้อยที่คุณสามารถลงเล่นเกมบาคาร่าได้นั้นเพียงแต่ไม่กี่สิบบาทแค่นั้น
มองเห็นแล้วใช่ไหมค่ะว่าเพราะเหตุใดคุณจำต้องเล่นเกมบาคาร่าออนไลน์กับเว็บไซต์คาสิโนของพวกเราฉะนั้นถ้าเกิดคุณพึงพอใจที่จะเข้ามาลงทะเบียนเป็นสมาชิกหรือพึงพอใจเข้ามาร่วมเล่นเกมบาคาร่ากับพวกเราสามารถสอบถามหรือแอด Line เข้ามาได้พวกเรามีแอดไม่นใจดีที่จะรอให้ความให้การช่วยเหลือตอบปัญหาและก็อำนวยความสะดวกสำหรับในการฝากถอนหรือสำหรับการเล่นเกมคาสิโนบาคาร่าของคุณ
บาคาร่า

Anonymous said...

ไม่น่าเลย! "เลอมาร์" รับเศร้าใจพลาดซบหงส์แดง
ไม่มีอะไรจะต้องปกปิด...โตมาส์ เลอมาร์ ปีกร่างเล็ก แอตเลติเตียนโก มาดริด ยอมรับสารภาพหวังที่ชวดย้ายซบ ลิเวอร์พูล เมื่อสามปีก่อน พร้อมแย้มอาจเลือกล่ำลาถิ่น ว่านต๋า เมโตรโปลีตาโน่ ด้านหลังจบฤดูนี้
มารวมเป็นส่วนหนึ่งส่วนใดกับเรา กับบริการที่เหมาะสมที่สุด

ขอพูดถึง อีกหนึ่งค่ายเกมที่ได้รับความนิยม ทีอยู่ในระดับที่ยอดเยี่ยม ไม่ว่าจะเป็น Kickoffbet หรือค่ายนี้เขายังมีเกมที่ชื่อว่า AE sexy หรืออีกชื่อคือ
game hall อยู่ ซึ่งเป็นเกมที่ คนเล่นเยอะที่สุดในโลก รวมไปถึง Kickoffbet
เพราะว่ามีสาวสวยเซ็กซี่ ทำหน้าที่รับบทเป็นคนแจกไพ่ อีกทั้งยังมีมากมายหลายประเทศ ไม่ซ้ำหน้า มากกว่าที่ในใดในชาวโลกคือผู้เล่นส่วนใหญ่เป็นคนไทยเยอะมาก ๆ
ยังมีอีกหนึ่งบริการทื่เราลืมไม่ได้เลยครับ นั่นก็คือการ sa gaming หรือว่าจะเป็น joker gaming
ขอพูดถึง Kickoffbetอีกหนึ่งค่ายเกมที่ได้รับความนิยม ทีอยู่ในระดับที่ยอดเยี่ยม ไม่ว่าจะเป็น sexy gaming หรือ
AE sexy ซึ่งเป็นเกมที่ คนเล่นเยอะที่สุดในโลก
เพราะว่ามีสาวสวยเซ็กซี่ ทำหน้าที่รับบทเป็นคนแจกไพ่ อีกทั้งยังมีมากมายหลายประเทศ ไม่ซ้ำหน้า มากกว่าที่ในใดในชาวโลกคือผู้เล่นส่วนใหญ่เป็นคนไทยเยอะมาก ๆ
ยังมีอีกหนึ่งบริการทื่เราลืมไม่ได้เลยครับ นั่นก็คือการ สมัคร SA หรือว่าจะเป็น jokergame
เมื่อพูดถึงเกมการที่สนุกและสุดมันส์ใน Kickoffbet เรานึกถึงอะไร
กัน


โตมาส์ เลอมาร์ ปีกชาวประเทศฝรั่งเศสของ แอตเลตำหนิโก มาดริด ชมรมดังที่เวที ลา ลีกา ประเทศสเปน เห็นด้วยว่า รู้สึกผิดหวังที่มิได้ย้ายไปร่วมกลุ่ม หงส์แดง ยอดสมาคมลูกหนังในศึก พรีเมียร์ลีก อังกฤษ เมื่อสามปีที่ผ่านมา

"ผมพร้อมใคร่ครวญทุกข้อเสนอแนะ ผมเป็นนักฟุตบอล ผมชอบใจบอล และไม่มีทางปิดโอกาสดีๆให้กับตัวเอง" แข้งดีกรีแชมป์โลก ระบุ “

UFA888 said...



This are new articles stylse for you. https://sbo98bet.wixsite.com/sbo98bet/post/%E0%B8%AA%E0%B8%A1-%E0%B8%84%E0%B8%A3-ufabet amazin555 http://foxz98bet.over-blog.com/ufabet-6 It might help you to write or think some new idea.
https://dafa98bet.weebly.com/36263617363335883619362636173634359436363585/-ufabet8326348 Thanks for sharing such a wonderful post.
https://w88-com.jimdofree.com/2020/09/01/%E0%B8%AA%E0%B8%A1-%E0%B8%84%E0%B8%A3-ufabet/ I am very glad for reading my articles.

UFA888 said...


This Is Really Useful And Nices Information. แทงบอลสเต็ป
This are such great articles. แทงบอลสเต็ป This articles can help you to make some new ideas.
https://soccersurfer98.hatenablog.com/entry/2020/09/02/132139?_ga=2.193217001.552343305.1598844608-1286484823.1596077192 I appreciate for reading my blogs.

pandith13 said...

it was great information and very useful
SRI ANNAPOORNESHAWARI ASTROLOGY CENTER.Best Astrologer In Virginia


Pandith13 said...

Thanks for providing this information. It's very helpful.

SRI ANNAPOORNESHAWARI ASTROLOGY CENTER.Best Astrologer In Latur

Sudharshan Bhat guruji said...

Nice blog with good content,thanks for sharing.
For Astrological service contact Shri Durga astro center,They gives
Vashikaran Astrologer in Hubli

MS Groups Resorts said...

Very useful information...!!!
Visit Resorts in Mysore Road.

MAJALAH4D said...

Saat ini togel deposit pulsa 10rb tanpa potongan besar sudah bisa dimainkan di agen Majalah4D bersama agen togel online anda bisa melakukan togel deposit pulsa 10rb hanya di Agen Togel Toto 4D hanya dengan menggunakan 1 user id saja.


Togel deposit pulsa
situs togel deposit pulsa
Togel deposit pulsa 10rb
togel toto 4d
Sabung Ayam sv388
Link situs Sv388
Sabung ayam sv388 apk
Aplikasi sv388
Slot deposit pulsa
Slot deposit pulsa tri 10rb