diff --git a/README.md b/README.md index 0e461a4..0d74baf 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/flake.nix b/flake.nix index 0373556..c6544c7 100644 --- a/flake.nix +++ b/flake.nix @@ -9,6 +9,7 @@ systems = [ "x86_64-linux" "aarch64-linux" + "aarch64-darwin" ]; forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system}); in @@ -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 @@ -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; }; }; } diff --git a/nix/module/README.md b/nix/module/README.md new file mode 100644 index 0000000..585e47e --- /dev/null +++ b/nix/module/README.md @@ -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. diff --git a/nix/module.nix b/nix/module/common.nix similarity index 56% rename from nix/module.nix rename to nix/module/common.nix index e77955e..6acc292 100644 --- a/nix/module.nix +++ b/nix/module/common.nix @@ -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"; @@ -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 ]; - }; } diff --git a/nix/module/darwin/default.nix b/nix/module/darwin/default.nix new file mode 100644 index 0000000..dd5b455 --- /dev/null +++ b/nix/module/darwin/default.nix @@ -0,0 +1,14 @@ +{ + config, + lib, + ... +}: +let + cfg = config.programs.zapp; +in +{ + imports = [ ../common.nix ]; + config = lib.mkIf cfg.enable { + environment.systemPackages = [ cfg.package ]; + }; +} diff --git a/nix/module/nixos/default.nix b/nix/module/nixos/default.nix new file mode 100644 index 0000000..6921b0c --- /dev/null +++ b/nix/module/nixos/default.nix @@ -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 ]; + }; +} diff --git a/nix/package.nix b/nix/package.nix index 711bb37..00b7b1f 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -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 @@ -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 ''; @@ -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; }; }