Skip to content

Commit fb5b46b

Browse files
authored
Merge pull request #1 from formalco/eric/refactor-add-mac-support
FEATREQ-19: Add MacOS support to Nix overlays
2 parents 959b85a + 86ce3e4 commit fb5b46b

File tree

6 files changed

+165
-43
lines changed

6 files changed

+165
-43
lines changed

.github/workflows/test-build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ jobs:
1515
runner: ubuntu-24.04
1616
- os: Linux arm64
1717
runner: ubuntu-24.04-arm
18+
- os: macOS arm64
19+
runner: macos-latest
20+
- os: macOS x86_64
21+
runner: macos-latest
1822
runs-on: ${{ matrix.target.runner }}
1923
steps:
2024
- uses: actions/checkout@v4

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,39 @@ add the overlay as shown below:
5656
}
5757
```
5858

59+
## Use with nix-darwin flake (recommended)
60+
If you're using a flake for your nix-darwin configuration, you can
61+
add the overlay as shown below:
62+
```nix
63+
{
64+
inputs = {
65+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
66+
nix-darwin = {
67+
url = "github:nix-darwin/nix-darwin/master";
68+
inputs.nixpkgs.follows = "nixpkgs";
69+
}
70+
formal-overlay = {
71+
url = "github:formalco/formal-overlay";
72+
inputs.nixpkgs.follows = "nixpkgs";
73+
};
74+
};
75+
76+
outputs = { self, nix-darwin, nixpkgs, formal-overlay }:
77+
{
78+
# Build darwin flake using:
79+
# $ darwin-rebuild build --flake .#yourHost
80+
darwinConfigurations.yourHost = nix-darwin.lib.darwinSystem {
81+
modules = [
82+
./configuration.nix
83+
{
84+
nixpkgs.overlays = [ formal-overlay.overlays.default ];
85+
}
86+
];
87+
};
88+
};
89+
}
90+
```
91+
5992
## With fetchTarball
6093
If you're using a `configuration.nix` file, this approach is recommended. A
6194
sample configuration is shown below:

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
systems = [
1313
"x86_64-linux"
1414
"aarch64-linux"
15+
"aarch64-darwin"
1516
];
1617

1718
eachSystem =

pkgs/darwin.nix

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
stdenv,
3+
fetchurl,
4+
pname,
5+
version,
6+
meta,
7+
cpio,
8+
xar,
9+
}:
10+
11+
let
12+
inherit (stdenv.hostPlatform) system;
13+
fetch = hash: fetchurl {
14+
url = "https://static-assets.formalcloud.net/desktop-app/darwin/formal-${version}.pkg";
15+
inherit hash;
16+
};
17+
18+
platforms = [ "aarch64-darwin" "x86_64-darwin" ];
19+
in
20+
stdenv.mkDerivation {
21+
inherit pname version meta;
22+
23+
src = fetch "sha256-OnR3t+/Et9CWuomWZl+KyL/vdO+MOZyhJnyM6WkIVZY=";
24+
25+
nativeBuildInputs = [
26+
cpio
27+
xar
28+
];
29+
30+
unpackPhase = ''
31+
runHook preUnpack
32+
33+
xar -xf $src
34+
gunzip -c Payload | cpio -i
35+
gunzip -c Scripts | cpio -i
36+
37+
runHook postUnpack
38+
'';
39+
40+
installPhase = ''
41+
runHook preInstall
42+
43+
mkdir -p "$out"/Applications/Formal.app
44+
cp -r Contents "$out"/Applications/Formal.app
45+
46+
mkdir -p "$out"/bin
47+
cp Contents/MacOS/formal "$out"/bin/formal
48+
49+
runHook postInstall
50+
'';
51+
}

pkgs/formal.nix

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,40 @@
22
lib,
33
stdenv,
44
fetchurl,
5+
callPackage,
56
dpkg,
67
autoPatchelfHook,
78
gtk3,
9+
cpio,
10+
xar,
811
libayatana-appindicator,
912
}:
1013

1114
let
12-
inherit (stdenv.hostPlatform) system;
13-
version = "0.1.4";
14-
fetch = arch: hash: fetchurl {
15-
url = "https://static-assets.formalcloud.net/desktop-app/linux/formal-desktop_${version}_${arch}.deb";
16-
inherit hash;
17-
};
18-
sources = rec {
19-
aarch64-linux = fetch "arm64" "sha256-yidonBngXgYO6r1JA3i938ZBBg0JTEjVxS9jyDSSWGY=";
20-
x86_64-linux = fetch "amd64" "sha256-RiDafFAGewcydJguR57kzhoYahojR/oLj2AFiWxehvM=";
21-
};
22-
platforms = builtins.attrNames sources;
23-
in
24-
stdenv.mkDerivation rec {
2515
pname = "formal";
26-
inherit version;
27-
28-
src = if (builtins.elem system platforms) then
29-
sources.${system}
30-
else
31-
throw "Unsupported system: ${system}";
32-
33-
nativeBuildInputs = [
34-
dpkg
35-
autoPatchelfHook
36-
];
37-
38-
buildInputs = [
39-
gtk3
40-
libayatana-appindicator
41-
];
42-
43-
installPhase = ''
44-
runHook preInstall
45-
install -D -m755 usr/bin/formal $out/bin/formal
46-
install -D usr/share/pixmaps/formal.png $out/share/pixmaps/formal.png
47-
substituteInPlace usr/share/applications/formal.desktop \
48-
--replace-fail /usr/bin/formal $out/bin/formal
49-
install -D -m644 usr/share/applications/formal.desktop $out/share/applications/formal.desktop
50-
51-
runHook postInstall
52-
'';
53-
16+
version = "0.3.1";
5417
meta = {
5518
description = "Formal Desktop";
5619
homepage = "https://joinformal.com";
5720
mainProgram = "formal";
5821
license = lib.licenses.unfree;
59-
platforms = lib.platforms.linux;
22+
platforms = lib.platforms.linux ++ lib.platforms.darwin;
6023
};
61-
}
24+
in
25+
# Referenced from https://github.com/NixOS/nixpkgs/blob/590a11b096aed29944ecb4ee32b746155117f85c/pkgs/by-name/_1/_1password-gui/package.nix
26+
if stdenv.hostPlatform.isDarwin then
27+
callPackage ./darwin.nix {
28+
inherit
29+
pname
30+
version
31+
meta
32+
;
33+
}
34+
else
35+
callPackage ./linux.nix {
36+
inherit
37+
pname
38+
version
39+
meta
40+
;
41+
}

pkgs/linux.nix

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
stdenv,
3+
fetchurl,
4+
pname,
5+
version,
6+
meta,
7+
dpkg,
8+
autoPatchelfHook,
9+
gtk3,
10+
libayatana-appindicator,
11+
}:
12+
13+
let
14+
inherit (stdenv.hostPlatform) system;
15+
fetch = arch: hash: fetchurl {
16+
url = "https://static-assets.formalcloud.net/desktop-app/linux/formal-desktop_${version}_${arch}.deb";
17+
inherit hash;
18+
};
19+
20+
sources = rec {
21+
aarch64-linux = fetch "arm64" "sha256-GrHTSo0uIx6KzB3xO8tXKLNdBRVf71Awkgniwbvag1w=";
22+
x86_64-linux = fetch "amd64" "sha256-9FwakjTp1MJDl7ioyobgf38ycdwmOYi+KThcD5ZOOhY=";
23+
};
24+
platforms = builtins.attrNames sources;
25+
in
26+
stdenv.mkDerivation {
27+
inherit pname version meta;
28+
29+
src = if (builtins.elem system platforms) then
30+
sources.${system}
31+
else
32+
throw "Unsupported system: ${system}";
33+
34+
nativeBuildInputs = [
35+
dpkg
36+
autoPatchelfHook
37+
];
38+
39+
buildInputs = [
40+
gtk3
41+
libayatana-appindicator
42+
];
43+
44+
installPhase = ''
45+
runHook preInstall
46+
install -D -m755 usr/bin/formal $out/bin/formal
47+
install -D usr/share/pixmaps/formal.png $out/share/pixmaps/formal.png
48+
substituteInPlace usr/share/applications/formal.desktop \
49+
--replace-fail /usr/bin/formal $out/bin/formal
50+
install -D -m644 usr/share/applications/formal.desktop $out/share/applications/formal.desktop
51+
runHook postInstall
52+
'';
53+
}

0 commit comments

Comments
 (0)