From 6770621c707d5d61bdca27cfe8ebbaa0713fd1dc Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sun, 5 Jan 2020 22:41:19 -0700 Subject: [PATCH] utils: add to specialArgs All the utility functions defined in lib/utils.nix are now easily accessible via NixOS module arguements, i.e. `{ utils, ... }:` --- README.md | 26 +++++++++++++++++++++----- hosts/default.nix | 2 ++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9f826c5..60e3c77 100644 --- a/README.md +++ b/README.md @@ -86,11 +86,11 @@ the `nixosConfigurations` flake output and thus becomes deployable. See the ## Profiles A profile is any directory under [profiles](profiles) containing a `default.nix` -defining a valid NixOS module, _with_ the added restriction that no new -delclarations to the `options` attribute are allowed (use [modules](modules) -instead). Their purpose is to provide abstract expressions suitable for reuse by -multiple deployments. They are perhaps _the_ key concept in keeping this -repository matainable. +defining a valid NixOS module, with the added restriction that no new +delclarations to the `options` _or_ `config` attributes are allowed +(use [modules](modules) instead). Their purpose is to provide abstract +expressions suitable for reuse by multiple deployments. They are perhaps _the_ +key mechanism by which we keep this repo maintainable. 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 @@ -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 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 Anything you wish to keep encrypted goes in the `secrets` directory, which is created on first entering a `nix-shell`. diff --git a/hosts/default.nix b/hosts/default.nix index 8a71c9f..f33d8a9 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -10,6 +10,8 @@ let nixpkgs.lib.nixosSystem rec { system = "x86_64-linux"; + specialArgs = { inherit utils; }; + modules = let core = ../profiles/core.nix;