diff --git a/nix/home-module.nix b/nix/home-module.nix index 713c8f65c..15e797dbe 100644 --- a/nix/home-module.nix +++ b/nix/home-module.nix @@ -16,6 +16,8 @@ in { options.programs.noctalia-shell = { enable = lib.mkEnableOption "Noctalia shell configuration"; + systemd.enable = lib.mkEnableOption "Noctalia shell systemd integration"; + package = lib.mkOption { type = lib.types.nullOr lib.types.package; description = "The noctalia-shell package to use"; @@ -103,18 +105,46 @@ in { useApp2Unit = cfg.settings.appLauncher.useApp2Unit or false; in lib.mkIf cfg.enable { + systemd.user.services.noctalia-shell = lib.mkIf cfg.systemd.enable { + Unit = { + Description = "Noctalia Shell - Wayland desktop shell"; + Documentation = "https://docs.noctalia.dev/docs"; + PartOf = [ config.wayland.systemd.target ]; + After = [ config.wayland.systemd.target ]; + X-Restart-Triggers = [ "${config.xdg.configFile."noctalia/settings.json".source}" ] + ++ lib.optional (cfg.colors != { }) "${config.xdg.configFile."noctalia/colors.json".source}"; + }; + + Service = { + ExecStart = lib.getExe cfg.package; + Restart = "on-failure"; + Environment = [ + "NOCTALIA_SETTINGS_FALLBACK=%h/.config/noctalia/gui-settings.json" + ]; + }; + + Install.WantedBy = [ config.wayland.systemd.target ]; + }; + home.packages = lib.optional useApp2Unit cfg.app2unit.package ++ lib.optional (cfg.package != null) cfg.package; xdg.configFile = { "noctalia/settings.json" = { - onChange = restart; + onChange = lib.mkIf (!cfg.systemd.enable) restart; text = builtins.toJSON cfg.settings; }; "noctalia/colors.json" = lib.mkIf (cfg.colors != {}) { - onChange = restart; + onChange = lib.mkIf (!cfg.systemd.enable) restart; text = builtins.toJSON cfg.colors; }; }; + + assertions = [ + { + assertion = !cfg.systemd.enable || cfg.package != null; + message = "noctalia-shell: The package option must not be null when systemd service is enabled."; + } + ]; }; }