Skip to content

Commit

Permalink
add module & update Install.md
Browse files Browse the repository at this point in the history
  • Loading branch information
id3v1669 committed Sep 18, 2024
1 parent c5487c8 commit fe270db
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
45 changes: 45 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
default = (pkgsFor system).callPackage ./nix/shell.nix { };
});

nixosModules.default = import ./nix/module.nix self;
};
}
68 changes: 68 additions & 0 deletions nix/module.nix
Original file line number Diff line number Diff line change
@@ -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;
}
});
'';
};
};
}

0 comments on commit fe270db

Please sign in to comment.