All Projects → numtide → Flake Utils

numtide / Flake Utils

Licence: mit
Pure Nix flake utility functions

Labels

Projects that are alternatives of or similar to Flake Utils

Pre Commit Hooks.nix
Seamless integration of https://pre-commit.com git hooks with Nix.
Stars: ✭ 92 (-18.58%)
Mutual labels:  nix
Nixos Config
Mirror of https://code.balsoft.ru/balsoft/nixos-config
Stars: ✭ 100 (-11.5%)
Mutual labels:  nix
Yarn2nix
Generate nix expressions from a yarn.lock file [maintainer=???]
Stars: ✭ 110 (-2.65%)
Mutual labels:  nix
Stack2nix
Generate nix expressions for Haskell projects
Stars: ✭ 93 (-17.7%)
Mutual labels:  nix
Styx
Static site generator in Nix expression language.
Stars: ✭ 99 (-12.39%)
Mutual labels:  nix
Nix Tree
Interactively browse the dependency graph of your Nix derivations.
Stars: ✭ 104 (-7.96%)
Mutual labels:  nix
Upcast
Abandonware
Stars: ✭ 91 (-19.47%)
Mutual labels:  nix
Nix Deploy
Deploy software or an entire NixOS system configuration to another NixOS system
Stars: ✭ 111 (-1.77%)
Mutual labels:  nix
Nix Linter
Linter for the Nix expression language
Stars: ✭ 100 (-11.5%)
Mutual labels:  nix
Nix Haskell Monorepo
Pragmatic tutorial on how to use nix with a haskell monorepo
Stars: ✭ 111 (-1.77%)
Mutual labels:  nix
System
My system configuration
Stars: ✭ 94 (-16.81%)
Mutual labels:  nix
Nixcloud Webservices
This nixpkgs extension, called nixcloud-webservices, focuses on ease of deployment of web-related technologies.
Stars: ✭ 98 (-13.27%)
Mutual labels:  nix
Nix Home
Utilities for working with user configurations in Nix.
Stars: ✭ 107 (-5.31%)
Mutual labels:  nix
Ghc.nix
Nix (shell) expression for working on GHC
Stars: ✭ 94 (-16.81%)
Mutual labels:  nix
Nixos Config
My NixOS configuration files. (This public mirror is not updated anymore.)
Stars: ✭ 110 (-2.65%)
Mutual labels:  nix
Nix Processmgmt
Experimental Nix-based process management framework
Stars: ✭ 92 (-18.58%)
Mutual labels:  nix
Cached Nix Shell
Instant startup time for nix-shell
Stars: ✭ 103 (-8.85%)
Mutual labels:  nix
Nix Config
My NixOS configuration
Stars: ✭ 112 (-0.88%)
Mutual labels:  nix
Nixwrt
Build images for embedded MIPS SoCs using NixPkgs (experimental)
Stars: ✭ 111 (-1.77%)
Mutual labels:  nix
Powerline Rs
GitLab: https://gitlab.com/jD91mZM2/powerline-rs
Stars: ✭ 108 (-4.42%)
Mutual labels:  nix

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

allSystems -> [<system>]

A list of all systems defined in nixpkgs. For a smaller list see defaultSystems

defaultSystems -> [<system>]

The list of systems supported by nixpkgs and built by hydra. Useful if you want add additional platforms:

eachSystem (defaultSystems ++ ["armv7l-linux"]) (system: { hello = 42; })

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 = 42; }; }
eachSystem allSystems (system: { hello = 42; })
# => {
   hello.aarch64-darwin = 42,
   hello.aarch64-genode = 42,
   hello.aarch64-linux = 42,
   ...
   hello.x86_64-redox = 42,
   hello.x86_64-solaris = 42,
   hello.x86_64-windows = 42
}

eachDefaultSystem -> (<system> -> attrs)

eachSystem pre-populated with defaultSystems.

Example

$ examples/each-system/flake.nix as nix

{
  description = "Flake utils demo";

  inputs.flake-utils.url = "github:numtide/flake-utils";

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

mkApp { drv, name ? drv.pname or drv.name, exePath ? drv.passthru.exePath or "/bin/${name}"

A small utility that builds the structure expected by the special apps and defaultApp prefixes.

flattenTree -> attrs -> attrs

Nix flakes insists on having a flat attribute set of derivations in various places like the packages and checks attributes.

This function traverses a tree of attributes (by respecting recurseIntoAttrs) and only returns their derivations, with a flattened key-space.

Eg:

flattenTree { hello = pkgs.hello; gitAndTools = pkgs.gitAndTools }

Returns:

{
  hello = «derivation»;
  "gitAndTools/git" = «derivation»;
  "gitAndTools/hub" = «derivation»;
  # ...
}

simpleFlake -> attrs -> attrs

This function should be useful for most common use-cases where you have a simple flake that builds a package. It takes nixpkgs and a bunch of other parameters and outputs a value that is compatible as a flake output.

Input:

{
  # pass an instance of self
  self
, # pass an instance of the nixpkgs flake
  nixpkgs
, # we assume that the name maps to the project name, and also that the
  # overlay has an attribute with the `name` prefix that contains all of the
  # project's packages.
  name
, # nixpkgs config
  config ? { }
, # pass either a function or a file
  overlay ? null
, # use this to load other flakes overlays to supplement nixpkgs
  preOverlays ? [ ]
, # maps to the devShell output. Pass in a shell.nix file or function.
  shell ? null
, # pass the list of supported systems
  systems ? [ "x86_64-linux" ]
}: null

Example

Here is how it looks like in practice:

$ examples/simple-flake/flake.nix as nix

{
  description = "Flake utils demo";

  inputs.flake-utils.url = "github:numtide/flake-utils";

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.simpleFlake {
      inherit self nixpkgs;
      name = "simple-flake";
      overlay = ./overlay.nix;
      shell = ./shell.nix;
    };
}

Known issues

$ nix flake check
warning: unknown flake output 'lib'

nixpkgs is currently having the same issue so I assume that it will be eventually standardized.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].