1
0
Fork 0
mirror of https://github.com/numtide/flake-utils.git synced 2024-12-14 11:47:31 +00:00
Pure Nix flake utility functions [maintainer=@zimbatm]
Find a file
Frederik Rietdijk 400fa6d9af
Fix target specification type (#1)
Otherwise you get an error `Target specification with 3 components is ambiguous`.
2020-06-30 16:19:09 +00:00
example remove deprecated flake edition 2020-05-30 00:39:37 +02:00
.gitignore better docs 2020-04-22 17:33:24 +02:00
default.nix fmt 2020-05-02 22:51:26 +02:00
flake.nix remove deprecated flake edition 2020-05-30 00:39:37 +02:00
LICENSE Initial commit 2020-04-11 13:21:35 +00:00
README.md Fix target specification type (#1) 2020-06-30 16:19:09 +00:00

flake-utils

STATUS: alpha

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

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:

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 as nix

{
  description = "Flake utils demo";
  edition = 201909;

  inputs.utils = {
    uri = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, utils }:
    utils.lib.eachDefaultSystem (system:
      let pkgs = nixpkgs.legacyPackages.${system}; in
      rec {
        packages.hello = pkgs.hello;
        defaultPackage = packages.hello;
        apps.hello = utils.lib.mkApp { drv = packages.hello; };
        defaultApp = apps.hello;
      }
    );
}