diff --git a/flake.lock b/flake.lock --- a/flake.lock +++ b/flake.lock @@ -159,6 +159,22 @@ "repo": "gitignore.nix", "type": "github" } }, + "kamid": { + "flake": false, + "locked": { + "lastModified": 1730762973, + "narHash": "sha256-FQA/nfc3/WqzN1FY5pBOxK2coc1Tw+hn9H4NvF7oCAU=", + "owner": "omar-polo", + "repo": "kamid", + "rev": "48e3b41db1a35f09e072985a9f238ca202999247", + "type": "github" + }, + "original": { + "owner": "omar-polo", + "repo": "kamid", + "type": "github" + } + }, "nix": { "inputs": { "flake-compat": [ @@ -250,6 +266,7 @@ "root": { "inputs": { "devenv": "devenv", "flake-parts": "flake-parts_2", + "kamid": "kamid", "nixpkgs": "nixpkgs_2", "systems": "systems" } diff --git a/flake.nix b/flake.nix --- a/flake.nix +++ b/flake.nix @@ -9,6 +9,10 @@ inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; inputs.flake-parts.url = "github:hercules-ci/flake-parts"; inputs.devenv.url = "github:cachix/devenv"; inputs.systems.url = "github:nix-systems/default"; + inputs.kamid = { + url = "github:omar-polo/kamid"; + flake = false; + }; outputs = {flake-parts, ...} @ inputs: flake-parts.lib.mkFlake {inherit inputs;} { @@ -18,11 +22,19 @@ ]; systems = import inputs.systems; - perSystem = {pkgs, ...}: { + perSystem = {pkgs, ...}: let + kamid = pkgs.callPackage ./nix/kamid { inherit inputs; }; + in { formatter = pkgs.alejandra; + packages = { + inherit kamid; + }; + devenv.shells.default = { languages.erlang.enable = true; + + packages = [ kamid ]; }; }; }; diff --git a/nix/kamid/default.nix b/nix/kamid/default.nix new file mode 100644 --- /dev/null +++ b/nix/kamid/default.nix @@ -0,0 +1,33 @@ +# SPDX-FileCopyrightText: 2026 Łukasz Niemier <~@hauleth.dev> +# +# SPDX-License-Identifier: Apache-2.0 + +{ + inputs, + + kamid, + autoreconfHook, + pkg-config, + bison, + stdenv, + + lib +}: + +kamid.overrideAttrs (old: { + version = "git"; + + src = inputs.kamid; + + nativeBuildInputs = old.nativeBuildInputs ++ [ + autoreconfHook + pkg-config + bison + ]; + + patches = lib.optionals stdenv.isDarwin [ ./macos.patch ]; + + meta.package.platforms = old.meta.package.platforms ++ [ + "aarch64-darwin" + ]; +}) diff --git a/nix/kamid/macos.patch b/nix/kamid/macos.patch new file mode 100644 --- /dev/null +++ b/nix/kamid/macos.patch @@ -0,0 +1,56 @@ +diff --git i/compat.h w/compat.h +index 2819b0e..349865e 100644 +--- i/compat.h ++++ w/compat.h +@@ -193,4 +193,7 @@ long long strtonum(const char *, long long, long long, const char **); + # include "compat/vis.h" + #endif + ++#define SOCK_CLOEXEC 0 ++#define SOCK_NONBLOCK 0 ++ + #endif /* COMPAT_H */ +diff --git i/kamid/client.c w/kamid/client.c +index 33e0206..063c698 100644 +--- i/kamid/client.c ++++ w/kamid/client.c +@@ -418,7 +418,7 @@ qid_update_from_sb(struct qid *qid, struct stat *sb) + * Theoretically (and hopefully!) this should be a 64 bit + * number. Unfortunately, 9P uses 32 bit timestamps. + */ +- qid->vers = sb->st_mtim.tv_sec; ++ qid->vers = sb->st_mtime; + + if (S_ISREG(sb->st_mode)) + qid->type = QTFILE; +@@ -1477,8 +1477,8 @@ serialize_stat(const char *fname, struct stat *sb, struct evbuffer *evb) + np_write32(evb, sb->st_dev); /* dev[4] */ + np_qid(evb, &qid); /* qid[13] */ + np_write32(evb, mode); /* mode[4] */ +- np_write32(evb, sb->st_atim.tv_sec); /* atime[4] */ +- np_write32(evb, sb->st_mtim.tv_sec); /* mtime[4] */ ++ np_write32(evb, sb->st_atime); /* atime[4] */ ++ np_write32(evb, sb->st_mtime); /* mtime[4] */ + + /* special case: directories have size 0 */ + if (qid.type & QTDIR) +diff --git i/kamid/control.c w/kamid/control.c +index 9fef9a5..dd44435 100644 +--- i/kamid/control.c ++++ w/kamid/control.c +@@ -67,12 +67,14 @@ control_init(const char *path) + int fd; + mode_t old_umask; + +- if ((fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, ++ if ((fd = socket(AF_UNIX, SOCK_STREAM, + 0)) == -1) { + log_warn("%s: socket", __func__); + return (-1); + } + ++ fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK | O_CLOEXEC); ++ + memset(&sun, 0, sizeof(sun)); + sun.sun_family = AF_UNIX; + strlcpy(sun.sun_path, path, sizeof(sun.sun_path)); diff --git a/nix/kamid/macos.patch.license b/nix/kamid/macos.patch.license new file mode 100644 --- /dev/null +++ b/nix/kamid/macos.patch.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2026 Łukasz Niemier <~@hauleth.dev> + +SPDX-License-Identifier: Apache-2.0