Flakes: Difference between revisions
add missing "path:" line in the output of "nix flake show" |
m grammar fix |
||
| (5 intermediate revisions by 2 users not shown) | |||
| Line 5: | Line 5: | ||
<translate> | <translate> | ||
<!--T:182--> | <!--T:182--> | ||
'''Nix flakes''' are an [https://nix.dev/manual/nix/stable/ | '''Nix flakes''' are an [https://nix.dev/manual/nix/stable/development/experimental-features experimental feature] first introduced in the 2.4 [[Nix]] release,{{Cite manual|nix|development/experimental-features|number=13.8|title=Experimental Features|subsection=xp-feature-flakes|subtitle=flakes}}{{Cite manual|nix|release-notes/rl-2.4|number=14.27|title=Release 2.4 (2021-11-01)}} aiming to address a number of areas of improvement for the Nix ecosystem: they provide a uniform structure for Nix projects, allow for pinning specific versions of each dependency, and sharing these dependencies via lock files, and overall make it more convenient to write reproducible Nix expressions. | ||
<!--T:183--> | <!--T:183--> | ||
| Line 72: | Line 72: | ||
<syntaxhighlight lang="shell"> | <syntaxhighlight lang="shell"> | ||
--experimental-features 'nix-command flakes' | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 81: | Line 81: | ||
<!--T:8--> | <!--T:8--> | ||
Add the following to the [[ | Add the following to the [[NixOS system configuration#Usage|NixOS configuration]]: | ||
</translate> | </translate> | ||
<syntaxHighlight lang=nix> | <syntaxHighlight lang=nix> | ||
nix.settings.experimental-features = [ "nix-command" "flakes" ]; | |||
</syntaxHighlight> | </syntaxHighlight> | ||
| Line 96: | Line 96: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
nix.settings.experimental-features = [ "nix-command" "flakes" ]; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 223: | Line 223: | ||
<!--T:149--> | <!--T:149--> | ||
* <code>nixConfig</code> is an attribute set of values which reflect the [https:// | * <code>nixConfig</code> is an attribute set of values which reflect the [https://nix.dev/manual/nix/stable/command-ref/conf-file.html values given to nix.conf]. This can extend the normal behavior of a user's nix experience by adding flake-specific configuration, such as a [[Binary Cache|binary cache]]. | ||
=== Input schema === <!--T:31--> | === Input schema === <!--T:31--> | ||
<!--T:32--> | <!--T:32--> | ||
[https:// | [https://nix.dev/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-inputs The nix flake inputs manual]. | ||
<!--T:150--> | <!--T:150--> | ||
[https:// | [https://nix.dev/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references The nix flake references manual]. | ||
<!--T:33--> | <!--T:33--> | ||
| Line 290: | Line 290: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
inputs.self.submodules = true; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 297: | Line 297: | ||
<!--T:151--> | <!--T:151--> | ||
The output schema is described the [https://nix.dev/manual/nix/ | The output schema is described the [https://nix.dev/manual/nix/stable/command-ref/new-cli/nix3-flake-check.html#evaluation-checks nix flake check manual page]. | ||
<!--T:43--> | <!--T:43--> | ||
| Line 397: | Line 397: | ||
description = "A flake targeting multiple architectures"; | description = "A flake targeting multiple architectures"; | ||
inputs = { | inputs = { | ||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; | nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; | ||
}; | }; | ||
outputs = { self, nixpkgs }: let | outputs = { self, nixpkgs }: let | ||
systems = [ "x86_64-linux" "aarch64-linux" ]; | |||
forAllSystems = f: builtins.listToAttrs (map (system: { | |||
name = system; | |||
value = f system; | |||
}) systems); | |||
in { | in { | ||
hello = pkgs.hello; | packages = forAllSystems (system: let | ||
pkgs = nixpkgs.legacyPackages.${system}; | |||
in { | |||
hello = pkgs.hello; | |||
default = pkgs.hello; | |||
}); | |||
}; | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 439: | Line 439: | ||
let | let | ||
system = "x86_64-linux"; | system = "x86_64-linux"; | ||
pkgs = import nixpkgs { inherit system; config.allowUnfree = true;}; | pkgs = import nixpkgs { inherit system; config.allowUnfree = true; }; | ||
in { | in { | ||
... | ... | ||
| Line 469: | Line 469: | ||
<translate> | <translate> | ||
=== Flake support in projects without flakes === <!--T:50--> | === Flake support in projects without flakes === <!--T:50--> | ||
{{Tip|Consider building your project in a manner where the <code>flake.nix</code> is merely <code>import</code>ing or <code>callPackage</code>ing stable Nix code to maximize compatibility for everyone as well as avoiding adding workaround dependencies to your project}} | |||
<!--T:51--> | <!--T:51--> | ||
| Line 489: | Line 491: | ||
</translate> | </translate> | ||
< | <syntaxhighlight lang=console> | ||
nix build github:nixos/nixpkgs?ref=pull/<PR_NUMBER>/head#<PACKAGE> | $ nix build github:nixos/nixpkgs?ref=pull/<PR_NUMBER>/head#<PACKAGE> | ||
</ | </syntaxhighlight> | ||
<translate> | <translate> | ||
| Line 501: | Line 503: | ||
</translate> | </translate> | ||
< | <syntaxhighlight lang=console> | ||
git fetch upstream pull/<PR_NUMBER>/head && git checkout FETCH_HEAD && nix build .#PACKAGE | $ git fetch upstream pull/<PR_NUMBER>/head && git checkout FETCH_HEAD && nix build .#PACKAGE | ||
</ | </syntaxhighlight> | ||
<translate> | <translate> | ||
| Line 515: | Line 517: | ||
</translate> | </translate> | ||
< | <syntaxhighlight lang=console> | ||
git add --intent-to-add extra/flake.nix | $ git add --intent-to-add extra/flake.nix | ||
git update-index --skip-worktree --assume-unchanged extra/flake.nix | $ git update-index --skip-worktree --assume-unchanged extra/flake.nix | ||
</ | </syntaxhighlight> | ||
<translate> | <translate> | ||
| Line 530: | Line 532: | ||
</translate> | </translate> | ||
< | <syntaxhighlight lang=console> | ||
cd ~/libdep-src-checkout/ | $ cd ~/libdep-src-checkout/ | ||
nix develop # Or `nix-shell` if applicable. | $ nix develop # Or `nix-shell` if applicable. | ||
export prefix="./install" # configure nix to install it here | $ export prefix="./install" # configure nix to install it here | ||
buildPhase # build it like nix does | $ buildPhase # build it like nix does | ||
installPhase # install it like nix does | $ installPhase # install it like nix does | ||
</ | </syntaxhighlight> | ||
<translate> | <translate> | ||
| Line 543: | Line 545: | ||
</translate> | </translate> | ||
< | <syntaxhighlight lang=console> | ||
cd ~/consumexe-src-checkout/ | $ cd ~/consumexe-src-checkout/ | ||
nix develop --redirect libdep ~/libdep-src-checkout/install | $ nix develop --redirect libdep ~/libdep-src-checkout/install | ||
echo $buildInputs | tr " " "\n" | grep libdep | $ echo $buildInputs | tr " " "\n" | grep libdep | ||
# Output should show ~/libdep-src-checkout/ so you know it worked | $ # Output should show ~/libdep-src-checkout/ so you know it worked | ||
</ | </syntaxhighlight> | ||
<translate> | <translate> | ||
| Line 563: | Line 565: | ||
<!--T:176--> | <!--T:176--> | ||
* [https:// | * [https://nix.dev/manual/nix/stable/command-ref/new-cli/nix3-flake.html Nix flake command reference manual] - Many additional details about flakes, and their parts. | ||
<!--T:178--> | <!--T:178--> | ||