-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
flake.nix
165 lines (145 loc) · 5.15 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
# SPDX-FileCopyrightText: 2023 Christina Sørensen
# SPDX-FileContributor: Christina Sørensen
#
# SPDX-License-Identifier: AGPL-3.0-only
{
description = "rime: Nix Flake Input Versioning";
inputs = {
flake-utils.url = "http://rime.cx/v1/github/semnix/flake-utils.tar.gz";
naersk.url = "http://rime.cx/v1/github/semnix/naersk.tar.gz";
nixpkgs.url = "http:/rime.cx/v1/github/NixOS/nixpkgs/b/nixpkgs-unstable.tar.gz";
treefmt-nix.url = "http://rime.cx/v1/github/semnix/treefmt-nix.tar.gz";
rust-overlay.url = "http://rime.cx/v1/github/semnix/rust-overlay.tar.gz";
pre-commit-hooks = {
url = "http://rime.cx/v1/github/semnix/pre-commit-hooks.nix.tar.gz";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs = {
self,
flake-utils,
naersk,
nixpkgs,
treefmt-nix,
rust-overlay,
pre-commit-hooks,
}:
flake-utils.lib.eachDefaultSystem (
system: let
overlays = [(import rust-overlay)];
pkgs = (import nixpkgs) {
inherit system overlays;
};
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
naersk' = pkgs.callPackage naersk {
cargo = toolchain;
rustc = toolchain;
clippy = toolchain;
};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
darwinBuildInputs = with pkgs; with darwin.apple_sdk.frameworks; [libiconv Security SystemConfiguration];
buildInputs = with pkgs; [pkg-config openssl] ++ lib.optionals stdenv.isDarwin darwinBuildInputs;
in rec {
# For `nix fmt`
formatter = treefmtEval.config.build.wrapper;
packages = {
# For `nix build` & `nix run`:
default = naersk'.buildPackage {
src = ./.;
doCheck = true; # run `cargo test` on build
copyBins = true;
copyLibs = true;
singleStep = true;
inherit buildInputs;
nativeBuildInputs = with pkgs; [makeWrapper installShellFiles];
MAN_OUT = "./man";
preBuild = ''
mkdir -p "./$MAN_OUT";
'';
preInstall = ''
installManPage man/rime.1
installShellCompletion \
--fish man/rime.fish \
--bash man/rime.bash \
--zsh man/_rime
mkdir -p $out
'';
};
container = pkgs.dockerTools.buildLayeredImage {
name = "rime";
tag = "latest";
contents = [packages.default pkgs.cacert];
config = {
Labels = {
"org.opencontainers.image.source" = "https://github.com/cafkafk/rime";
"org.opencontainers.image.description" = "rime: Nix Flake Input Versioning";
"org.opencontainers.image.license" = "AGPL-3.0-only";
};
Env = [
"RUST_LOG=trace"
];
Cmd = ["/bin/rime"];
};
};
# Run `nix build .#check` to check code
check = naersk'.buildPackage {
src = ./.;
mode = "check";
inherit buildInputs;
};
# Run `nix build .#test` to run tests
test = naersk'.buildPackage {
src = ./.;
mode = "test";
inherit buildInputs;
};
# Run `nix build .#clippy` to lint code
clippy = naersk'.buildPackage {
src = ./.;
mode = "clippy";
inherit buildInputs;
};
};
# For `nix develop`:
devShells.default = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
nativeBuildInputs = with pkgs; [rustup toolchain just zip reuse pkg-config openssl vhs fish];
};
# For `nix flake check`
checks = {
pre-commit-check = let
# some treefmt formatters are not supported in pre-commit-hooks we filter them out for now.
toFilter =
# HACK: This is a nice hack to not have to manually filter we should keep in mind for a future refactor.
# Stolen from eza
["yamlfmt"];
filterFn = n: _v: (!builtins.elem n toFilter);
treefmtFormatters = pkgs.lib.mapAttrs (_n: v: {inherit (v) enable;}) (pkgs.lib.filterAttrs filterFn (import ./treefmt.nix).programs);
in
pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks =
treefmtFormatters
// {
convco.enable = true; # not in treefmt
reuse = {
enable = true;
name = "reuse";
entry = with pkgs; "${pkgs.reuse}/bin/reuse lint";
pass_filenames = false;
};
};
};
formatting = treefmtEval.config.build.check self;
build = packages.check;
inherit
(packages)
default
test
;
lint = packages.clippy;
};
}
);
}