-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
package nix & add module & refactor flake
- Loading branch information
id3v1669
committed
Sep 18, 2024
1 parent
f2bee30
commit ea68984
Showing
6 changed files
with
193 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
result | ||
target | ||
*.zip | ||
*.gz | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
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; | ||
|
||
format = pkgs.formats.ini {}; | ||
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/id3v1669/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; | ||
} | ||
}); | ||
''; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ lib | ||
, rustPlatform | ||
, makeWrapper | ||
, pkg-config | ||
, udev | ||
, killall | ||
}: | ||
|
||
rustPlatform.buildRustPackage rec { | ||
|
||
pname = "swhkd"; | ||
version = "1.3.0"; | ||
|
||
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 | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
]; | ||
} |