-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
flake.nix
213 lines (190 loc) · 7.23 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
{
description = "CLI to manage timers";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
# https://github.com/nix-community/fenix/pull/145
# url = "github:nix-community/fenix";
url = "github:soywod/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = { self, nixpkgs, gitignore, fenix, naersk, ... }:
let
inherit (nixpkgs) lib;
inherit (gitignore.lib) gitignoreSource;
crossSystems = {
x86_64-linux = {
x86_64-linux = {
rustTarget = "x86_64-unknown-linux-musl";
};
aarch64-linux = rec {
rustTarget = "aarch64-unknown-linux-musl";
runner = { pkgs, comodoro }: "${pkgs.qemu}/bin/qemu-aarch64 ${comodoro}";
mkPackage = { system, ... }: package:
let
inherit (mkPkgsCross system rustTarget) stdenv;
cc = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
in
package // {
TARGET_CC = cc;
CARGO_BUILD_RUSTFLAGS = package.CARGO_BUILD_RUSTFLAGS ++ [ "-Clinker=${cc}" ];
};
};
x86_64-windows = {
rustTarget = "x86_64-pc-windows-gnu";
runner = { pkgs, comodoro }:
let wine = pkgs.wine.override { wineBuild = "wine64"; };
in "${wine}/bin/wine64 ${comodoro}.exe";
mkPackage = { pkgs, ... }: package:
let
inherit (pkgs.pkgsCross.mingwW64) stdenv windows;
cc = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
in
package // {
depsBuildBuild = [ stdenv.cc windows.pthreads ];
TARGET_CC = cc;
CARGO_BUILD_RUSTFLAGS = package.CARGO_BUILD_RUSTFLAGS ++ [ "-Clinker=${cc}" ];
};
};
};
aarch64-linux.aarch64-linux = {
rustTarget = "aarch64-unknown-linux-musl";
};
x86_64-darwin.x86_64-darwin = {
rustTarget = "x86_64-apple-darwin";
mkPackage = { pkgs, ... }: package:
let inherit (pkgs.darwin.apple_sdk.frameworks) Cocoa;
inherit (pkgs.darwin.apple_sdk_11_0.frameworks) AppKit Security;
in
package // {
buildInputs = [ Cocoa ];
NIX_LDFLAGS = [
"-F${AppKit}/Library/Frameworks"
"-framework AppKit"
"-F${Security}/Library/Frameworks"
"-framework Security"
];
};
};
aarch64-darwin.aarch64-darwin = {
rustTarget = "aarch64-apple-darwin";
mkPackage = { pkgs, ... }: package:
let inherit (pkgs.darwin.apple_sdk.frameworks) Cocoa;
in package // {
buildInputs = [ Cocoa ];
};
};
};
eachBuildSystem = lib.genAttrs (builtins.attrNames crossSystems);
mkPkgsCross = buildSystem: crossSystem: import nixpkgs {
system = buildSystem;
crossSystem.config = crossSystem;
};
mkToolchain = import ./rust-toolchain.nix fenix;
mkApp = { pkgs, buildSystem, targetSystem ? buildSystem }:
let
comodoro = lib.getExe self.packages.${buildSystem}.${targetSystem};
wrapper = crossSystems.${buildSystem}.${targetSystem}.runner or (_: comodoro) { inherit pkgs comodoro; };
program = lib.getExe (pkgs.writeShellScriptBin "comodoro" "${wrapper} $@");
app = { inherit program; type = "app"; };
in
app;
mkApps = buildSystem:
let
pkgs = import nixpkgs { system = buildSystem; };
mkApp' = targetSystem: _: mkApp { inherit pkgs buildSystem targetSystem; };
defaultApp = mkApp { inherit pkgs buildSystem; };
apps = builtins.mapAttrs mkApp' crossSystems.${buildSystem};
in
apps // { default = defaultApp; };
mkPackage = { pkgs, buildSystem, targetSystem ? buildSystem }:
let
targetConfig = crossSystems.${buildSystem}.${targetSystem};
toolchain = mkToolchain.fromTarget {
inherit pkgs buildSystem;
targetSystem = targetConfig.rustTarget;
};
rust = naersk.lib.${buildSystem}.override {
cargo = toolchain;
rustc = toolchain;
};
mkPackage' = targetConfig.mkPackage or (_: p: p);
comodoro = "./comodoro";
runner = targetConfig.runner or (_: comodoro) { inherit pkgs comodoro; };
package = mkPackage' { inherit pkgs; system = buildSystem; } {
name = "comodoro";
src = gitignoreSource ./.;
strictDeps = true;
doCheck = false;
auditable = false;
nativeBuildInputs = with pkgs; [ pkg-config ];
CARGO_BUILD_TARGET = targetConfig.rustTarget;
CARGO_BUILD_RUSTFLAGS = [ "-Ctarget-feature=+crt-static" ];
postInstall = ''
export WINEPREFIX="$(mktemp -d)"
mkdir -p $out/bin/share/{completions,man}
cd $out/bin
${runner} man ./share/man
${runner} completion bash > ./share/completions/comodoro.bash
${runner} completion elvish > ./share/completions/comodoro.elvish
${runner} completion fish > ./share/completions/comodoro.fish
${runner} completion powershell > ./share/completions/comodoro.powershell
${runner} completion zsh > ./share/completions/comodoro.zsh
tar -czf comodoro.tgz comodoro* share
mv comodoro.tgz ../
${pkgs.zip}/bin/zip -r comodoro.zip comodoro* share
mv comodoro.zip ../
'';
};
in
rust.buildPackage package;
mkPackages = buildSystem:
let
pkgs = import nixpkgs { system = buildSystem; };
mkPackage' = targetSystem: _: mkPackage { inherit pkgs buildSystem targetSystem; };
defaultPackage = mkPackage { inherit pkgs buildSystem; };
packages = builtins.mapAttrs mkPackage' crossSystems.${buildSystem};
in
packages // { default = defaultPackage; };
mkDevShells = buildSystem:
let
pkgs = import nixpkgs { system = buildSystem; };
rust-toolchain = mkToolchain.fromFile { inherit buildSystem; };
defaultShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [
# Nix
nixd
nixpkgs-fmt
# Rust
rust-toolchain
cargo-watch
# Email env
gnupg
gpgme
msmtp
notmuch
];
};
in
{ default = defaultShell; };
in
{
apps = eachBuildSystem mkApps;
packages = eachBuildSystem mkPackages;
devShells = eachBuildSystem mkDevShells;
};
}