diff options
author | Silvan Mosberger <contact@infinisil.com> | 2019-08-12 18:18:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-12 18:18:05 +0200 |
commit | a7c7bb156f1125fc82ef71c46a1e8b89a6ed253b (patch) | |
tree | 80b770a25c0deff8231d17523666a29c9c0e4e93 | |
parent | 5d807f80c78c65c560c410b4e284988bd75fcc30 (diff) | |
parent | 7c8ea897be91758787dea1c3280974c7cdf7df9b (diff) | |
download | nixlib-a7c7bb156f1125fc82ef71c46a1e8b89a6ed253b.tar nixlib-a7c7bb156f1125fc82ef71c46a1e8b89a6ed253b.tar.gz nixlib-a7c7bb156f1125fc82ef71c46a1e8b89a6ed253b.tar.bz2 nixlib-a7c7bb156f1125fc82ef71c46a1e8b89a6ed253b.tar.lz nixlib-a7c7bb156f1125fc82ef71c46a1e8b89a6ed253b.tar.xz nixlib-a7c7bb156f1125fc82ef71c46a1e8b89a6ed253b.tar.zst nixlib-a7c7bb156f1125fc82ef71c46a1e8b89a6ed253b.zip |
clight: init (#64309)
clight: init
-rw-r--r-- | nixos/modules/config/locale.nix (renamed from nixos/modules/config/timezone.nix) | 35 | ||||
-rw-r--r-- | nixos/modules/module-list.nix | 3 | ||||
-rw-r--r-- | nixos/modules/rename.nix | 14 | ||||
-rw-r--r-- | nixos/modules/services/x11/clight.nix | 115 | ||||
-rw-r--r-- | nixos/modules/services/x11/redshift.nix | 58 | ||||
-rw-r--r-- | pkgs/applications/misc/clight/clightd.nix | 75 | ||||
-rw-r--r-- | pkgs/applications/misc/clight/default.nix | 57 | ||||
-rw-r--r-- | pkgs/development/libraries/libmodule/default.nix | 29 | ||||
-rw-r--r-- | pkgs/top-level/all-packages.nix | 6 |
9 files changed, 341 insertions, 51 deletions
diff --git a/nixos/modules/config/timezone.nix b/nixos/modules/config/locale.nix index b15948f6e2e5..6f0565881877 100644 --- a/nixos/modules/config/timezone.nix +++ b/nixos/modules/config/locale.nix @@ -9,6 +9,8 @@ let timezone = types.nullOr (types.addCheck types.str nospace) // { description = "null or string without spaces"; }; + lcfg = config.location; + in { @@ -37,12 +39,45 @@ in }; }; + + location = { + + latitude = mkOption { + type = types.float; + description = '' + Your current latitude, between + <literal>-90.0</literal> and <literal>90.0</literal>. Must be provided + along with longitude. + ''; + }; + + longitude = mkOption { + type = types.float; + description = '' + Your current longitude, between + between <literal>-180.0</literal> and <literal>180.0</literal>. Must be + provided along with latitude. + ''; + }; + + provider = mkOption { + type = types.enum [ "manual" "geoclue2" ]; + default = "manual"; + description = '' + The location provider to use for determining your location. If set to + <literal>manual</literal> you must also provide latitude/longitude. + ''; + }; + + }; }; config = { environment.sessionVariables.TZDIR = "/etc/zoneinfo"; + services.geoclue2.enable = mkIf (lcfg.provider == "geoclue2") true; + # This way services are restarted when tzdata changes. systemd.globalEnvironment.TZDIR = tzdir; diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index c775345ba4c0..3d4c41bbbdb8 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -20,6 +20,7 @@ ./config/iproute2.nix ./config/krb5/default.nix ./config/ldap.nix + ./config/locale.nix ./config/malloc.nix ./config/networking.nix ./config/no-x-libs.nix @@ -33,7 +34,6 @@ ./config/system-environment.nix ./config/system-path.nix ./config/terminfo.nix - ./config/timezone.nix ./config/unix-odbc-drivers.nix ./config/users-groups.nix ./config/vpnc.nix @@ -820,6 +820,7 @@ ./services/web-servers/varnish/default.nix ./services/web-servers/zope2.nix ./services/x11/extra-layouts.nix + ./services/x11/clight.nix ./services/x11/colord.nix ./services/x11/compton.nix ./services/x11/unclutter.nix diff --git a/nixos/modules/rename.nix b/nixos/modules/rename.nix index 4ae642222740..6228c95ae91e 100644 --- a/nixos/modules/rename.nix +++ b/nixos/modules/rename.nix @@ -257,6 +257,20 @@ with lib; (mkRenamedOptionModule [ "networking" "extraResolvconfConf" ] [ "networking" "resolvconf" "extraConfig" ]) (mkRenamedOptionModule [ "networking" "resolvconfOptions" ] [ "networking" "resolvconf" "extraOptions" ]) + # Redshift + (mkChangedOptionModule [ "services" "redshift" "latitude" ] [ "location" "latitude" ] + (config: + let value = getAttrFromPath [ "services" "redshift" "latitude" ] config; + in if value == null then + throw "services.redshift.latitude is set to null, you can remove this" + else builtins.fromJSON value)) + (mkChangedOptionModule [ "services" "redshift" "longitude" ] [ "location" "longitude" ] + (config: + let value = getAttrFromPath [ "services" "redshift" "longitude" ] config; + in if value == null then + throw "services.redshift.longitude is set to null, you can remove this" + else builtins.fromJSON value)) + ] ++ (flip map [ "blackboxExporter" "collectdExporter" "fritzboxExporter" "jsonExporter" "minioExporter" "nginxExporter" "nodeExporter" "snmpExporter" "unifiExporter" "varnishExporter" ] diff --git a/nixos/modules/services/x11/clight.nix b/nixos/modules/services/x11/clight.nix new file mode 100644 index 000000000000..6ec395bb05ec --- /dev/null +++ b/nixos/modules/services/x11/clight.nix @@ -0,0 +1,115 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.services.clight; + + toConf = v: + if builtins.isFloat v then toString v + else if isInt v then toString v + else if isBool v then boolToString v + else if isString v then ''"${escape [''"''] v}"'' + else if isList v then "[ " + concatMapStringsSep ", " toConf v + " ]" + else abort "clight.toConf: unexpected type (v = ${v})"; + + clightConf = pkgs.writeText "clight.conf" + (concatStringsSep "\n" (mapAttrsToList + (name: value: "${toString name} = ${toConf value};") + (filterAttrs + (_: value: value != null) + cfg.settings))); +in { + options.services.clight = { + enable = mkOption { + type = types.bool; + default = false; + description = '' + Whether to enable clight or not. + ''; + }; + + temperature = { + day = mkOption { + type = types.int; + default = 5500; + description = '' + Colour temperature to use during the day, between + <literal>1000</literal> and <literal>25000</literal> K. + ''; + }; + night = mkOption { + type = types.int; + default = 3700; + description = '' + Colour temperature to use at night, between + <literal>1000</literal> and <literal>25000</literal> K. + ''; + }; + }; + + settings = let + validConfigTypes = with types; either int (either str (either bool float)); + in mkOption { + type = with types; attrsOf (nullOr (either validConfigTypes (listOf validConfigTypes))); + default = {}; + example = { captures = 20; gamma_long_transition = true; ac_capture_timeouts = [ 120 300 60 ]; }; + description = '' + Additional configuration to extend clight.conf. See + <link xlink:href="https://github.com/FedeDP/Clight/blob/master/Extra/clight.conf"/> for a + sample configuration file. + ''; + }; + }; + + config = mkIf cfg.enable { + boot.kernelModules = [ "i2c_dev" ]; + environment.systemPackages = with pkgs; [ clight clightd ]; + services.dbus.packages = with pkgs; [ clight clightd ]; + services.upower.enable = true; + + services.clight.settings = { + gamma_temp = with cfg.temperature; mkDefault [ day night ]; + } // (optionalAttrs (config.location.provider == "manual") { + latitude = mkDefault config.location.latitude; + longitude = mkDefault config.location.longitude; + }); + + services.geoclue2.appConfig."clightc" = { + isAllowed = true; + isSystem = true; + }; + + systemd.services.clightd = { + requires = [ "polkit.service" ]; + wantedBy = [ "multi-user.target" ]; + + description = "Bus service to manage various screen related properties (gamma, dpms, backlight)"; + serviceConfig = { + Type = "dbus"; + BusName = "org.clightd.clightd"; + Restart = "on-failure"; + RestartSec = 5; + ExecStart = '' + ${pkgs.clightd}/bin/clightd + ''; + }; + }; + + systemd.user.services.clight = { + after = [ "upower.service" "clightd.service" ]; + wants = [ "upower.service" "clightd.service" ]; + partOf = [ "graphical-session.target" ]; + wantedBy = [ "graphical-session.target" ]; + + description = "C daemon to adjust screen brightness to match ambient brightness, as computed capturing frames from webcam"; + serviceConfig = { + Restart = "on-failure"; + RestartSec = 5; + ExecStart = '' + ${pkgs.clight}/bin/clight --conf-file ${clightConf} + ''; + }; + }; + }; +} diff --git a/nixos/modules/services/x11/redshift.nix b/nixos/modules/services/x11/redshift.nix index 4345a3348081..55f8f75021bc 100644 --- a/nixos/modules/services/x11/redshift.nix +++ b/nixos/modules/services/x11/redshift.nix @@ -5,6 +5,7 @@ with lib; let cfg = config.services.redshift; + lcfg = config.location; in { @@ -18,35 +19,6 @@ in { ''; }; - latitude = mkOption { - type = types.nullOr types.str; - default = null; - description = '' - Your current latitude, between - <literal>-90.0</literal> and <literal>90.0</literal>. Must be provided - along with longitude. - ''; - }; - - longitude = mkOption { - type = types.nullOr types.str; - default = null; - description = '' - Your current longitude, between - between <literal>-180.0</literal> and <literal>180.0</literal>. Must be - provided along with latitude. - ''; - }; - - provider = mkOption { - type = types.enum [ "manual" "geoclue2" ]; - default = "manual"; - description = '' - The location provider to use for determining your location. If set to - <literal>manual</literal> you must also provide latitude/longitude. - ''; - }; - temperature = { day = mkOption { type = types.int; @@ -106,33 +78,19 @@ in { }; config = mkIf cfg.enable { - assertions = [ - { - assertion = - if cfg.provider == "manual" - then (cfg.latitude != null && cfg.longitude != null) - else (cfg.latitude == null && cfg.longitude == null); - message = "Latitude and longitude must be provided together, and with provider set to null."; - } - ]; - # needed so that .desktop files are installed, which geoclue cares about environment.systemPackages = [ cfg.package ]; - services.geoclue2 = mkIf (cfg.provider == "geoclue2") { - enable = true; - appConfig."redshift" = { - isAllowed = true; - isSystem = true; - }; + services.geoclue2.appConfig."redshift" = { + isAllowed = true; + isSystem = true; }; - systemd.user.services.redshift = + systemd.user.services.redshift = let - providerString = - if cfg.provider == "manual" - then "${cfg.latitude}:${cfg.longitude}" - else cfg.provider; + providerString = if lcfg.provider == "manual" + then "${toString lcfg.latitude}:${toString lcfg.longitude}" + else lcfg.provider; in { description = "Redshift colour temperature adjuster"; diff --git a/pkgs/applications/misc/clight/clightd.nix b/pkgs/applications/misc/clight/clightd.nix new file mode 100644 index 000000000000..43ff1d73f78f --- /dev/null +++ b/pkgs/applications/misc/clight/clightd.nix @@ -0,0 +1,75 @@ +{ lib, stdenv, fetchFromGitHub +, dbus, cmake, pkgconfig +, glib, udev, polkit, libmodule +, pcre, libXdmcp, utillinux, libpthreadstubs +, enableDdc ? true, ddcutil +, enableDpms ? true, libXext +, enableGamma ? true, libXrandr +, enableScreen ? true }: + +stdenv.mkDerivation rec { + pname = "clightd"; + version = "3.4"; + + src = fetchFromGitHub { + owner = "FedeDP"; + repo = "Clightd"; + rev = version; + sha256 = "0g6kawizwfhvigkwm7rbfq6rg872xn8igy8n355w4d7mmcxk0jf8"; + }; + + # dbus-1.pc has datadir=/etc + SYSTEM_BUS_DIR = "${placeholder "out"}/share/dbus-1/system-services"; + # systemd.pc has prefix=${systemd.out} + MODULE_LOAD_DIR = "${placeholder "out"}/lib/modules-load.d"; + # polkit-gobject-1.pc has prefix=${polkit.out} + POLKIT_ACTION_DIR = "${placeholder "out"}/share/polkit-1/actions"; + + postPatch = '' + sed -i "s@/etc@$out\0@" CMakeLists.txt + sed -i "s@pkg_get_variable(SYSTEM_BUS_DIR.*@set(SYSTEM_BUS_DIR $SYSTEM_BUS_DIR)@" CMakeLists.txt + sed -i "s@pkg_get_variable(MODULE_LOAD_DIR.*@set(MODULE_LOAD_DIR $MODULE_LOAD_DIR)@" CMakeLists.txt + sed -i "s@pkg_get_variable(POLKIT_ACTION_DIR.*@set(POLKIT_ACTION_DIR $POLKIT_ACTION_DIR)@" CMakeLists.txt + ''; + + cmakeFlags = with lib; + optional enableDdc "-DENABLE_DDC=1" + ++ optional enableDpms "-DENABLE_DPMS=1" + ++ optional enableGamma "-DENABLE_GAMMA=1" + ++ optional enableScreen "-DENABLE_SCREEN=1"; + + nativeBuildInputs = [ + dbus + cmake + pkgconfig + ]; + + buildInputs = with lib; [ + glib + udev + polkit + libmodule + + pcre + libXdmcp + utillinux + libpthreadstubs + ] ++ optional enableDdc ddcutil + ++ optional enableDpms libXext + ++ optional enableGamma libXrandr; + + postInstall = '' + mkdir -p $out/bin + ln -svT $out/lib/clightd/clightd $out/bin/clightd + ''; + + meta = with lib; { + description = "Linux bus interface that changes screen brightness/temperature"; + homepage = https://github.com/FedeDP/Clightd; + platforms = platforms.linux; + license = licenses.gpl3; + maintainers = with maintainers; [ + eadwu + ]; + }; +} diff --git a/pkgs/applications/misc/clight/default.nix b/pkgs/applications/misc/clight/default.nix new file mode 100644 index 000000000000..829fd4e12231 --- /dev/null +++ b/pkgs/applications/misc/clight/default.nix @@ -0,0 +1,57 @@ +{ lib, stdenv, fetchFromGitHub +, dbus, cmake, pkgconfig, bash-completion +, gsl, popt, clightd, systemd, libconfig +, withGeoclue ? true, geoclue2 +, withUpower ? true, upower }: + +stdenv.mkDerivation rec { + pname = "clight"; + version = "3.1"; + + src = fetchFromGitHub { + owner = "FedeDP"; + repo = "Clight"; + rev = version; + sha256 = "0rzcr1x9h4llnmklhgzs9r7xwhsrw1qkqvfffkp8fs90nycaqx81"; + }; + + # bash-completion.pc completionsdir=${bash-completion.out} + COMPLETIONS_DIR = "${placeholder "out"}/share/bash-completions/completions"; + # dbus-1.pc has datadir=/etc + SESSION_BUS_DIR = "${placeholder "out"}/share/dbus-1/services"; + + postPatch = '' + sed -i "s@/usr@$out@" CMakeLists.txt + sed -i "s@/etc@$out\0@" CMakeLists.txt + sed -i "s@pkg_get_variable(COMPLETIONS_DIR.*@set(COMPLETIONS_DIR $COMPLETIONS_DIR)@" CMakeLists.txt + sed -i "s@pkg_get_variable(SESSION_BUS_DIR.*@set(SESSION_BUS_DIR $SESSION_BUS_DIR)@" CMakeLists.txt + ''; + + nativeBuildInputs = [ + dbus + cmake + pkgconfig + bash-completion + ]; + + buildInputs = with lib; [ + gsl + popt + upower + clightd + systemd + geoclue2 + libconfig + ] ++ optional withGeoclue geoclue2 + ++ optional withUpower upower; + + meta = with lib; { + description = "A C daemon that turns your webcam into a light sensor"; + homepage = https://github.com/FedeDP/Clight; + platforms = platforms.linux; + license = licenses.gpl3; + maintainers = with maintainers; [ + eadwu + ]; + }; +} diff --git a/pkgs/development/libraries/libmodule/default.nix b/pkgs/development/libraries/libmodule/default.nix new file mode 100644 index 000000000000..bcd20c3b4076 --- /dev/null +++ b/pkgs/development/libraries/libmodule/default.nix @@ -0,0 +1,29 @@ +{ stdenv, fetchFromGitHub +, cmake, pkgconfig }: + +stdenv.mkDerivation rec { + pname = "libmodule"; + version = "4.2.0"; + + src = fetchFromGitHub { + owner = "FedeDP"; + repo = "libmodule"; + rev = version; + sha256 = "1qn54pysdm0q7v1gnisd43i5i4ylf8s8an77jk6jd8qimysv08mx"; + }; + + nativeBuildInputs = [ + cmake + pkgconfig + ]; + + meta = with stdenv.lib; { + description = "C simple and elegant implementation of an actor library"; + homepage = https://github.com/FedeDP/libmodule; + platforms = platforms.linux; + license = licenses.mit; + maintainers = with maintainers; [ + eadwu + ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 76a16cc5aa1a..3e9e36311dca 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -12034,6 +12034,8 @@ in libmodplug = callPackage ../development/libraries/libmodplug {}; + libmodule = callPackage ../development/libraries/libmodule { }; + libmpcdec = callPackage ../development/libraries/libmpcdec { }; libmp3splt = callPackage ../development/libraries/libmp3splt { }; @@ -17449,6 +17451,10 @@ in cligh = python3Packages.callPackage ../development/tools/github/cligh {}; + clight = callPackage ../applications/misc/clight { }; + + clightd = callPackage ../applications/misc/clight/clightd.nix { }; + clipgrab = qt5.callPackage ../applications/video/clipgrab { }; clipmenu = callPackage ../applications/misc/clipmenu { }; |