Skip to content

Commit

Permalink
Merge pull request kmonad#586 from mtoohey31/feat/nix-darwin-support
Browse files Browse the repository at this point in the history
Support x86_64-darwin in flake
  • Loading branch information
slotThe committed Jan 3, 2023
2 parents 995e735 + 9a88e7e commit 1ee4644
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 8 deletions.
1 change: 1 addition & 0 deletions c_src/mac/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
list-keyboards
12 changes: 10 additions & 2 deletions c_src/mac/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
all: list-keyboards.c
gcc $< -o list-keyboards -framework IOKit -framework CoreFoundation
.PHONY: all install

all: list-keyboards

install: list-keyboards
mkdir -p $(DESTDIR)/bin
cp $< $(DESTDIR)/bin

list-keyboards: list-keyboards.c
$(CC) $< -o $@ -framework IOKit -framework CoreFoundation
13 changes: 12 additions & 1 deletion doc/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ because you installed it yourself or because you are using NixOS, you can build
nix-build nix
```

On MacOS, you'll have to use something like the following to get nix to pull in
the karabiner submodule:

```shell
nix build "./nix?submodules=1"
```

If you want to pull in kmonad as a flake input for configuring a darwin system,
you may find it necessary to use a reference like:
`git+https://github.com/kmonad/kmonad?submodules=1&dir=nix` instead of
`github:...`.

Another option with `nix` is to use the `nix-shell` to ensure you have the
correct environment to run `stack` in. You can enter the development environment
using:
Expand All @@ -66,7 +78,6 @@ using:
nix-shell nix/shell.nix
```


Note: we do also have to compile a little bit of C-code, so make sure `gcc` is
installed as well.

Expand Down
46 changes: 41 additions & 5 deletions nix/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
outputs = { self, nixpkgs, ... }@inputs:
let
# List of supported systems:
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];

# List of supported compilers:
supportedCompilers = [
Expand Down Expand Up @@ -46,10 +51,30 @@

# The package derivation:
derivation = pkgs: haskell: (
haskell.callCabal2nix "kmonad" (haskellSourceFilter ../.) { }
haskell.callCabal2nixWithOptions "kmonad" (haskellSourceFilter ../.)
(pkgs.lib.strings.optionalString
pkgs.stdenv.hostPlatform.isDarwin
"--flag=dext")
{ }
).overrideAttrs (orig: {
buildInputs = orig.buildInputs ++ [ (fakeGit pkgs) ];
});
buildInputs = orig.buildInputs ++ [ (fakeGit pkgs) ] ++
(pkgs.lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
pkgs.darwin.apple_sdk.frameworks.CoreFoundation
pkgs.darwin.IOKit
]);
} // (pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isDarwin {
configureFlags = orig.configureFlags ++ [
"--extra-include-dirs=c_src/mac/Karabiner-DriverKit-VirtualHIDDevice/src/Client/vendor/include"
"--extra-include-dirs=c_src/mac/Karabiner-DriverKit-VirtualHIDDevice/include/pqrs/karabiner/driverkit"
];
statSubmodulePhase = ''
stat c_src/mac/Karabiner-DriverKit-VirtualHIDDevice/include || (
echo "Karabiner submodule not found. This flake needs to be built with submodules on darwin. See the kmonad docs for more information." 1>&2
exit 1
)
'';
preConfigurePhases = [ "statSubmodulePhase" ] ++ orig.preConfigurePhases;
}));
in
{
packages = forAllSystems (system:
Expand All @@ -61,7 +86,18 @@
# Just the executables for the default compiler:
default = pkgs.haskell.lib.justStaticExecutables
(derivation pkgs pkgs.haskellPackages);
} // builtins.listToAttrs (map
} // (pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isDarwin {
list-keyboards = pkgs.stdenv.mkDerivation {
name = "list-keyboards";
version = self.shortRev;
src = ../c_src/mac;
buildInputs = [
pkgs.darwin.apple_sdk.frameworks.CoreFoundation
pkgs.darwin.IOKit
];
installFlags = [ "DESTDIR=$(out)" ];
};
}) // builtins.listToAttrs (map
(compiler: {
name = "kmonad-${compiler}";
value = derivation pkgs pkgs.haskell.packages.${compiler};
Expand Down

0 comments on commit 1ee4644

Please sign in to comment.