-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathflake.nix
185 lines (171 loc) · 6.25 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/staging-next";
crane.url = "github:ipetkov/crane";
utils.url = "github:numtide/flake-utils";
treefmt-nix.url = "github:numtide/treefmt-nix";
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
helix = {
url = "github:JordanForks/helix";
flake = false;
};
nix-github-actions = {
url = "github:nix-community/nix-github-actions";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, utils, crane, advisory-db, treefmt-nix, helix, nix-github-actions }:
{
githubActions = nix-github-actions.lib.mkGithubMatrix {
checks =
builtins.mapAttrs
(name: value: if name != "x86_64-linux" then removeAttrs value [ "clippy" "audit" "formatting" "doc" ] else value)
{ inherit (self.checks) x86_64-linux aarch64-darwin; };
};
}
//
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
craneLib = crane.mkLib pkgs;
cargoOnlySrc = craneLib.cleanCargoSource ./.;
src = pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [
./.cargo
./Cargo.toml
./Cargo.lock
./tree-sitter-grammar-repository
./src
./statics
./templates
./themes
./deny.toml
./build.rs
];
};
rgit-grammar = pkgs.callPackage ./grammars.nix { inherit helix; };
commonArgs = {
inherit src;
strictDeps = true;
buildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin [ pkgs.libiconv ];
nativeBuildInputs = with pkgs; [ cmake clang ];
LIBCLANG_PATH = "${pkgs.clang.cc.lib}/lib";
ROCKSDB_LIB_DIR = "${pkgs.rocksdb}/lib";
};
cargoArtifacts = craneLib.buildDepsOnly (commonArgs // { src = cargoOnlySrc; });
buildArgs = commonArgs // {
inherit cargoArtifacts;
buildInputs = [ rgit-grammar ] ++ commonArgs.buildInputs;
TREE_SITTER_GRAMMAR_LIB_DIR = rgit-grammar;
};
rgit = craneLib.buildPackage (buildArgs // { doCheck = false; });
treefmt = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
{
checks = {
build = rgit;
clippy = craneLib.cargoClippy buildArgs;
doc = craneLib.cargoDoc buildArgs;
audit = craneLib.cargoAudit { inherit advisory-db; src = cargoOnlySrc; };
deny = craneLib.cargoDeny { inherit src; };
test = craneLib.cargoNextest (buildArgs // {
partitions = 1;
partitionType = "count";
});
formatting = treefmt.config.build.check self;
};
formatter = treefmt.config.build.wrapper;
packages.default = rgit;
apps.default = utils.lib.mkApp { drv = rgit; };
devShells.default = craneLib.devShell {
checks = self.checks.${system};
};
nixosModules.default = { config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.rgit;
in
{
options.services.rgit = {
enable = mkEnableOption "rgit";
bindAddress = mkOption {
default = "[::]:8333";
description = "Address and port to listen on";
type = types.str;
};
dbStorePath = mkOption {
default = "/tmp/rgit.db";
description = "Path to store the temporary cache";
type = types.path;
};
repositoryStorePath = mkOption {
default = "/git";
description = "Path to repositories";
type = types.path;
};
requestTimeout = mkOption {
default = "10s";
description = "Timeout for incoming HTTP requests";
type = types.str;
};
package = mkOption {
default = rgit;
description = "rgit package to use";
type = types.package;
};
};
config = mkIf cfg.enable {
users.groups.rgit = { };
users.users.rgit = {
description = "RGit service user";
group = "rgit";
isSystemUser = true;
home = "/git";
};
systemd.services.rgit = {
enable = true;
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
path = [ pkgs.git ];
serviceConfig = {
Type = "exec";
ExecStart = "${cfg.package}/bin/rgit --request-timeout ${cfg.requestTimeout} --db-store ${cfg.dbStorePath} ${cfg.bindAddress} ${cfg.repositoryStorePath}";
Restart = "on-failure";
User = "rgit";
Group = "rgit";
CapabilityBoundingSet = "";
NoNewPrivileges = true;
PrivateDevices = true;
PrivateTmp = true;
PrivateUsers = true;
PrivateMounts = true;
ProtectHome = true;
ProtectClock = true;
ProtectProc = "noaccess";
ProcSubset = "pid";
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectControlGroups = true;
ProtectHostname = true;
RestrictSUIDSGID = true;
RestrictRealtime = true;
RestrictNamespaces = true;
LockPersonality = true;
RemoveIPC = true;
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
SystemCallFilter = [ "@system-service" "~@privileged" ];
};
};
};
};
});
nixConfig = {
extra-substituters = [ "https://rgit.cachix.org" ];
extra-trusted-public-keys = [ "rgit.cachix.org-1:3Wva/GHhrlhbYx+ObbEYQSYq1Yzk8x9OAvEvcYazgL0=" ];
};
}