Nix-Configs/modules/machine-info.nix

119 lines
3.6 KiB
Nix
Raw Normal View History

2023-03-21 19:56:35 +00:00
{ config, pkgs, lib, ... }: with lib; {
2023-03-16 15:15:47 +00:00
options.environment.machineInfo = mkOption {
description = lib.mdDoc ''
Machine metadata, including stylized hostname, computer icon, etc.
This module controls the options written to `/etc/machine-info`. For more
information, see [the freedesktop documentation][1].
[1]: https://www.freedesktop.org/software/systemd/man/machine-info.html
'';
default = {};
type = types.submodule { options = {
prettyHostname = mkOption {
description = lib.mdDoc ''
A pretty, human-readable hostname for this machine, potentially including
spaces, unicode, and emoji. If unset, this falls back to the network hostname
set in `networking.hostName`.
'';
type = with types; nullOr str;
default = null;
defaultText = literalExpression "null";
example = literalExpression "\"Jade's Laptop 💎\"";
};
iconName = mkOption {
description = lib.mdDoc ''
An XDG icon which should be associated with this machine. Some common choices
include: `"computer"`, `"phone"`, but a complete list of icons can be found in
the [XDG Icon Naming Spec][1].
If left unset, applications will typically default to `"computer"`.
[1]: https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
'';
type = with types; nullOr str;
default = null;
defaultText = literalExpression "null";
example = literalExpression "\"computer\"";
};
chassis = mkOption {
description = lib.mdDoc ''
The type of chassis this machine resides within. This is typically detected
automatically, but can be manually overridden here.
'';
type = with types; nullOr (enum [
"desktop"
"laptop"
"convertible"
"server"
"tablet"
"handset"
"watch"
"embedded"
"vm"
"container"
]);
default = null;
defaultText = literalExpression "null";
example = literalExpression "\"server\"";
};
deployment = mkOption {
description = lib.mdDoc ''
If this machine is part of a deployment environment / pipeline, this option can
be used to specify what environment/pipeline stage it manages.
Typically, but not necessarily, set to something like `"development"`,
`"integration"`, `"staging"`, or `"production"`.
'';
type = with types; nullOr str;
default = null;
defaultText = literalExpression "null";
example = literalExpression "\"production\"";
};
location = mkOption {
description = lib.mdDoc ''
A human-readable short description of the location of this machine.
This can be set to whatever has the most meaning for you, for example "Living
Room", "Left Rack, 2nd Shelf", or "Parishville, NY".
'';
type = with types; nullOr str;
default = null;
defaultText = literalExpression "null";
example = literalExpression "\"Bedroom\"";
};
extraOptions = mkOption {
description = lib.mdDoc ''
Extra variables to put in `/etc/machine-info`
'';
type = with types; attrsOf str;
default = {};
defaultText = literalExpression "{ }";
example = literalExpression "{ HARDWARE_VENDOR = \"Intel Corp.\" }";
};
};};
};
config.environment.etc.machine-info =
with config.environment.machineInfo;
let
rawShellVars = {
PRETTY_HOSTNAME = prettyHostname;
ICON_NAME = iconName;
CHASSIS = chassis;
DEPLOYMENT = deployment;
LOCATION = location;
} // extraOptions;
nonNullShellVars = attrsets.filterAttrs (k: v: v != null) rawShellVars;
in rec {
text = strings.toShellVars nonNullShellVars;
enable = builtins.stringLength text > 0;
};
}