Flakes: Difference between revisions
imported>Tfc m fix missing semicolon |
imported>Jtojnar describe flake-compat |
||
| Line 146: | Line 146: | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
== Using flakes project from a legacy Nix == | |||
There is a [https://github.com/edolstra/flake-compat flake-compat] library you can use to shim legacy <code>default.nix</code> and <code>shell.nix</code> files. It will download the inputs of the flake, pass them to the flake’s <code>outputs</code> function and return an attribute set containing <code>defaultNix</code> and <code>shellNix</code> attributes. The attributes will contain the output attribute set with an extra <code>default</code> attribute pointing to current platform’s <code>defaultPackage</code> (resp. <code>devShell</code> for <code>shellNix</code>). | |||
Place the following into <code>default.nix</code> (for <code>shell.nix</code>, replace <code>defaultNix</code> with <code>shellNix</code>) to use the shim: | |||
<syntaxHighlight lang=nix> | |||
(import ( | |||
fetchTarball { | |||
url = "https://github.com/edolstra/flake-compat/archive/c75e76f80c57784a6734356315b306140646ee84.tar.gz"; | |||
sha256 = "071aal00zp2m9knnhddgr2wqzlx6i6qa1263lv1y7bdn2w20h10h"; } | |||
) { | |||
src = ./.; | |||
}).defaultNix | |||
</syntaxHighlight> | |||
You can also use the lockfile to make updating the hashes easier using <code>nix flake update --update-input flake-compat</code>. Add the following to your <code>flake.nix</code>: | |||
<syntaxHighlight lang=nix> | |||
inputs.flake-compat = { | |||
url = "github:edolstra/flake-compat"; | |||
flake = false; | |||
}; | |||
</syntaxHighlight> | |||
and add <code>flake-compat</code> to the arguments of <code>outputs</code> attribute. Then you will be able to use <code>default.nix</code> like the following: | |||
<syntaxHighlight lang=nix> | |||
(import ( | |||
let | |||
lock = builtins.fromJSON (builtins.readFile ./flake.lock); | |||
in fetchTarball { | |||
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; | |||
sha256 = lock.nodes.flake-compat.locked.narHash; } | |||
) { | |||
src = ./.; | |||
}).defaultNix | |||
</syntaxHighlight> | |||
== The nix flakes command == | == The nix flakes command == | ||