From 77970b2643db7a33bb08e0710ec38e3464a1d4ad Mon Sep 17 00:00:00 2001 From: Linus Ammon <235536459+linusammon@users.noreply.github.com> Date: Wed, 24 Jun 2026 19:06:35 +0200 Subject: [PATCH] feat(nixos): replace hardcoded cursor options with generic toml settings --- README.md | 19 ++++++---- nix/nixos-module.nix | 85 +++++++++++++++++++++++++------------------- 2 files changed, 60 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 9051b51..06574c6 100644 --- a/README.md +++ b/README.md @@ -123,10 +123,14 @@ programs.noctalia-greeter = { # Optional configuration greeter-args = ""; - settings.cursor = { - theme = "Adwaita"; - size = 24; - package = pkgs.adwaita-icon-theme; + settings = { + cursor = { + theme = "Adwaita"; + size = 24; + }; + keyboard = { + layout = "us"; + }; }; }; ``` @@ -137,6 +141,9 @@ The module enables greetd and sets the session command automatically. `--session ` to set a default session. Run `noctalia-greeter sessions` to list valid names. +`settings` accepts a Nix attrset, a raw TOML string, or a path to a `.toml` file, +and is copied to `/var/lib/noctalia-greeter/greeter.toml` on boot. + ## Building and installing Requires [just](https://github.com/casey/just) and [meson](https://mesonbuild.com/). @@ -314,9 +321,7 @@ command = "env XCURSOR_THEME=Adwaita XCURSOR_SIZE=24 /usr/bin/noctalia-greeter-s ``` If the theme is not under the default search path, also set -`XCURSOR_PATH` (or `cursor_path`) to the directory that contains it. On NixOS, -use the `programs.noctalia-greeter.settings.cursor` options instead, which wire this up -for you. +`XCURSOR_PATH` (or `cursor.path`) to the directory that contains it. ## Keyboard diff --git a/nix/nixos-module.nix b/nix/nixos-module.nix index 096f3e3..5c9377e 100644 --- a/nix/nixos-module.nix +++ b/nix/nixos-module.nix @@ -6,6 +6,16 @@ }: let cfg = config.programs.noctalia-greeter; + tomlFormat = pkgs.formats.toml { }; + + generateToml = + name: value: + if lib.isString value then + pkgs.writeText name value + else if builtins.isPath value || lib.isStorePath value then + value + else + tomlFormat.generate name value; in { options.programs.noctalia-greeter = { @@ -22,45 +32,41 @@ in description = "Arguments to add onto noctalia-greeter-session command."; }; - settings.cursor = { - theme = lib.mkOption { - type = lib.types.nullOr lib.types.str; - default = null; - example = "Adwaita"; - description = '' - Cursor theme name for the greeter. - ''; - }; - - size = lib.mkOption { - type = lib.types.nullOr lib.types.int; - default = null; - example = 24; - description = "Cursor size for the greeter."; - }; - - package = lib.mkOption { - type = lib.types.nullOr lib.types.package; - default = null; - example = lib.literalExpression "pkgs.adwaita-icon-theme"; - description = '' - Package providing the cursor theme. - ''; - }; + settings = lib.mkOption { + type = + with lib.types; + oneOf [ + tomlFormat.type + str + path + ]; + default = { }; + description = '' + Settings for noctalia-greeter written to greeter.toml. + Can be written as: + - A Nix attrset (converted to TOML via nixpkgs' tomlFormat) + - A raw TOML string + - A path to a `.toml` file + ''; + example = lib.literalExpression '' + { + cursor = { + theme = "Adwaita"; + size = 24; + }; + keyboard = { + layout = "us"; + }; + } + ''; }; }; config = let user = config.services.greetd.settings.default_session.user; - cursor = cfg.settings.cursor; - cursorEnv = - lib.optional (cursor.theme != null) "XCURSOR_THEME=${cursor.theme}" - ++ lib.optional (cursor.size != null) "XCURSOR_SIZE=${toString cursor.size}" - ++ lib.optional (cursor.package != null) "XCURSOR_PATH=${cursor.package}/share/icons"; - envPrefix = lib.optionalString ( - cursorEnv != [ ] - ) "${pkgs.coreutils}/bin/env ${lib.concatStringsSep " " cursorEnv} "; + group = + if config.users.users.${user}.group != "" then config.users.users.${user}.group else "greeter"; in lib.mkIf cfg.enable { environment.systemPackages = [ @@ -69,16 +75,21 @@ in systemd.tmpfiles.settings."10-noctalia-greeter" = { "/var/lib/noctalia-greeter".d = { - inherit user; - group = - if config.users.users.${user}.group != "" then config.users.users.${user}.group else "greeter"; + inherit user group; mode = "0750"; }; + } + // lib.optionalAttrs (cfg.settings != { }) { + "/var/lib/noctalia-greeter/greeter.toml".C = { + argument = generateToml "greeter.toml" cfg.settings; + inherit user group; + mode = "0644"; + }; }; services.greetd = { enable = lib.mkDefault true; - settings.default_session.command = lib.mkDefault "${envPrefix}${cfg.package}/bin/noctalia-greeter-session -- ${cfg.greeter-args}"; + settings.default_session.command = lib.mkDefault "${cfg.package}/bin/noctalia-greeter-session -- ${cfg.greeter-args}"; }; assertions = [