From bc948ad1abed5eef3f8a10f5b44dc5bcd94d725a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Gro=C3=9Fmann?= Date: Mon, 25 Dec 2023 18:06:39 +0100 Subject: [PATCH] feat: added i3 systemdTarget feat: added xorg wallpaper module --- flake.nix | 2 ++ hm-modules/default.nix | 6 ++++ hm-modules/i3.nix | 31 ++++++++++++++++++++ hm-modules/wallpapers.nix | 60 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 hm-modules/default.nix create mode 100644 hm-modules/i3.nix create mode 100644 hm-modules/wallpapers.nix diff --git a/flake.nix b/flake.nix index ed1eec0..436d0d3 100644 --- a/flake.nix +++ b/flake.nix @@ -27,6 +27,8 @@ { nixosModules.extra-modules = import ./modules; nixosModules.default = self.nixosModules.extra-modules; + homeManagerModules.extra-modules = import ./hm-modules; + homeManagerModules.default = self.homeManagerModules.extra-modules; } // flake-utils.lib.eachDefaultSystem (system: rec { pkgs = import nixpkgs { diff --git a/hm-modules/default.nix b/hm-modules/default.nix new file mode 100644 index 0000000..8c4f54c --- /dev/null +++ b/hm-modules/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./i3.nix + ./wallpapers.nix + ]; +} diff --git a/hm-modules/i3.nix b/hm-modules/i3.nix new file mode 100644 index 0000000..1fac342 --- /dev/null +++ b/hm-modules/i3.nix @@ -0,0 +1,31 @@ +{ + lib, + config, + pkgs, + ... +}: { + options.xsession.windowManager.i3.enableSystemdTarget = lib.mkEnableOption "i3 autostarting the systemd graphical user targets"; + config = let + cfg = config.xsession.windowManager.i3.enableSystemdTarget; + in + lib.mkIf cfg { + systemd.user = { + targets.i3-session = { + Unit = { + Description = "i3 session"; + Documentation = ["man:systemd.special(7)"]; + BindsTo = ["graphical-session.target"]; + Wants = ["graphical-session-pre.target"]; + After = ["graphical-session-pre.target"]; + }; + }; + }; + xsession.windowManager.i3.config.startup = lib.mkAfter [ + { + command = "${pkgs.systemd}/bin/systemctl --user start i3-session.target"; + always = false; + notification = false; + } + ]; + }; +} diff --git a/hm-modules/wallpapers.nix b/hm-modules/wallpapers.nix new file mode 100644 index 0000000..f5a57c7 --- /dev/null +++ b/hm-modules/wallpapers.nix @@ -0,0 +1,60 @@ +{ + lib, + config, + pkgs, + ... +}: { + options.xsession.wallpapers = { + enable = lib.mkEnableOption "automatically refreshing randomly selected wallpapers"; + folder = lib.mkOption { + description = "The folder from which the wallpapers are selected. Relative to home directory"; + type = lib.types.str; + default = ".local/share/wallpapers"; + }; + refreshInterval = lib.mkOption { + description = "How often new wallpapers are drawn. Used as a Systemd timer interval."; + type = lib.types.str; + default = "3 min"; + }; + }; + config = let + cfg = config.xsession.wallpapers; + exe = + pkgs.writeShellScript "set-wallpaper" + '' + ${pkgs.feh}/bin/feh --no-fehbg --bg-fill --randomize \ + $( ${pkgs.findutils}/bin/find ${config.home.homeDirectory}/${cfg.folder} \( -iname "*.png" -or -iname "*.jpg" \) ) + ''; + in + lib.mkIf cfg.enable { + systemd.user = { + timers = { + set-wallpaper = { + Unit = { + Description = "Set a random wallpaper every 3 minutes"; + }; + Timer = { + OnUnitActiveSec = cfg.refreshInterval; + }; + Install.WantedBy = [ + "timers.target" + ]; + }; + }; + services = { + set-wallpaper = { + Unit = { + Description = "Set a random wallpaper on all X displays"; + }; + Service = { + Type = "oneshot"; + ExecStart = + exe; + }; + Install.WantedBy = ["graphical-session.target"]; + }; + }; + }; + home.persistence."/state".directories = [cfg.folder]; + }; +}