about summary refs log tree commit diff
path: root/nixos/modules/services/ttys
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2021-01-05 16:44:43 +0000
committerAlyssa Ross <hi@alyssa.is>2021-01-08 13:55:25 +0000
commit8694e7de2593139ea46c3e6d1431d6803a2d5a8a (patch)
treecf381722b63ab2ed9b9aa9bc89905f6cdf3de7e4 /nixos/modules/services/ttys
parent306fe1c436fc5c80218150e77c63a891e158fb9a (diff)
nixos/getty: add services.getty.loginOptions
This corresponds to agetty's --login-options argument.

With this change, I can set

    services.getty.autologinUser = "qyliss";
    services.getty.loginOptions = "-- \\u";

and have my username prefilled, but with my password still
required (unlike the normal autologinUser behaviour).
Diffstat (limited to 'nixos/modules/services/ttys')
-rw-r--r--nixos/modules/services/ttys/getty.nix31
1 files changed, 29 insertions, 2 deletions
diff --git a/nixos/modules/services/ttys/getty.nix b/nixos/modules/services/ttys/getty.nix
index 68ab81837772a..ecfabef5fb131 100644
--- a/nixos/modules/services/ttys/getty.nix
+++ b/nixos/modules/services/ttys/getty.nix
@@ -3,9 +3,19 @@
 with lib;
 
 let
+  cfg = config.services.getty;
+
+  loginArgs = [
+    "--login-program" "${pkgs.shadow}/bin/login"
+  ] ++ optionals (cfg.autologinUser != null) [
+    "--autologin" cfg.autologinUser
+  ] ++ optionals (cfg.loginOptions != null) [
+    "--login-options" cfg.loginOptions
+  ];
 
-  autologinArg = optionalString (config.services.getty.autologinUser != null) "--autologin ${config.services.getty.autologinUser}";
-  gettyCmd = extraArgs: "@${pkgs.util-linux}/sbin/agetty agetty --login-program ${pkgs.shadow}/bin/login ${autologinArg} ${extraArgs}";
+  gettyCmd = extraArgs:
+    "@${pkgs.util-linux}/sbin/agetty agetty ${escapeShellArgs loginArgs} "
+      + extraArgs;
 
 in
 
@@ -30,6 +40,23 @@ in
         '';
       };
 
+      loginOptions = mkOption {
+        type = types.nullOr types.str;
+        default = null;
+        description = ''
+          Template for arguments to be passed to
+          <citerefentry><refentrytitle>login</refentrytitle>
+          <manvolnum>1</manvolnum></citerefentry>.
+
+          See <citerefentry><refentrytitle>agetty</refentrytitle>
+          <manvolnum>1</manvolnum></citerefentry> for details,
+          including security considerations.  If unspecified, agetty
+          will not be invoked with a <option>--login-options</option>
+          option.
+        '';
+        example = "-h darkstar -- \u";
+      };
+
       greetingLine = mkOption {
         type = types.str;
         description = ''