Clight icon indicating copy to clipboard operation
Clight copied to clipboard

NixOS-generated `clight.service` not respecting `--conf-file`

Open spikespaz opened this issue 3 years ago • 5 comments

If you tell me that this isn't a bug with Clight, but rather with the NixOS module, I will republish on the nixpkgs repository.

Issue Description

TL;DR: Command with --conf-file in systemd unit generated by NixOS module starts a service that doesn't respect the provided file, going to default settings. Sometimes.

When using the module provided by nixpkgs, enabling the service (plus the geoclue2 location provider) and using the settings attribute provided has no effect (sometimes). The majority of the time Clight appears to use default settings, and changes made to the configuration file (generated through the Nix configuration) have no effect, even when reloaded with systemctl --user reload clight.service.

Note that only once was I able to get Clight to respect the generated configuration. I can confirm that the systemd units appear to have been correctly generated and enabled; documentation of this will follow. Additionally, the single instance where Clight behaved as expected was not after the initial install, it happened randomly while I was troubleshooting. I do not know what I changed, but it stopped reading my settings again following a system reboot.

Unfortunately, as it seems impossible to configure Clight at the moment, attaching verbose logs is an impossibility.

Environment Specifications

Clight version: 4.8
Clightd version: 5.6
System distribution: NixOS 22.11.20220828.a63021a (Raccoon) x86_64
Configurations: https://github.com/spikespaz/dotfiles
Kernel version: 5.19.4
Desktop environment: Hyprland (Wayland)
Hardware specifications: LENOVO 20Y1S00C00 (ThinkPad P14s Gen 1)

Reproduction

Unknown.

Steps-Taken

I have tried reloading both of the daemons after every ghange, though I believe that this is done by NixOS automatically.

Following are the commands that I have used many times, in many orders, in effort to troubleshoot this myself.

$ sudo nixos-rebuild switch --flake path:/home/jacob/dotfiles#
$ sudo systemctl restart clightd.service
$ systemctl --user restart clight.service
$ systemctl --user remove clight.service
$ sudo nixos-rebuild switch --flake path:/home/jacob/dotfiles#
$ nix build --no-link path:/home/jacob/dotfiles#homeConfigurations.jacob.activationPackage
$ "$(nix path-info path:/home/jacob/dotfiles#homeConfigurations.jacob.activationPackage)/activate"

NixOS Module Configuration

NixOS module source: https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/services/x11/clight.nix Unredacted commitish: https://github.com/spikespaz/dotfiles/commit/a72d561174f786106b0e59cf55b89e7198442d2f

# keyboard and monitor backlight
services.clight = {
  enable = true;

  ## Gamma temperature during day and night
  ## this nix option overrides gamma.temp
  temperature.day = 5500;
  temperature.night = 3700;

  settings = {
    verbose = false;
    resumedelay = 0;

    inhibit = {
      disabled = false;
      inhibit_docked = true;
      inhibit_pm = true;
      inhibit_bl = true;
    };

    backlight = {
      disabled = true;
      restore_on_exit = true;
      no_smooth_transition = false;
      trans_step = 0.05;
      trans_timeout = 30;
      trans_fixed = 0;
      ac_timeouts = [ 600 2700 300 ];
      batt_timeouts = [ 1200 5400 600 ];
      shutter_threshold = 0.10;
      no_auto_calibration = false;
      pause_on_lid_closed = true;
      capture_on_lid_opened = true;
    };

    sensor = {
      ac_regression_points = [ 0.0 0.15 0.29 0.45 0.61 0.74 0.81 0.88 0.93 0.97 1.0 ];
      batt_regression_points = [ 0.0 0.15 0.23 0.36 0.52 0.59 0.65 0.71 0.75 0.78 0.80 ];
      devname = "";
      settings = "";
      captures = [ 5 5 ];
    };

    keyboard = {
      disabled = false;
      timeouts = [ 15 7 ];
      ac_regression_points = [ 1.0 0.97 0.93 0.88 0.81 0.74 0.61 0.45 0.29 0.15 0.0 ];
      batt_regression_points = [ 0.80 0.78 0.75 0.71 0.65 0.59 0.52 0.36 0.23 0.15 0.0 ];
    };

    gamma = {
      disabled = true;
      restore_on_exit = true;
      no_smooth_transition = false;
      trans_step = 50;
      trans_timeout = 300;
      long_transition = true;
      ambient_gamma = false;
    };

    daytime = {
      sunrise = "6:30";
      sunset = "20:30";
      event_duration = 1800;
      sunrise_offset = 0;
      sunset_offset = 0;
    };

    dimmer = rec {
      disabled = false;
      no_smooth_transition = [ false false ];
      trans_steps = [ 0.01 0.08 ];
      trans_timeouts =
        let
          # calculates a duration for each step between
          # full brightness and the dimmed percentage
          formula = duration: target: step: builtins.floor (duration / ((1 - target) / step));
        in
      [
        (formula 2000 dimmed_pct (builtins.elemAt trans_steps 0))
        (formula 250 dimmed_pct (builtins.elemAt trans_steps 1))
      ];
      trans_fixed = [ 0 0 ];
      timeouts = [ 30 15 ];
      dimmed_pct = 0.2;
    };

    dpms = {
      disabled = false;
      timeouts = [ 900 300 ];
    };

    screen = {
      disabled = true;
      contrib = 0.2;
      timeouts = [ 5 0 ];
    };
  };
};

Generated Configuration File

The configuration file that is generated by Nix can be found with:

cat $(systemctl --user cat clight.service | grep ExecStart | sed -E 's/.+--conf-file //') > clight.conf

Observe that running this ensures that the output file matches exactly what should be visible from the currently-used systemd service unit.

The contents follow:

backlight : 
{
ac_timeouts = [ 600, 2700, 300 ];
batt_timeouts = [ 1200, 5400, 600 ];
capture_on_lid_opened = true;
disabled = true;
no_smooth_transition = false;
pause_on_lid_closed = true;
restore_on_exit = true;
shutter_threshold = 0.100000;
trans_fixed = 0;
trans_step = 0.050000;
trans_timeout = 30;
};
daytime : 
{
event_duration = 1800;
sunrise = "6:30";
sunrise_offset = 0;
sunset = "20:30";
sunset_offset = 0;
};
dimmer : 
{
dimmed_pct = 0.200000;
disabled = false;
no_smooth_transition = [ false, false ];
timeouts = [ 30, 15 ];
trans_fixed = [ 0, 0 ];
trans_steps = [ 0.010000, 0.080000 ];
trans_timeouts = [ 25, 25 ];
};
dpms : 
{
disabled = false;
timeouts = [ 900, 300 ];
};
gamma : 
{
ambient_gamma = false;
disabled = true;
long_transition = true;
no_smooth_transition = false;
restore_on_exit = true;
temp = [ 5500, 3700 ];
trans_step = 50;
trans_timeout = 300;
};
inhibit : 
{
disabled = false;
inhibit_bl = true;
inhibit_docked = true;
inhibit_pm = true;
};
keyboard : 
{
ac_regression_points = [ 1.000000, 0.970000, 0.930000, 0.880000, 0.810000, 0.740000, 0.610000, 0.450000, 0.290000, 0.150000, 0.000000 ];
batt_regression_points = [ 0.800000, 0.780000, 0.750000, 0.710000, 0.650000, 0.590000, 0.520000, 0.360000, 0.230000, 0.150000, 0.000000 ];
disabled = false;
timeouts = [ 15, 7 ];
};
monitor_override = [  ];
resumedelay = 0;
screen : 
{
contrib = 0.200000;
disabled = true;
timeouts = [ 5, 0 ];
};
sensor : 
{
ac_regression_points = [ 0.000000, 0.150000, 0.290000, 0.450000, 0.610000, 0.740000, 0.810000, 0.880000, 0.930000, 0.970000, 1.000000 ];
batt_regression_points = [ 0.000000, 0.150000, 0.230000, 0.360000, 0.520000, 0.590000, 0.650000, 0.710000, 0.750000, 0.780000, 0.800000 ];
captures = [ 5, 5 ];
devname = "";
settings = "";
};
verbose = false;

NixOS-generated systemd Service Units

systemctl --user cat clight.service

# /etc/systemd/user/clight.service
[Unit]
After=upower.service clightd.service
Description=C daemon to adjust screen brightness to match ambient brightness, as computed capturing frames from webcam
PartOf=graphical-session.target
Wants=upower.service clightd.service

[Service]
Environment="LOCALE_ARCHIVE=/nix/store/3m17sg8n0066z2a1wqj17ldxzh2vxgva-glibc-locales-2.35-163/lib/locale/locale-archive"
Environment="PATH=/nix/store/mj6wiv9gbbydh06x2i4fl5a9ksdck7c5-coreutils-9.1/bin:/nix/store/nqwkgzay3m6ynr4qz42ypx576s7ckp24-findutils-4.9.0/bin:/nix/store/zpjn33mx0pbfc71ddfi9sc8pdfqrsh8z-gnugrep-3.7/bin:/nix/store/n62963g6w2fj8hnka006wycqwx9pqw5q-gnused-4.8/bin:/nix/store/a026zm6yhqsil81q6f57jgs65ipjgfgz-systemd-251.4/bin:/nix/store/mj6wiv9gbbydh06x2i4fl5a9ksdck7c5-coreutils-9.1/sbin:/nix/store/nqwkgzay3m6ynr4qz42ypx576s7ckp24-findutils-4.9.0/sbin:/nix/store/zpjn33mx0pbfc71ddfi9sc8pdfqrsh8z-gnugrep-3.7/sbin:/nix/store/n62963g6w2fj8hnka006wycqwx9pqw5q-gnused-4.8/sbin:/nix/store/a026zm6yhqsil81q6f57jgs65ipjgfgz-systemd-251.4/sbin"
Environment="TZDIR=/nix/store/2wzs29fwdr03m8a5z5n3mycyay0r73qn-tzdata-2022b/share/zoneinfo"



ExecStart=/nix/store/cl4wspgfy159qrfsh7z6ykk3b7pv00g9-clight-4.8/bin/clight --conf-file /nix/store/vzlqjibfy3s5vq6m7cydxxvifhqv4f9a-clight.conf

Restart=on-failure
RestartSec=5

systemctl cat clightd.service

# /etc/systemd/system/clightd.service
[Unit]
Description=Bus service to manage various screen related properties (gamma, dpms, backlight)
Requires=polkit.service

[Service]
Environment="LOCALE_ARCHIVE=/nix/store/3m17sg8n0066z2a1wqj17ldxzh2vxgva-glibc-locales-2.35-163/lib/locale/locale-archive"
Environment="PATH=/nix/store/mj6wiv9gbbydh06x2i4fl5a9ksdck7c5-coreutils-9.1/bin:/nix/store/nqwkgzay3m6ynr4qz42ypx576s7ckp24-findutils-4.9.0/bin:/nix/store/zpjn33mx0pbfc71ddfi9sc8pdfqrsh8z-gnugrep-3.7/bin:/nix/store/n62963g6w2fj8hnka006wycqwx9pqw5q-gnused-4.8/bin:/nix/store/a026zm6yhqsil81q6f57jgs65ipjgfgz-systemd-251.4/bin:/nix/store/mj6wiv9gbbydh06x2i4fl5a9ksdck7c5-coreutils-9.1/sbin:/nix/store/nqwkgzay3m6ynr4qz42ypx576s7ckp24-findutils-4.9.0/sbin:/nix/store/zpjn33mx0pbfc71ddfi9sc8pdfqrsh8z-gnugrep-3.7/sbin:/nix/store/n62963g6w2fj8hnka006wycqwx9pqw5q-gnused-4.8/sbin:/nix/store/a026zm6yhqsil81q6f57jgs65ipjgfgz-systemd-251.4/sbin"
Environment="TZDIR=/nix/store/2wzs29fwdr03m8a5z5n3mycyay0r73qn-tzdata-2022b/share/zoneinfo"



BusName=org.clightd.clightd
ExecStart=/nix/store/hszqgi3rgd949cswkr2pp3kimdv7w6w3-clightd-5.6/bin/clightd

Restart=on-failure
RestartSec=5
Type=dbus

spikespaz avatar Sep 01 '22 04:09 spikespaz

Hi @spikespaz ! Sorry for the very late response! Thanks for the very detailed bug report! Unfortunately i am not much into nixOS :/ generated systemd units seem fine, and the generated config file for Clight seems ok too! From my understandings, it seems like a timing issue; just an idea:

--conf-file /nix/store/vzlqjibfy3s5vq6m7cydxxvifhqv4f9a-clight.conf

Is the file /nix/store/vzlqjibfy3s5vq6m7cydxxvifhqv4f9a-clight.conf generated by something else? Perhaps the clight service starts before that file is generated/accessible from the user, and Clight gracefully discards it!

FedeDP avatar Sep 24 '22 21:09 FedeDP

Sorry, your reply got lost in "read" notifications for three months.

Is the file /nix/store/vzlqjibfy3s5vq6m7cydxxvifhqv4f9a-clight.conf generated by something else? Perhaps the clight service starts before that file is generated/accessible from the user, and Clight gracefully discards it!

Nix generates all of these files at generation build time, which I initiate. Programs after subsequent reboots can see all of the depended-on files just as a they would in an orthodox distribution.

spikespaz avatar Dec 30 '22 18:12 spikespaz

Sorry, your reply got lost in "read" notifications for three months.

No problem :D It happens to me all the time eheh

Nix generates all of these files at generation build time, which I initiate. Programs after subsequent reboots can see all of the depended-on files just as a they would in an orthodox distribution.

Oh, that is weird; can you try to locally build Clight and forcing verbose=true by default? (eg: by adding a line here: https://github.com/FedeDP/Clight/blob/master/src/conf/opts.c#L137, like conf.verbose=true;) then you will be able to share a verbose log ;)

FedeDP avatar Jan 04 '23 15:01 FedeDP

I'm also using clight on NixOS, but I don't have any problems with the config file getting applied. The only trouble I've had was knowing what changes to make to get the intended result. verbose = true works for me too.

infinisil avatar Apr 05 '23 19:04 infinisil

Thank you for your input! I never used NixOS therefore I don't really know what should be done and why. If there's anything to improve the wiki pages please let me know!

FedeDP avatar Apr 06 '23 15:04 FedeDP