Flakes: Difference between revisions

imported>Charles-dyfis-net
Fix bug in my-nix-fast-repl wrapper that would break arguments with spaces
imported>Raboof
Using flakes project from a legacy Nix: for legacy interop, document builtins.getFlake first. Not sure when exactly you'd use flake-compat.
Line 178: Line 178:


== Using flakes project from a legacy Nix ==
== 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>).
 
If you want to use a flake from a 'regular' derivation on a system that does have flakes enabled, you can use something like `(builtins.getFlake "path:/path/to/directory").packages.x86_64-linux.default`, where 'directory' is the directory that contains your `flake.nix`.
 
There is also 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:
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: