-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
114 lines (102 loc) · 3.06 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{
description = "razer-laptop-control";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
inputs@{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
name = "razer-laptop-control";
in
{
formatter = pkgs.nixfmt-rfc-style;
packages.default = pkgs.rustPlatform.buildRustPackage {
pname = name;
version = "0.2.0";
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [
dbus.dev
hidapi
systemd
glib
pango
gtk3
];
src = ./razer_control_gui;
postConfigure = ''
substituteInPlace src/daemon/device.rs --replace '/usr/share/razercontrol/laptops.json' '${./razer_control_gui/data/devices/laptops.json}'
'';
postBuild =
let
app = "razer-settings";
path = "$out/share/applications/${app}.desktop";
in
''
# Install .desktop file
mkdir -p $out/share/applications
cat > ${path} <<EOF
[Desktop Entry]
Name=Razer Settings
Exec=$out/bin/${app}
Type=Application
Categories=Utility;
EOF
chmod +x ${path}
'';
postInstall = ''
mkdir -p $out/lib/udev/rules.d
mkdir -p $out/libexec
mv $out/bin/daemon $out/libexec
cp ${./razer_control_gui/data/udev/99-hidraw-permissions.rules} $out/lib/udev/rules.d/99-hidraw-permissions.rules
'';
cargoLock = {
lockFile = ./razer_control_gui/Cargo.lock;
};
};
}
)
// {
nixosModules.default =
{
config,
lib,
pkgs,
...
}:
with lib;
let
cfg = config.services.razer-laptop-control;
in
{
options.services.razer-laptop-control = {
enable = mkEnableOption "Enables razer-laptop-control";
package = mkOption {
type = types.package;
default = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.default;
};
};
config = mkIf cfg.enable {
services.upower.enable = true;
environment.systemPackages = [ cfg.package ];
services.udev.packages = [ cfg.package ];
systemd.user.services."razerdaemon" = {
description = "Razer laptop control daemon";
serviceConfig = {
Type = "simple";
ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p %h/.local/share/razercontrol";
ExecStart = "${cfg.package}/libexec/daemon";
};
wantedBy = [ "default.target" ];
};
};
};
};
}