mirror of
https://github.com/ryan4yin/nixos-and-flakes-book.git
synced 2024-12-12 09:50:42 +01:00
2.5 KiB
2.5 KiB
Flake outputs
the outputs
in flake.nix
are what a flake produces as part of its build. Each flake can have many different outputs simultaneously, including but not limited to:
- Nix packages: named
apps.<system>.<name>
,packages.<system>.<name>
, orlegacyPackages.<system>.<name>
- we can build a package by command
nix build .#<name>
- we can build a package by command
- Nix Helper Functions: named
lib
., which means a library for other flakes. - Nix development environments: named
devShells
devShells
can be used by commandnix develop
, will be introduced later.
- NixOS configuration: named
nixosConfiguration
nixosConfiguration
will be used by commandnixos-rebuild switch --flake .#<name>
- Nix templates: named
templates
- templates can be used by command
nix flake init --template <reference>
- templates can be used by command
- Other user defined outputs, may be parsed by other nix-related tools.
An example copy from NixOS Wiki:
{ self, ... }@inputs:
{
# Executed by `nix flake check`
checks."<system>"."<name>" = derivation;
# Executed by `nix build .#<name>`
packages."<system>"."<name>" = derivation;
# Executed by `nix build .`
packages."<system>".default = derivation;
# Executed by `nix run .#<name>`
apps."<system>"."<name>" = {
type = "app";
program = "<store-path>";
};
# Executed by `nix run . -- <args?>`
apps."<system>".default = { type = "app"; program = "..."; };
# Formatter (alejandra, nixfmt or nixpkgs-fmt)
formatter."<system>" = derivation;
# Used for nixpkgs packages, also accessible via `nix build .#<name>`
legacyPackages."<system>"."<name>" = derivation;
# Overlay, consumed by other flakes
overlays."<name>" = final: prev: { };
# Default overlay
overlays.default = {};
# Nixos module, consumed by other flakes
nixosModules."<name>" = { config }: { options = {}; config = {}; };
# Default module
nixosModules.default = {};
# Used with `nixos-rebuild --flake .#<hostname>`
# nixosConfigurations."<hostname>".config.system.build.toplevel must be a derivation
nixosConfigurations."<hostname>" = {};
# Used by `nix develop .#<name>`
devShells."<system>"."<name>" = derivation;
# Used by `nix develop`
devShells."<system>".default = derivation;
# Hydra build jobs
hydraJobs."<attr>"."<system>" = derivation;
# Used by `nix flake init -t <flake>#<name>`
templates."<name>" = {
path = "<store-path>";
description = "template description goes here?";
};
# Used by `nix flake init -t <flake>`
templates.default = { path = "<store-path>"; description = ""; };
}