diff --git a/INSTALL.md b/INSTALL.md index e0e1769..47c6e25 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -2,6 +2,51 @@ We have packaged `swhkd-git`. `swhkd-bin` has been packaged separately by a user of swhkd. +## NixOS + +For now flake users only. + +This repo contains a NixOS Module for swhkd service. +To enable module add an input first and import to modules: +```nix +{ + inputs = { + swhkd.url = "github:waycrate/swhkd"; + } + + outputs = {nixpkgs, swhkd, ...} @ inputs: { + nixosConfigurations.HOSTNAME = nixpkgs.lib.nixosSystem { + specialArgs = { inherit inputs; }; + modules = [ + ./configuration.nix + swhkd.nixosModules.default + ]; + }; + } +} +``` +After importing you should be able to use it in your configuration.nix file: +```nix +{ inputs +, ... +}: +{ + services.swhkd = { + enable = true; + package = inputs.swhkd.packages.${system}.default; + cooldown = 300; + settings = '' +super + return + alacritty + ''; + }; +} +``` +* Do not forget to start/add to autostart swhkd of your system after login. +* Replace HOSTNAME with your oun + +ps. this module will be updated after Security Model improve, but it is already good enough to use + # Building: `swhkd` and `swhks` install to `/usr/local/bin/` by default. You can change this behaviour by editing the [Makefile](../Makefile) variable, `DESTDIR`, which acts as a prefix for all installed files. You can also specify it in the make command line, e.g. to install everything in `subdir`: `make DESTDIR="subdir" install`. diff --git a/flake.nix b/flake.nix index a4ae898..c4749c0 100644 --- a/flake.nix +++ b/flake.nix @@ -31,5 +31,6 @@ default = (pkgsFor system).callPackage ./nix/shell.nix { }; }); + nixosModules.default = import ./nix/module.nix self; }; } \ No newline at end of file diff --git a/nix/module.nix b/nix/module.nix new file mode 100644 index 0000000..358ef81 --- /dev/null +++ b/nix/module.nix @@ -0,0 +1,68 @@ +self: +{ config +, lib +, stdenv +, ... +}: +let + cfg = config.services.swhkd; + inherit (stdenv.hostPlatform) system; + + inherit (lib) types; + inherit (lib.modules) mkIf; + inherit (lib.options) mkOption mkEnableOption; +in +{ + options.services.swhkd = { + enable = mkEnableOption "Simple Wayland HotKey Daemon"; + + package = mkOption { + description = "The package to use for `swhkd`"; + default = self.packages.${system}.default; + type = types.package; + }; + + cooldown = mkOption { + description = "The cooldown to use for `swhkd`"; + default = 250; + type = types.int; + }; + + settings = mkOption { + description = "The config to use for `swhkd` syntax and samples could found in [repo](https://github.com/waycrate/swhkd)."; + default = '' + super + return + alacritty + ''; + type = types.lines; + }; + }; + + config = mkIf cfg.enable { + environment.systemPackages = [ cfg.package ]; + environment.etc."swhkd/swhkdrc".text = cfg.settings; + + systemd.user.services.swhkd = { + description = "Simple Wayland HotKey Daemon"; + bindsTo = [ "default.target" ]; + script = '' + /run/wrappers/bin/pkexec ${cfg.package}/bin/swhkd \ + --cooldown ${toString cfg.cooldown} + ''; + serviceConfig.Restart = "always"; + wantedBy = [ "default.target" ]; + }; + security.polkit = { + enable = true; + extraConfig = '' + polkit.addRule(function(action, subject) { + if (action.id == "com.github.swhkd.pkexec" && + subject.local == true && + subject.active == true &&) { + return polkit.Result.YES; + } + }); + ''; + }; + }; +}