flake-utils/README.md

64 lines
1.5 KiB
Markdown
Raw Normal View History

2020-04-11 15:21:35 +02:00
# flake-utils
2020-04-22 17:12:09 +02:00
2020-04-22 17:33:24 +02:00
**STATUS: alpha**
2020-04-22 17:12:09 +02:00
Pure Nix flake utility functions.
The goal of this project is to build a collection of pure Nix functions that don't
depend on nixpkgs, and that are useful in the context of writing other Nix
flakes.
## Usage
2020-04-22 17:33:24 +02:00
### `defaultSystems -> [<system>]`
A list of all the systems supported by the nixpkgs project.
### `eachSystem -> [<system>] -> (<system> -> attrs)`
A common case is to build the same structure for each system. Instead of
building the hierarchy manually or per prefix, iterate over each systems and
then re-build the hierarchy.
Eg:
```nix
eachSystem ["x86-64-linux"] (system: { hello = 42; })
# => { hello.x86-64-linux.hello = 42; }
```
### `eachDefaultSystem -> (<system> -> attrs)`
`eachSystem` pre-populated with `defaultSystems`.
### `mkApp { drv, name ? drv.pname or drv.name, execPath ? drv.passthru.execPath or "/bin/${name}"`
A small utility that builds the structure expected by the special `apps` and `defaultApp` prefixes.
## Example
Here is how it looks like in practice:
[$ example/flake.nix](example/flake.nix) as nix
2020-04-22 17:12:09 +02:00
```nix
{
2020-04-22 17:33:24 +02:00
description = "Flake utils demo";
2020-04-22 17:12:09 +02:00
edition = 201909;
2020-04-22 17:33:24 +02:00
inputs.utils = {
uri = "github:numtide/flake-utils";
2020-04-22 17:12:09 +02:00
};
2020-04-22 17:33:24 +02:00
2020-04-22 17:12:09 +02:00
outputs = { self, nixpkgs, utils }:
2020-04-22 17:33:24 +02:00
utils.lib.eachDefaultSystem (system:
2020-04-22 17:12:09 +02:00
let pkgs = nixpkgs.legacyPackages.${system}; in
rec {
2020-04-22 17:33:24 +02:00
packages.hello = pkgs.hello;
defaultPackage = packages.hello;
apps.hello = utils.lib.mkApp { drv = packages.hello; };
defaultApp = apps.hello;
}
2020-04-22 17:12:09 +02:00
);
}
```