-
Notifications
You must be signed in to change notification settings - Fork 31
/
flake.nix
152 lines (139 loc) · 4.8 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
{
description = "Radicle web frontend";
inputs = {
nixpkgs.follows = "heartwood/nixpkgs";
flake-utils.follows = "heartwood/flake-utils";
heartwood = {
url = "git+https://seed.radicle.xyz/z3gqcJUoA1n9HaHKufZs5FCSGazv5.git?ref=refs/namespaces/z6MksFqXN3Yhqk8pTJdUGLwATkRfQvwZXPqR2qMEhbS9wzpT/refs/tags/v1.0.0";
};
};
outputs = {
self,
heartwood,
nixpkgs,
flake-utils,
...
}@inputs:
{
nixosModules.radicle-explorer = { config, lib, pkgs, ... }: {
options.services.radicle-explorer.enable = lib.mkEnableOption "Local radicle web interface";
config = lib.mkIf config.services.radicle-explorer.enable {
services.nginx = {
enable = true;
virtualHosts.localhost = {
listen = [ { addr = "127.0.0.1"; port = 4433; ssl = false; } ];
rejectSSL = true;
locations = {
"/" = {
index = "index.html";
root = self.packages.${pkgs.system}.radicle-explorer;
extraConfig = ''
try_files $uri $uri/ /index.html;
'';
};
};
};
};
};
};
} //
(flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [(import heartwood.inputs.rust-overlay)];
};
inherit (pkgs) lib;
rustToolChain = pkgs.rust-bin.fromRustupToolchainFile radicle-httpd/rust-toolchain;
craneLib = (heartwood.inputs.crane.mkLib pkgs).overrideToolchain rustToolChain;
basicArgs = {
pname = "radicle-httpd";
src = ./radicle-httpd;
strictDeps = true;
};
in {
checks = {
radicle-explorer = self.packages.${system}.radicle-explorer.override { doCheck = true; };
radicle-httpd = self.packages.${system}.radicle-httpd.overrideAttrs (_: { doCheck = true; });
};
packages = {
default = self.packages.${system}.radicle-explorer;
twemoji-assets = pkgs.fetchFromGitHub {
owner = "twitter";
repo = "twemoji";
rev = "v14.0.2";
hash = "sha256-YoOnZ5uVukzi/6bLi22Y8U5TpplPzB7ji42l+/ys5xI=";
};
radicle-explorer = pkgs.callPackage ({
lib, buildNpmPackage, doCheck ? false
}: buildNpmPackage rec {
pname = "radicle-explorer";
version = (builtins.fromJSON (builtins.readFile ./package.json)).version;
src = ./.;
npmDepsHash = "sha256-RC+QQXtvXC48uM0oOAFA0ni5AU/l9m8k1LgrxykSu5M=";
postPatch = ''
patchShebangs --build ./scripts
mkdir -p "public/twemoji"
cp -t public/twemoji -r -- ${self.packages.${system}.twemoji-assets}/assets/svg/*
: >scripts/install-twemoji-assets
'';
dontConfigure = true;
inherit doCheck;
nativeCheckInputs = with pkgs; [
which
gitMinimal
];
checkPhase = ''
runHook preCheck
bins=$(scripts/install-binaries -s)
mkdir -p "$bins"
cp -t "$bins" -- ${heartwood.packages.${system}.default}/bin/* ${self.checks.${system}.radicle-httpd}/bin/*
scripts/check
{
npm run test:unit
} | tee /dev/null
runHook postCheck
'';
installPhase = ''
runHook preInstall
mkdir -p "$out"
cp -r -t "$out" build/*
runHook postInstall
'';
}) {};
radicle-httpd = craneLib.buildPackage (basicArgs // {
inherit (craneLib.crateNameFromCargoToml {cargoToml = ./radicle-httpd + "/Cargo.toml";}) pname version;
cargoArtifacts = craneLib.buildDepsOnly basicArgs;
nativeBuildInputs = with pkgs;
[
git
# Add additional build inputs here
asciidoctor installShellFiles
]
++ lib.optionals pkgs.stdenv.isDarwin (with pkgs; [
# Additional darwin specific inputs can be set here
libiconv
darwin.apple_sdk.frameworks.Security
]);
env =
{
RADICLE_VERSION = "nix-" + (self.shortRev or self.dirtyShortRev or "unknown");
}
// (
if self ? rev || self ? dirtyRev
then {
GIT_HEAD = self.rev or self.dirtyRev;
}
else {}
);
cargoExtraArgs = "-p radicle-httpd";
doCheck = false;
postInstall = ''
for page in radicle-httpd.1.adoc; do
asciidoctor -d manpage -b manpage $page
installManPage ''${page::-5}
done
'';
});
};
}));
}