nixos-and-flakes-book/docs/other-usage-of-flakes/inputs.md

59 lines
2.4 KiB
Markdown
Raw Normal View History

# Flake Inputs
2023-06-23 16:41:34 +02:00
The `inputs` section in `flake.nix` is an attribute set used to specify the dependencies
of the current flake. There are various types of inputs, as shown in the examples below:
2023-06-23 16:41:34 +02:00
```nix
{
inputs = {
2023-07-16 07:06:13 +02:00
# GitHub repository as the data source, specifying the master branch.
# This is the most common input format.
2023-06-23 16:41:34 +02:00
nixpkgs.url = "github:Mic92/nixpkgs/master";
# Git URL, applicable to any Git repository using the https/ssh protocol.
git-example.url = "git+https://git.somehost.tld/user/path?ref=branch";
2024-02-15 13:06:26 +01:00
# Archive File URL, needed in case your input use LFS.
# Regular git input doesn't support LFS yet.
2024-02-15 14:16:55 +01:00
git-example-lfs.url = "https://codeberg.org/solver-orgz/treedome/archive/master.tar.gz";
2024-03-16 11:07:01 +01:00
# Similar to fetching a Git repository, but using the ssh protocol
# with key authentication. Also uses the shallow=1 parameter
2023-07-16 07:06:13 +02:00
# to avoid copying the .git directory.
ssh-git-example.url = "git+ssh://git@github.com/ryan4yin/nix-secrets.git?shallow=1";
# It's also possible to directly depend on a local Git repository.
2023-06-23 16:41:34 +02:00
git-directory-example.url = "git+file:/path/to/repo?shallow=1";
# Using the `dir` parameter to specify a subdirectory.
nixpkgs.url = "github:foo/bar?dir=shu";
# Local folder (if using an absolute path, the 'path:' prefix can be omitted).
2023-06-23 16:41:34 +02:00
directory-example.url = "path:/path/to/repo";
# If the data source is not a flake, set flake=false.
2023-07-16 07:30:02 +02:00
# `flake=false` is usually used to include additional source code,
# configuration files, etc.
# In Nix code, you can directly reference files within
# it using "${inputs.bar}/xxx/xxx" notation.
# For example, import "${inputs.bar}/xxx/xxx.nix" to import a specific nix file,
# or use "${inputs.bar}/xx/xx" as a path parameter for certain options.
2023-06-23 16:41:34 +02:00
bar = {
url = "github:foo/bar/branch";
flake = false;
};
sops-nix = {
url = "github:Mic92/sops-nix";
# `follows` is the inheritance syntax within inputs.
2024-03-16 11:07:01 +01:00
# Here, it ensures that sops-nix's `inputs.nixpkgs` aligns with
2023-07-16 07:06:13 +02:00
# the current flake's inputs.nixpkgs,
# avoiding inconsistencies in the dependency's nixpkgs version.
2023-06-23 16:41:34 +02:00
inputs.nixpkgs.follows = "nixpkgs";
};
# Lock the flake to a specific commit.
2023-06-23 16:41:34 +02:00
nix-doom-emacs = {
url = "github:vlaci/nix-doom-emacs?rev=238b18d7b2c8239f676358634bfb32693d3706f3";
flake = false;
};
2023-07-06 05:04:52 +02:00
};
outputs = { self, ... }@inputs: { ... };
2023-06-23 16:41:34 +02:00
}
```