diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 23a1878ba302..e33941037f9c 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -247,6 +247,7 @@ ./services/mail/rmilter.nix ./services/misc/apache-kafka.nix ./services/misc/autofs.nix + ./services/misc/autorandr.nix ./services/misc/bepasty.nix ./services/misc/canto-daemon.nix ./services/misc/calibre-server.nix diff --git a/nixos/modules/services/misc/autorandr.nix b/nixos/modules/services/misc/autorandr.nix new file mode 100644 index 000000000000..6746f3fec698 --- /dev/null +++ b/nixos/modules/services/misc/autorandr.nix @@ -0,0 +1,43 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.autorandr; + +in { + + options = { + + services.autorandr = { + enable = mkEnableOption "handling of hotplug and sleep events by autorandr"; + }; + + }; + + config = mkIf cfg.enable { + + services.udev.packages = [ pkgs.autorandr ]; + + environment.systemPackages = [ pkgs.autorandr ]; + + # systemd.unitPackages = [ pkgs.autorandr ]; + systemd.services.autorandr = { + unitConfig = { + Description = "autorandr execution hook"; + After = [ "sleep.target" ]; + StartLimitInterval = "5"; + StartLimitBurst = "1"; + }; + serviceConfig = { + ExecStart = "${pkgs.autorandr}/bin/autorandr --batch --change --default default"; + Type = "oneshot"; + RemainAfterExit = false; + }; + wantedBy = [ "sleep.target" ]; + }; + + }; + +} diff --git a/pkgs/tools/misc/autorandr/default.nix b/pkgs/tools/misc/autorandr/default.nix index da9a599714cb..d63819ade215 100644 --- a/pkgs/tools/misc/autorandr/default.nix +++ b/pkgs/tools/misc/autorandr/default.nix @@ -1,12 +1,12 @@ -{ fetchgit -, stdenv +{ stdenv , python3Packages -, fetchFromGitHub }: +, fetchFromGitHub +, systemd }: let python = python3Packages.python; wrapPython = python3Packages.wrapPython; - date = "2016-11-23"; + date = "2017-01-22"; in stdenv.mkDerivation { name = "autorandr-unstable-${date}"; @@ -16,20 +16,38 @@ in phases = [ "unpackPhase" "installPhase" ]; installPhase = '' - # install bash completions - mkdir -p $out/bin $out/libexec $out/etc/bash_completion.d - cp -v contrib/bash_completion/autorandr $out/etc/bash_completion.d - - # install autorandr bin - cp autorandr.py $out/bin/autorandr + make install TARGETS='autorandr' PREFIX=$out wrapPythonProgramsIn $out/bin/autorandr $out + + make install TARGETS='bash_completion' DESTDIR=$out + + make install TARGETS='autostart_config' PREFIX=$out DESTDIR=$out + + ${if false then '' + # breaks systemd-udev-settle during boot so disabled + make install TARGETS='systemd udev' PREFIX=$out DESTDIR=$out \ + SYSTEMD_UNIT_DIR=/lib/systemd/system \ + UDEV_RULES_DIR=/etc/udev/rules.d + substituteInPlace $out/etc/udev/rules.d/40-monitor-hotplug.rules \ + --replace /bin "${systemd}/bin" + '' else if systemd != null then '' + make install TARGETS='systemd' PREFIX=$out DESTDIR=$out \ + SYSTEMD_UNIT_DIR=/lib/systemd/system + make install TARGETS='udev' PREFIX=$out DESTDIR=$out \ + UDEV_RULES_DIR=/etc/udev/rules.d + '' else '' + make install TARGETS='pmutils' DESTDIR=$out \ + PM_SLEEPHOOKS_DIR=/lib/pm-utils/sleep.d + make install TARGETS='udev' PREFIX=$out DESTDIR=$out \ + UDEV_RULES_DIR=/etc/udev/rules.d + ''} ''; src = fetchFromGitHub { owner = "phillipberndt"; repo = "autorandr"; - rev = "53d29f99275aebf14240ea95f2d7022b305738d5"; - sha256 = "0pza4wfkzv7mmg2m4pf3n8wk0p7cy6bfqknn8ywz51r8ja16cqfj"; + rev = "855c18b7f2cfd364d6f085d4301b5b98ba6e572a"; + sha256 = "1yp1gns3lwa8796cb7par9czkc9i7paap2fkzf7wj6zqlkgjdvv0"; }; meta = {