Lib
Usage
snowfall-lib
provides two utilities directly on the flake itself.
mkLib
The library generator function. This is the entrypoint for snowfall-lib
and is how
you access all of its features. See the following Nix Flake example for how to create a
library instance with mkLib
.
For information on how to use lib
, see the lib
section. Or skip directly
to lib.mkFlake
to see how to configure your flake’s outputs.
mkFlake
A convenience wrapper for writing the following.
Instead, with mkFlake
you can combine these calls into one like the following.
See lib.mkFlake
for information on how to configure your flake’s outputs.
lib
Snowfall Lib provides utilities for creating flake outputs as well as some
necessary helpers. In addition, lib
is an extension of nixpkgs.lib
and every
flake input that contains a lib
attribute. This means that you can use lib
directly for all of your needs, whether they’re Snowfall-related, NixPkgs-related,
or for one of the other flake inputs.
The way that mkLib
merges libraries is by starting with the base nixpkgs.lib
and
then merge each flake input’s lib
attribute, namespaced by the name of the input.
For example, if you have the input flake-utils-plus
then you will be able to use
lib.flake-utils-plus
instead of having to keep a reference to the input’s lib at
inputs.flake-utils-plus.lib
.
If you have your own library in a lib/
directory at your flake’s root, definitions
in there will automatically be imported and merged as well.
When producing flake outputs with mkFlake
or another Snowfall lib
utility, lib
will
be passed in as an input. All of this together gives you easy access to a common
library of utilities and easy access to the libraries of flake inputs or your own
custom library.
lib.mkFlake
The lib.mkFlake
function creates full flake outputs. For most cases you will only
need to use this helper and the Snowfall lib
will take care of everything else.
Flake Structure
Snowfall Lib has opinions about how a flake’s files are laid out. This lets
lib
do all of the busy work for you and allows you to focus on creating. Here is
the structure that lib
expects to find at the root of your flake.
Default Flake
Without any extra input, lib.mkFlake
will generate outputs for all systems, modules,
packages, overlays, and shells specified by the Flake Structure section.
Snowfall Configuration
Snowfall Lib supports configuring some functionality and interopability with other tools via
the snowfall
attribute passed to mkLib
.
External Overlays And Modules
You can apply overlays and modules from your flake’s inputs with the following options.
Internal Packages And Outputs
Packages created from your packages/
directory are automatically made available via an
overlay for your nixpkgs
channel. System configurations can access these packages directly
on pkgs
and consumers of your flake can use the generated <your-flake>.overlays
attributes.
Default Packages And Shells
Snowfall Lib will create packages and shells based on your packages/
and shells
directories. However, it is common to additionally map one of those packages or shells
to be their respective default. This can be achieved by setting an alias
and
mapping the default
package or shell to the name of the one you want.
Darwin And NixOS Generators
Snowfall Lib has support for configuring macOS systems and building any output
supported by NixOS Generators. In order to use these features, your flake must
include darwin
and/or nixos-generators
as inputs.
Any macOS systems will be available on your flake at darwinConfigurations
for use
with darwin-rebuild
. Any system type supported by NixOS Generators will be available
on your flake at <format>Configurations
where <format>
is the name of the generator
type. See the following table for a list of supported formats from NixOS Generators.
format | description |
---|---|
amazon | Amazon EC2 image |
azure | Microsoft azure image (Generation 1 / VHD) |
cloudstack | qcow2 image for cloudstack |
do | Digital Ocean image |
gce | Google Compute image |
hyperv | Hyper-V Image (Generation 2 / VHDX) |
install-iso | Installer ISO |
install-iso-hyperv | Installer ISO with enabled hyper-v support |
iso | ISO |
kexec | kexec tarball (extract to / and run /kexec_nixos) |
kexec-bundle | Same as before, but it’s just an executable |
kubevirt | KubeVirt image |
lxc | Create a tarball which is importable as an lxc container, use together with lxc-metadata |
lxc-metadata | The necessary metadata for the lxc image to start |
openstack | qcow2 image for openstack |
proxmox | VMA file for proxmox |
qcow | qcow2 image |
raw | Raw image with bios/mbr |
raw-efi | Raw image with efi support |
sd-aarch64 | Like sd-aarch64-installer, but does not use default installer image config. |
sd-aarch64-installer | create an installer sd card for aarch64 |
vagrant-virtualbox | VirtualBox image for Vagrant |
virtualbox | virtualbox VM |
vm | Only used as a qemu-kvm runner |
vm-bootloader | Same as vm, but uses a real bootloader instead of netbooting |
vm-nogui | Same as vm, but without a GUI |
vmware | VMWare image (VMDK) |
Home Manager
Snowfall Lib supports configuring Home Manager
for both standalone use and for use as a module with NixOS or nix-darwin. To use this feature,
your flake must include home-manager
as an input.
lib.snowfall.flake
Helpers related to Nix flakes.
lib.snowfall.flake.without-self
Remove the self
attribute from an attribute set.
Type: Attrs -> Attrs
Usage:
Result:
lib.snowfall.flake.without-src
Remove the src
attribute from an attribute set.
Type: Attrs -> Attrs
Usage:
Result:
lib.snowfall.flake.without-snowfall-inputs
Remove the src
and self
attributes from an attribute set.
Type: Attrs -> Attrs
Usage:
Result:
lib.snowfall.flake.get-libs
Transform an attribute set of inputs into an attribute set where
the values are the inputs’ lib
attribute. Entries without a lib
attribute are removed.
Type: Attrs -> Attrs
Usage:
Result:
lib.snowfall.path
lib.snowfall.path.split-file-extension
Split a file name and its extension.
Type: String -> [String]
Usage:
Result:
lib.snowfall.path.has-any-file-extension
Check if a file name has a file extension.
Type: String -> Bool
Usage:
Result:
lib.snowfall.path.get-file-extension
Get the file extension of a file name.
Type: String -> String
Usage:
Result:
lib.snowfall.path.has-file-extension
Check if a file name has a specific file extension.
Type: String -> String -> Bool
Usage:
Result:
lib.snowfall.path.get-parent-directory
Get the parent directory for a given path.
Type: Path -> Path
Usage:
Result:
lib.snowfall.path.get-file-name-without-extension
Get the file name of a path without its extension.
Type: Path -> String
Usage:
Result:
lib.snowfall.fs
File system utilities.
lib.snowfall.fs.is-file-kind
lib.snowfall.fs.is-symlink-kind
lib.snowfall.fs.is-directory-kind
lib.snowfall.fs.is-unknown-kind
Matchers for file kinds. These are often used with readDir
.
Type: String -> Bool
Usage:
Result:
lib.snowfall.fs.get-file
Get a file path relative to the user’s flake.
Type: Path -> Path
Usage:
Result:
lib.snowfall.fs.get-snowfall-file
Get a file path relative to the user’s snowfall directory.
Type: Path -> Path
Usage:
Result:
lib.snowfall.fs.internal-get-file
Get a file relative to the Snowfall Lib flake. You probably shouldn’t use this!
Type: Path -> Path
Usage:
Result:
lib.snowfall.fs.safe-read-directory
Safely read from a directory if it exists.
Type: Path -> Attrs
Usage:
Result:
lib.snowfall.fs.get-directories
Get directories at a given path.
Type: Path -> [Path]
Usage:
Result:
lib.snowfall.fs.get-files
Get files at a given path.
Type: Path -> [Path]
Usage:
Result:
lib.snowfall.fs.get-files-recursive
Get files at a given path, traversing any directories within.
Type: Path -> [Path]
Usage:
Result:
lib.snowfall.fs.get-nix-files
Get nix files at a given path.
Type: Path -> [Path]
Usage:
Result:
lib.snowfall.fs.get-nix-files-recursive
Get nix files at a given path, traversing any directories within.
Type: Path -> [Path]
Usage:
Result:
lib.snowfall.fs.get-default-nix-files
Get nix files at a given path named “default.nix”.
Type: Path -> [Path]
Usage:
Result:
lib.snowfall.fs.get-default-nix-files-recursive
Get nix files at a given path named “default.nix”, traversing any directories within.
Type: Path -> [Path]
Usage:
Result:
lib.snowfall.fs.get-non-default-nix-files
Get nix files at a given path not named “default.nix”.
Type: Path -> [Path]
Usage:
Result:
lib.snowfall.fs.get-non-default-nix-files-recursive
Get nix files at a given path not named “default.nix”, traversing any directories within.
Type: Path -> [Path]
Usage:
Result:
lib.snowfall.module
Utilities for working with NixOS modules.
lib.snowfall.module.create-modules
Create flake output modules.
Type: Attrs -> Attrs
Usage:
Result:
lib.snowfall.attrs
Utilities for working with attribute sets.
lib.snowfall.attrs.map-concat-attrs-to-list
Map and flatten an attribute set into a list.
Type: (a -> b -> [c]) -> Attrs -> [c]
Usage:
Result:
lib.snowfall.attrs.merge-deep
Recursively merge a list of attribute sets.
Type: [Attrs] -> Attrs
Usage:
Result:
lib.snowfall.attrs.merge-shallow
Merge the root of a list of attribute sets.
Type: [Attrs] -> Attrs
Usage:
Result:
lib.snowfall.attrs.merge-shallow-packages
Merge shallow for packages, but allow one deeper layer of attributes sets.
Type: [Attrs] -> Attrs
Usage:
Result:
lib.snowfall.system
lib.snowfall.system.is-darwin
Check whether a named system is macOS.
Type: String -> Bool
Usage:
Result:
lib.snowfall.system.is-linux
Check whether a named system is Linux.
Type: String -> Bool
Usage:
Result:
lib.snowfall.system.is-virtual
Check whether a named system is virtual.
Type: String -> Bool
Usage:
Result:
lib.snowfall.system.get-virtual-system-type
Get the virtual system type of a system target.
Type: String -> String
Usage:
Result:
lib.snowfall.system.get-inferred-system-name
Get the name of a system based on its file path.
Type: Path -> String
Usage:
Result:
lib.snowfall.system.get-target-systems-metadata
Get structured data about all systems for a given target.
Type: String -> [Attrs]
Usage:
Result:
lib.snowfall.system.get-system-builder
Get the system builder for a given target.
Type: String -> Function
Usage:
Result:
lib.snowfall.system.get-system-output
Get the flake output attribute for a system target.
Type: String -> String
Usage:
Result:
lib.snowfall.system.get-resolved-system-target
Get the resolved (non-virtual) system target.
Type: String -> String
Usage:
Result:
lib.snowfall.system.create-system
Create a system.
Type: Attrs -> Attrs
Usage:
Result:
lib.snowfall.system.create-systems
Create all available systems.
Type: Attrs -> Attrs
Usage:
Result:
lib.snowfall.home
lib.snowfall.home.split-user-and-host
Get the user and host from a combined string.
Type: String -> Attrs
Usage:
Result:
lib.snowfall.home.create-home
Create a home.
Type: Attrs -> Attrs
Usage:
Result:
lib.snowfall.home.create-homes
Create all available homes.
Type: Attrs -> Attrs
Usage:
Result:
lib.snowfall.home.get-target-homes-metadata
Get structured data about all homes for a given target.
Type: String -> [Attrs]
Usage:
Result:
lib.snowfall.home.create-home-system-modules
Create system modules for home-manager integration.
Type: Attrs -> [Module]
Usage:
Result:
lib.snowfall.package
Utilities for working with flake packages.
lib.snowfall.package.create-packages
Create flake output packages.
Type: Attrs -> Attrs
Usage:
Result:
lib.snowfall.shell
Utilities for working with flake dev shells.
lib.snowfall.shell.create-shell
Create flake output packages.
Type: Attrs -> Attrs
Usage:
Result:
lib.snowfall.overlay
Utilities for working with channel overlays.
lib.snowfall.overlay.create-overlays-builder
Create a flake-utils-plus overlays builder.
Type: Attrs -> Attrs -> [(a -> b -> c)]
Usage:
Result:
lib.snowfall.overlay.create-overlays
Create overlays to be used for flake outputs.
Type: Attrs -> Attrs
Usage:
Result:
lib.snowfall.template
Utilities for working with flake templates.
lib.snowfall.template.create-templates
Create flake templates.
Type: Attrs -> Attrs
Usage:
Result: