Compare commits

...

2 commits

Author SHA1 Message Date
Emi Simpson b8afaddc38
Add a machine-info module 2023-03-16 11:15:47 -04:00
Emi Simpson 1533464084
Minor spacing issue 2023-03-16 09:46:39 -04:00
3 changed files with 122 additions and 4 deletions

119
modules/machine-info.nix Normal file
View file

@ -0,0 +1,119 @@
{ config, pkgs, lib, ... }@nixpkgs: with lib; {
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;
};
}

View file

@ -10,6 +10,7 @@ let systemInformation = import ./system/system-information.nix; in
[ [
./configs/filesystems.nix ./configs/filesystems.nix
./system/hardware-requirements.nix ./system/hardware-requirements.nix
./modules/machine-info.nix
<home-manager/nixos> <home-manager/nixos>
]; ];
@ -166,9 +167,7 @@ let systemInformation = import ./system/system-information.nix; in
}; };
}; };
environment.etc.machine-info.text = lib.strings.toShellVars { environment.machineInfo.prettyHostname = systemInformation.prettyHostname;
PRETTY_HOSTNAME = systemInformation.prettyHostname;
};
# Enable the OpenSSH daemon. # Enable the OpenSSH daemon.
# services.openssh.enable = true; # services.openssh.enable = true;