[prev in list] [next in list] [prev in thread] [next in thread]
List: nix-dev
Subject: Re: [Nix-dev] Improve docs for overrideDerivation - overridable attributes
From: Layus <layus.on () gmail ! com>
Date: 2016-06-30 19:01:43
Message-ID: c466ed21-c82d-aea9-98c2-ff986cd17db4 () gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
On 30/06/16 20:18, Alex Berg wrote:
> I created a new "~/.nixpkgs/config.nix" file to customize the
> nix-channel-obtained nixpkgs copy on my system - my goal was to bump
> the version of Vim to a specific version.
>
> My first attempt was to override the derivation and simply set the
> "version" attribute, like this:
>
> {
> packageOverrides = pkgs: rec {
> vim = pkgs.vim.overrideDerivation (oldAttrs: {
> version = "7.4.1941";
> });
> };
> }
>
> But this had zero effect on the name of Vim I saw when using "nix-env
> -qaP" to see package details. The Vim package's definition has the
> "name" attribute defined like this:
>
> name = "vim-${version}";
> version = "7.4.1585";
>
> so I expected my overriding the "version" attribute to affect the
> package's name, but it did not.
No, because the definition above relies on the "rec" keyword, but "rec"
has already been applied /before/ overrideDerivation.
Overriding "version" will not override "name", and in turn will not
override "src".
In fact, overriding "version" will have no impact on the output path as
that parameter is not used by mkDerivation.
But the attribute is overriden. ` nix-instantiate "<nixpkgs>" --eval -A
vim.version ` will give you the new version string.
Overriding "name", for example, will have impact as it is used by
mkDerivation to compute the output path.
Again, it is not sufficient to build a different version of vim. See below.
>
> After asking the #nixos IRC channel, one person suggested the
> "version" attribute isn't overridable because it isn't an attribute
> the *primitive derivation* set. Based on this guess, I changed my
> ~/.nixpkgs/config.nix definition from that to this:
>
> let
> vim-version = "7.4.1941";
> in
> {
> packageOverrides = pkgs: rec {
> vim = pkgs.vim.overrideDerivation (oldAttrs: {
> name = "vim-${vim-version}";
> src = pkgs.fetchFromGitHub {
> owner = "vim";
> repo = "vim";
> rev = "v${vim-version}";
> sha256 = "0apq7sv1fbyfzqh4q0r2z19bn4gbjlb97wyl80kj7qsqmsy7m1lm";
> };
> });
> };
> }
>
> My guess is this works because I'm overriding the "name" attribute.
No, it works because you override the "src" attribute.
src is used by mkDerivation, so overriding modifies the package to be
built with the new source tree.
Overriding the name is not strictly necessary, but is a *very* good
practice, as otherwise you would get a 7.4.1941 vim with the old version
in the name... confusing :-)
> I read the definition of the "mkDerivation" function
> (pkgs/stdenv/generic/default.nix), but it doesn't have a simple list
> of attributes that are overridable, but is rather flexible. Also, that
> definition doesn't mention a "src" attribute, but "src" attribute is
> overridable, so I wonder why overriding the "src" attribute works.
>
> Where can I find explanation for this? If there is a restriction on
> which attributes are overridable, then I'd like to note this in the
> NixPkgs manual, here:
> https://nixos.org/nixpkgs/manual/index.html#sec-pkg-overrideDerivation
Everything is overridable separately, but you cannot count on the rec
keyword at override time.
Every attribute already has a fully defined value.
>
>
>
> _______________________________________________
> nix-dev mailing list
> nix-dev@lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
[Attachment #5 (text/html)]
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 30/06/16 20:18, Alex Berg wrote:<br>
</div>
<blockquote
cite="mid:CABgV3qu7iNPHKGFxvcsbwMVrppuMtFkMeSE-KVNW33CJOY+j_g@mail.gmail.com"
type="cite">
<div dir="ltr">I created a new "~/.nixpkgs/config.nix" file to
customize the nix-channel-obtained nixpkgs copy on my system -
my goal was to bump the version of Vim to a specific version.
<div><br>
</div>
<div>My first attempt was to override the derivation and simply
set the "version" attribute, like this:</div>
<font face="monospace, monospace"><br>
{<br>
packageOverrides = pkgs: rec {<br>
vim = pkgs.vim.overrideDerivation (oldAttrs: {<br>
version = "7.4.1941";<br>
});<br>
};<br>
}</font>
<div><font face="monospace, monospace"><br>
</font></div>
<div><font face="arial, helvetica, sans-serif">But this had zero
effect on the name of Vim I saw when using "nix-env -qaP" to
see package details. The Vim package's definition has the
"name" attribute defined like this:</font></div>
<div><font face="arial, helvetica, sans-serif"><br>
</font></div>
<font face="monospace, monospace">name = "vim-${version}";</font>
<div><font face="monospace, monospace">version = "7.4.1585";<br>
</font><br>
so I expected my overriding the "version" attribute to affect
the package's name, but it did not.</div>
</div>
</blockquote>
No, because the definition above relies on the "rec" keyword, but
"rec" has already been applied <i>before</i> overrideDerivation.<br>
Overriding "version" will not override "name", and in turn will not
override "src".<br>
In fact, overriding "version" will have no impact on the output path
as that parameter is not used by mkDerivation.<br>
But the attribute is overriden. ` nix-instantiate "<nixpkgs>"
--eval -A vim.version ` will give you the new version string.<br>
<br>
Overriding "name", for example, will have impact as it is used by
mkDerivation to compute the output path.<br>
Again, it is not sufficient to build a different version of vim. See
below.<br>
<br>
<blockquote
cite="mid:CABgV3qu7iNPHKGFxvcsbwMVrppuMtFkMeSE-KVNW33CJOY+j_g@mail.gmail.com"
type="cite">
<div dir="ltr">
<div><br>
</div>
After asking the #nixos IRC channel, one person suggested the
"version" attribute isn't overridable because it isn't an
attribute the *primitive derivation* set. Based on this guess, I
changed my ~/.nixpkgs/config.nix definition from that to this:
<div><br>
</div>
<font face="monospace, monospace">let<br>
vim-version = "7.4.1941";<br>
in<br>
{<br>
packageOverrides = pkgs: rec {<br>
vim = pkgs.vim.overrideDerivation (oldAttrs: {<br>
name = "vim-${vim-version}";<br>
src = pkgs.fetchFromGitHub {<br>
owner = "vim";<br>
repo = "vim";<br>
rev = "v${vim-version}";<br>
sha256 =
"0apq7sv1fbyfzqh4q0r2z19bn4gbjlb97wyl80kj7qsqmsy7m1lm";<br>
};<br>
});<br>
};<br>
}</font>
<div><font face="monospace, monospace"><br>
</font></div>
<div><font face="arial, helvetica, sans-serif">My guess is this
works because I'm overriding the "name" attribute.</font></div>
</div>
</blockquote>
<font face="arial, helvetica, sans-serif">No, it works because you
override the "src" attribute.<br>
src is used by mkDerivation, so overriding modifies the package to
be built with the new source tree.<br>
</font>Overriding the name is not strictly necessary, but is a
*very* good practice, as otherwise you would get a 7.4.1941 vim with
the old version in the name... confusing :-)<br>
<br>
<br>
<blockquote
cite="mid:CABgV3qu7iNPHKGFxvcsbwMVrppuMtFkMeSE-KVNW33CJOY+j_g@mail.gmail.com"
type="cite">
<div dir="ltr">
<div><font face="arial, helvetica, sans-serif">I read the
definition of the "mkDerivation" function \
(</font>pkgs/stdenv/generic/default.nix), but it doesn't have a simple list of \
attributes that are overridable, but is rather flexible. Also, that definition
doesn't mention a "src" attribute, but "src" attribute is
overridable, so I wonder why overriding the "src" attribute
works.</div>
<div><br>
</div>
<div>Where can I find explanation for this? <span
style="font-family:arial,helvetica,sans-serif">If there is a
restriction on which attributes are overridable, then I'd
like to note this in the NixPkgs manual, here: <a
moz-do-not-send="true"
href="https://nixos.org/nixpkgs/manual/index.html#sec-pkg-overrideDerivation"><a \
class="moz-txt-link-freetext" \
href="https://nixos.org/nixpkgs/manual/index.html#sec-pkg-overrideDerivation">https:// \
nixos.org/nixpkgs/manual/index.html#sec-pkg-overrideDerivation</a></a></span></div> \
</div> </blockquote>
Everything is overridable separately, but you cannot count on the
rec keyword at override time.<br>
Every attribute already has a fully defined value.
<blockquote
cite="mid:CABgV3qu7iNPHKGFxvcsbwMVrppuMtFkMeSE-KVNW33CJOY+j_g@mail.gmail.com"
type="cite">
<div dir="ltr">
<div><br>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
nix-dev mailing list
<a class="moz-txt-link-abbreviated" \
href="mailto:nix-dev@lists.science.uu.nl">nix-dev@lists.science.uu.nl</a> <a \
class="moz-txt-link-freetext" \
href="http://lists.science.uu.nl/mailman/listinfo/nix-dev">http://lists.science.uu.nl/mailman/listinfo/nix-dev</a>
</pre>
</blockquote>
<p><br>
</p>
</body>
</html>
_______________________________________________
nix-dev mailing list
nix-dev@lists.science.uu.nl
http://lists.science.uu.nl/mailman/listinfo/nix-dev
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic