Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for NixOS #258

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
result
target
*.zip
*.gz
Expand Down
44 changes: 44 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,50 @@

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
24 changes: 20 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 30 additions & 38 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,44 +1,36 @@
{
description = "Swhkd devel";
description = "Swhkd";

inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; };
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default-linux";
};

outputs = { self, nixpkgs, ... }:
let
pkgsFor = system:
import nixpkgs {
inherit system;
overlays = [ ];
};
outputs = inputs @
{ self
, nixpkgs
, systems
, ...
}:
let
eachSystem = nixpkgs.lib.genAttrs (import systems);

targetSystems = [ "aarch64-linux" "x86_64-linux" ];
in {
devShells = nixpkgs.lib.genAttrs targetSystems (system:
let pkgs = pkgsFor system;
in {
default = pkgs.mkShell {
name = "Swhkd-devel";
nativeBuildInputs = with pkgs; [
# Compilers
cargo
rustc
scdoc
pkgsFor = (system: import nixpkgs {
inherit system;
overlays = [ ];
});
in
{
packages = eachSystem (system: {
default = nixpkgs.legacyPackages.${system}.callPackage ./nix/package.nix { };
});

# libs
udev
defaultPackage = eachSystem (system: self.packages.${system}.default);

# Tools
pkg-config
clippy
gdb
gnumake
rust-analyzer
rustfmt
strace
valgrind
zip
];
};
});
};
}
devShells = eachSystem (system: {
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
, pkgs
, ...
}:
let
cfg = config.services.swhkd;
inherit (pkgs.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;
}
});
'';
};
};
}
50 changes: 50 additions & 0 deletions nix/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{ lib
, rustPlatform
, makeWrapper
, pkg-config
, udev
, killall
}:
rustPlatform.buildRustPackage rec {

pname = "swhkd";
version = "1.3.0-dev";

src = lib.cleanSource ../.;

cargoLock = {
lockFile = "${src}/Cargo.lock";
outputHashes = {
"sweet-0.3.0" = "sha256-swSE1CE39cGojp8HAziw0Bzjr+s4XaVU+4OqQDO60fE=";
};
};

nativeBuildInputs = [
pkg-config
makeWrapper
];

buildInputs = [
udev
killall
];

postInstall = ''
mkdir -p $out/share/polkit-1/actions
cat > $out/share/polkit-1/actions/com.github.swhkd.pkexec.policy <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN" "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>
<action id="com.github.swhkd.pkexec">
<message>Authentication is required to run Simple Wayland Hotkey Daemon</message>
<defaults>
<allow_any>no</allow_any>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">$out/bin/swhkd</annotate>
</action>
</policyconfig>
EOF
'';
}
26 changes: 26 additions & 0 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{pkgs}:
pkgs.mkShell {
name = "Swhkd-devel";
nativeBuildInputs = with pkgs; [
# Compilers
cargo
rustc
scdoc

# libs
udev

# Tools
cargo-audit
cargo-deny
pkg-config
clippy
gdb
gnumake
rust-analyzer
rustfmt
strace
valgrind
zip
];
}