utils: add to specialArgs

All the utility functions defined in lib/utils.nix are now easily
accessible via NixOS module arguements, i.e. `{ utils, ... }:`
This commit is contained in:
Timothy DeHerrera 2020-01-05 22:41:19 -07:00
parent f04bc17c89
commit 6770621c70
No known key found for this signature in database
GPG Key ID: 8985725DB5B0C122
2 changed files with 23 additions and 5 deletions

View File

@ -86,11 +86,11 @@ the `nixosConfigurations` flake output and thus becomes deployable. See the
## Profiles ## Profiles
A profile is any directory under [profiles](profiles) containing a `default.nix` A profile is any directory under [profiles](profiles) containing a `default.nix`
defining a valid NixOS module, _with_ the added restriction that no new defining a valid NixOS module, with the added restriction that no new
delclarations to the `options` attribute are allowed (use [modules](modules) delclarations to the `options` _or_ `config` attributes are allowed
instead). Their purpose is to provide abstract expressions suitable for reuse by (use [modules](modules) instead). Their purpose is to provide abstract
multiple deployments. They are perhaps _the_ key concept in keeping this expressions suitable for reuse by multiple deployments. They are perhaps _the_
repository matainable. key mechanism by which we keep this repo maintainable.
Profiles can have subprofiles which are themselves just profiles that live under Profiles can have subprofiles which are themselves just profiles that live under
another. There's no hard rule that everything in the folder must be imported by another. There's no hard rule that everything in the folder must be imported by
@ -118,6 +118,22 @@ your user should be declared here. For convenience, [home-manager][home-manager]
is available automatically for home directory setup and should only be used is available automatically for home directory setup and should only be used
from this directory. from this directory.
## Lib
The [lib](lib) directory contains a file `utils.nix` which is an attribute set
meant to consist mainly of utility functions you might want to write and use
throughout the configuration. They are available via a new `utils` attribute
passed to every NixOS module, eg:
```
# hosts/some-host.nix
{ utils, ... }:
let data = utils.myFunction # ...
in
{
# NixOS configuration
}
```
## Secrets ## Secrets
Anything you wish to keep encrypted goes in the `secrets` directory, which is Anything you wish to keep encrypted goes in the `secrets` directory, which is
created on first entering a `nix-shell`. created on first entering a `nix-shell`.

View File

@ -10,6 +10,8 @@ let
nixpkgs.lib.nixosSystem rec { nixpkgs.lib.nixosSystem rec {
system = "x86_64-linux"; system = "x86_64-linux";
specialArgs = { inherit utils; };
modules = let modules = let
core = ../profiles/core.nix; core = ../profiles/core.nix;