From f99b7ba23d692011d7d081169af62a2535a06bac Mon Sep 17 00:00:00 2001 From: Sam Willcocks Date: Fri, 1 Jul 2022 19:38:37 +0100 Subject: [PATCH] Add flake and some utils --- .envrc | 1 + .gitignore | 1 + README.md | 1 + flake.lock | 92 +++++++++++++++++++++++++++++++++++++++++ flake.nix | 28 +++++++++++++ pjsip/default.nix | 53 ++++++++++++++++++++++++ pjsip/fix-aarch64.patch | 13 ++++++ 7 files changed, 189 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 README.md create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 pjsip/default.nix create mode 100644 pjsip/fix-aarch64.patch diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92b2793 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.direnv diff --git a/README.md b/README.md new file mode 100644 index 0000000..dc96f1f --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +This is discosip, PRJ16, an attempt to enable use of discord from a SIP phone. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a3bb57d --- /dev/null +++ b/flake.lock @@ -0,0 +1,92 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1655976588, + "narHash": "sha256-VreHyH6ITkf/1EX/8h15UqhddJnUleb0HgbC3gMkAEQ=", + "owner": "numtide", + "repo": "devshell", + "rev": "899ca4629020592a13a46783587f6e674179d1db", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1642700792, + "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1643381941, + "narHash": "sha256-pHTwvnN4tTsEKkWlXQ8JMY423epos8wUOhthpwJjtpc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5efc8ca954272c4376ac929f4c5ffefcc20551d5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1656490020, + "narHash": "sha256-xonV1ITvAtwtoM58Iaz77mrkkj3NQKvP2QOPYZNiNvs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "23488b5815ef60b3084a874f71fdae2dff52e1f7", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "nixpkgs": "nixpkgs_2", + "utils": "utils" + } + }, + "utils": { + "locked": { + "lastModified": 1656065134, + "narHash": "sha256-oc6E6ByIw3oJaIyc67maaFcnjYOz1mMcOtHxbEf9NwQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "bee6a7250dd1b01844a2de7e02e4df7d8a0a206c", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..9a9fc3e --- /dev/null +++ b/flake.nix @@ -0,0 +1,28 @@ +{ + description = "A basic flake from samw"; + inputs = { + utils.url = "github:numtide/flake-utils"; + devshell.url = "github:numtide/devshell"; + }; + outputs = { + self, + nixpkgs, + utils, + devshell, + }: + utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs { + inherit system; + + overlays = [devshell.overlay]; + }; + in { + devShells.default = pkgs.devshell.mkShell { + packages = with pkgs; [ + ffmpeg + (callPackage ./pjsip {inherit (darwin.apple_sdk.frameworks) AppKit;}) + ]; + }; + formatter = pkgs.alejandra; + }); +} diff --git a/pjsip/default.nix b/pjsip/default.nix new file mode 100644 index 0000000..4d5141e --- /dev/null +++ b/pjsip/default.nix @@ -0,0 +1,53 @@ +{ + lib, + stdenv, + fetchFromGitHub, + openssl, + libsamplerate, + alsa-lib, + AppKit, + fetchpatch, +}: +stdenv.mkDerivation rec { + pname = "pjsip"; + version = "2.12.1"; + + src = fetchFromGitHub { + owner = pname; + repo = "pjproject"; + rev = version; + sha256 = "sha256-HIDL4xzzTu3irzrIOf8qSNCAvHGOMpi8EDeqZb8mMnc="; + }; + + patches = [ + ./fix-aarch64.patch + ]; + + buildInputs = + [openssl libsamplerate] + ++ lib.optional stdenv.isLinux alsa-lib + ++ lib.optional stdenv.isDarwin AppKit; + + preConfigure = '' + export LD=$CC + ''; + + postInstall = '' + mkdir -p $out/bin + cp pjsip-apps/bin/pjsua-* $out/bin/pjsua + mkdir -p $out/share/${pname}-${version}/samples + cp pjsip-apps/bin/samples/*/* $out/share/${pname}-${version}/samples + ''; + + # We need the libgcc_s.so.1 loadable (for pthread_cancel to work) + dontPatchELF = true; + + meta = with lib; { + description = "A multimedia communication library written in C, implementing standard based protocols such as SIP, SDP, RTP, STUN, TURN, and ICE"; + homepage = "https://pjsip.org/"; + license = licenses.gpl2Plus; + maintainers = with maintainers; [olynch]; + mainProgram = "pjsua"; + platforms = platforms.linux ++ platforms.darwin; + }; +} diff --git a/pjsip/fix-aarch64.patch b/pjsip/fix-aarch64.patch new file mode 100644 index 0000000..1680bde --- /dev/null +++ b/pjsip/fix-aarch64.patch @@ -0,0 +1,13 @@ +--- a/aconfigure ++++ b/aconfigure +@@ -9174,6 +9174,10 @@ + ac_webrtc_instset=neon + ac_webrtc_cflags="-DWEBRTC_ARCH_ARM64" + ;; ++ arm64*|aarch64*) ++ ac_webrtc_instset=neon ++ ac_webrtc_cflags="-DWEBRTC_ARCH_ARM64" ++ ;; + *) + ac_webrtc_instset=sse2 + ;;