Skip to content
Open
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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ You can download the latest version of zapp from the [releases](https://github.c
brew install zapp
```

nix-darwin is also supported. See the [Nix flakes](#flakes) section below for details.

### openSUSE

```sh
Expand Down Expand Up @@ -75,6 +77,26 @@ On NixOS, the flake exposes a module that installs the binary and registers the
}
```

On nix-darwin, the flake exposes a module that installs the binary:

```nix
{
inputs.zapp.url = "github:zsa/zapp";

outputs = { self, nixpkgs, zapp, ... }: {
darwinConfigurations.my-host = nix-darwin.lib.darwinSystem {
system = "aarch64-darwin";
modules = [
zapp.darwinModules.default
{ programs.zapp.enable = true; }
];
};
};
}
```

(Adjust nix-darwin.lib.darwinSystem to match your nix-darwin input.)

An overlay is also available (`zapp.overlays.default`) which adds `pkgs.zapp` to nixpkgs.

A `nix develop` shell with the Rust toolchain and `nixfmt` is provided for hacking on the flake itself.
Expand Down
14 changes: 11 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
in
Expand All @@ -22,7 +23,7 @@

devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
inputsFrom = [ self.packages.${pkgs.system}.zapp ];
inputsFrom = [ self.packages.${pkgs.stdenv.hostPlatform.system}.zapp ];
packages = [
pkgs.cargo
pkgs.rustc
Expand All @@ -38,8 +39,15 @@
nixosModules.default =
{ pkgs, ... }:
{
imports = [ ./nix/module.nix ];
programs.zapp.package = nixpkgs.lib.mkDefault self.packages.${pkgs.system}.default;
imports = [ ./nix/module/nixos ];
programs.zapp.package = nixpkgs.lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.default;
};

darwinModules.default =
{ pkgs, ... }:
{
imports = [ ./nix/module/darwin ];
programs.zapp.package = nixpkgs.lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.default;
};
};
}
11 changes: 11 additions & 0 deletions nix/module/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Modules

The flake exposes two modules:

- `zapp.nixosModules.default` (for NixOS)
- `zapp.darwinModules.default` (for nix-darwin)

Each are called from their respective sections in the main flake.nix. Both
modules source from nix/modules/common.nix, and only differ in how they handle
the module configuration: nixos registers a package with services.udev, while
nix-darwin does not.
10 changes: 0 additions & 10 deletions nix/module.nix → nix/module/common.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.zapp;
in
{
options.programs.zapp = {
enable = lib.mkEnableOption "zapp, a CLI tool for flashing ZSA keyboards";
Expand All @@ -16,9 +11,4 @@ in
description = "The zapp package to use.";
};
};

config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
services.udev.packages = [ cfg.package ];
};
}
14 changes: 14 additions & 0 deletions nix/module/darwin/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
config,
lib,
...
}:
let
cfg = config.programs.zapp;
in
{
imports = [ ../common.nix ];
config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
};
}
15 changes: 15 additions & 0 deletions nix/module/nixos/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
config,
lib,
...
}:
let
cfg = config.programs.zapp;
in
{
imports = [ ../common.nix ];
config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
services.udev.packages = [ cfg.package ];
};
}
23 changes: 13 additions & 10 deletions nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
rustPlatform,
pkg-config,
libusb1,
stdenv,
}:
let
fs = lib.fileset;
src = fs.toSource {
root = ../.;
fileset = fs.unions [
../Cargo.toml
../Cargo.lock
../zapp
../zapp-core
../zapp-oryx
../udev
];
fileset = fs.unions (
[
../Cargo.toml
../Cargo.lock
../zapp
../zapp-core
../zapp-oryx
]
++ lib.optional (!stdenv.isDarwin) ../udev
);
};
cargoToml = builtins.fromTOML (builtins.readFile ../zapp/Cargo.toml);
in
Expand All @@ -28,7 +31,7 @@ rustPlatform.buildRustPackage {
nativeBuildInputs = [ pkg-config ];
buildInputs = [ libusb1 ];

postInstall = ''
postInstall = lib.optionalString stdenv.isLinux ''
install -Dm644 udev/50-zsa.rules $out/lib/udev/rules.d/50-zsa.rules
'';

Expand All @@ -37,6 +40,6 @@ rustPlatform.buildRustPackage {
homepage = "https://github.com/zsa/zapp";
license = lib.licenses.mit;
mainProgram = "zapp";
platforms = lib.platforms.linux;
platforms = lib.platforms.linux ++ lib.platforms.darwin;
};
}