title: Nix overlays and override pattern
body: <p>I have trouble understanding Nix overlays and the override pattern. What I want to do is add something to "patches" of gdb without copy/pasting
  the whole derivation.</p>
  
  <p>From <a href="https://nixos.org/nixos/nix-pills/override-design-pattern.html" rel="noreferrer">Nix Pills</a> I kind of see that override just mimics OOP, in reality it is just another attribute of the set. But how does it work then? Override is a function from the original attribute set to a transformed one that again has a predefined override function?</p>
  
  <p>And as Nix is a functional language you also don't have variables only bindings which you can shadow in a different scope. But that still doesn't explain how overlays achieve their "magic".</p>
  
  <p>Through ~/.config/nixpkgs I have configured a test overlay approximately like this:</p>
  
  <pre><code>self: super:
    {
       test1 = super.gdb // { name = "test1"; buildInputs = [ super.curl ]; };
       test2 = super.gdb // { name = "test2"; buildInputs = [ super.coreutils ]; };
       test3 = super.gdb.override { pythonSupport = false; };
    };
  </code></pre>
  
  <p>And I get:</p>
  
  <pre><code>nix-repl&gt; "${test1}"
  "/nix/store/ib55xzrp60fmbf5dcswxy6v8hjjl0s34-gdb-8.3"
  
  nix-repl&gt; "${test2}"
  "/nix/store/ib55xzrp60fmbf5dcswxy6v8hjjl0s34-gdb-8.3"
  
  nix-repl&gt; "${test3}"
  "/nix/store/vqlrphs3a2jfw69v8kwk60vhdsadv3k5-gdb-8.3"
  </code></pre>
  
  <p>But then</p>
  
  <pre><code>$ nix-env -iA nixpkgs.test1
  replacing old 'test1'
  installing 'test1'
  </code></pre>
  
  <p>Can you explain me those results please? Am I correct that override can just alter the "defined interface" - that is all parameters of the function and as "patches" isn't a parameter of gdb I won't be able to change it? What is the best alternative then?</p>