2023-06-30 09:00:03 +00:00
# Flake outputs
2023-06-23 14:22:13 +00:00
2023-06-23 14:41:34 +00:00
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:
2023-06-23 14:22:13 +00:00
2023-06-23 14:41:34 +00:00
- Nix packages: named `apps.<system>.<name>` , `packages.<system>.<name>` , or `legacyPackages.<system>.<name>`
- we can build a package by command `nix build .#<name>`
- Nix Helper Functions: named `lib` ., which means a library for other flakes.
- Nix development environments: named `devShells`
- `devShells` can be used by command `nix develop` , will be introduced later.
- NixOS configuration: named `nixosConfiguration`
- `nixosConfiguration` will be used by command `nixos-rebuild switch --flake .#<name>`
- Nix templates: named `templates`
- templates can be used by command `nix flake init --template <reference>`
- Other user defined outputs, may be parsed by other nix-related tools.
2023-06-23 14:22:13 +00:00
2023-06-23 14:41:34 +00:00
An example copy from NixOS Wiki:
2023-06-23 14:22:13 +00:00
```nix
{ 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 = ""; };
}
2023-06-30 09:00:03 +00:00
```