diff options
author | Mx Kookie <kookie@spacekookie.de> | 2020-12-21 13:15:14 +0100 |
---|---|---|
committer | Mx Kookie <kookie@spacekookie.de> | 2020-12-22 20:41:55 +0100 |
commit | a3be97011845fefd94d0ec926448629f8f5e5cac (patch) | |
tree | d69b4e53b93c465b738be11721e35c350c4425b7 | |
parent | efde4a6127fd9c9da0e1c9ac1d9b6ea102a016c7 (diff) |
libkookie: adding the basic module system harness
The main purpose of this harness is to provide a set of basic
functions to create home-manager loaders, include user configuration,
and provide an API surface to specify the active users on a system.
-rw-r--r-- | infra/libkookie/modules/harness/hm-loader.nix | 15 | ||||
-rw-r--r-- | infra/libkookie/modules/harness/lib.nix | 18 | ||||
-rw-r--r-- | infra/libkookie/modules/harness/users.nix | 34 |
3 files changed, 67 insertions, 0 deletions
diff --git a/infra/libkookie/modules/harness/hm-loader.nix b/infra/libkookie/modules/harness/hm-loader.nix new file mode 100644 index 000000000000..0837780ef2b2 --- /dev/null +++ b/infra/libkookie/modules/harness/hm-loader.nix @@ -0,0 +1,15 @@ +/** + * Load a home-manager configuration for a set of active users + * + * This loader is not to be exposed to the rest of libkookie, + * and should only be accessible by harness/lib. + */ + +modPath: activeUsers: +{ config, lib, pkgs, ... }: + +with lib; +{ home-manager.users = (listToAttrs (map + (u: nameValuePair "${u.name}" ({ ... }: + { imports = [ modPath ]; })) activeUsers)); +} diff --git a/infra/libkookie/modules/harness/lib.nix b/infra/libkookie/modules/harness/lib.nix new file mode 100644 index 000000000000..d4da08a8de48 --- /dev/null +++ b/infra/libkookie/modules/harness/lib.nix @@ -0,0 +1,18 @@ +{ config, lib, pkgs, ... } @ args: + +let + makeModPath = (base: name: base + "/${name}.nix"); + loader = import ./hm-loader.nix; +in +{ + # Load a home-manager configuration module + # + # Returns a home-manager loader closure configured with the + # correct module derivation (by device) and active user set + # enabled via `libkookie.activeUsers`. + loadModule = (mod: dev: + (loader (makeModPath mod dev) config.libkookie.activeUsers)); + + # Load a simple path with the standard set of arguments + load = path: (import path) args; +} diff --git a/infra/libkookie/modules/harness/users.nix b/infra/libkookie/modules/harness/users.nix new file mode 100644 index 000000000000..1fd2600d4eb2 --- /dev/null +++ b/infra/libkookie/modules/harness/users.nix @@ -0,0 +1,34 @@ +{ config, lib, pkgs, ... }: + +with lib; +let + # Defines the structure of a libkookie user definition + userCfg = with types; (submodule { + options = { + name = mkOption { type = str; description = "The name of the user"; }; + cfg = mkOption { description = "The user configuration"; }; + pubkeys = mkOption { type = listOf path; + default = []; + description = "Set of ssh public keys to include"; }; + }; + }); +in +{ + options.libkookie = { + activeUsers = mkOption { + type = with types; listOf userCfg; + default = []; + description = '' + List of active users on this system. This set is used to + determine for which users the home-manager specific modules + need to be included, or which ssh pubkeys are installed. + ''; + }; + }; + + config = { + users.mutableUsers = false; + users.users = builtins.listToAttrs (map ({ name, cfg, ... }: + nameValuePair "${name}" cfg) config.libkookie.activeUsers); + }; +} |