Skip to content

Commit b1b7382

Browse files
Implement version 2.0.0
* Convert to a proper flake following the example of ngi-nix/weblate (see https://github.com/ngi-nix/weblate) * Add an integration test * Update README * Rename 'config' option to 'settings' to better follow RFC0042 (see https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md)
1 parent 7e9ae9e commit b1b7382

File tree

6 files changed

+221
-126
lines changed

6 files changed

+221
-126
lines changed

Diff for: README.md

+22-16
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This Nix flake packages [Cryptpad](https://cryptpad.org/), a collaborative offic
44

55
# Usage
66

7-
The primary use of this flake is deploying Cryptpad on NixOS. For that you would use the NixOS module available in `.#nixosModule`.
7+
With this flake you can deploy Cryptpad on NixOS. You can use the `cryptpad` module available in `.#nixosModules`.
88

99
## Using flakes
1010
1. Add this flake as an input
@@ -18,8 +18,6 @@ The primary use of this flake is deploying Cryptpad on NixOS. For that you would
1818
url = "github:nixos/nixpkgs/nixos-23.11";
1919
};
2020
21-
# Other inputs ...
22-
2321
cryptpad = {
2422
url = "github:michaelshmitty/cryptpad-flake";
2523
inputs = {
@@ -28,42 +26,50 @@ The primary use of this flake is deploying Cryptpad on NixOS. For that you would
2826
};
2927
};
3028
31-
outputs = { self, nixpkgs, ... }@inputs: {
29+
outputs = { self, nixpkgs, cryptpad }@inputs: {
3230
nixosConfigurations.myhostname = nixpkgs.lib.nixosSystem {
3331
system = "x86_64-linux";
34-
specialArgs = { inherit inputs; };
35-
modules = [ ./configuration.nix ];
32+
modules = [
33+
({ pkgs, ... }: {
34+
nixpkgs.overlays = [ inputs.cryptpad.overlays.default ];
35+
})
36+
inputs.cryptpad.nixosModules.cryptpad
37+
./configuration.nix
38+
];
3639
};
3740
};
3841
}
3942
```
4043

41-
42-
2. Now that you have the module available as an input, configuration is straightforward. See example:
44+
2. Now that you have the module available, configuration is straightforward. See example `configuration.nix`:
4345

4446
```nix
45-
{ inputs, ... }: {
46-
47-
imports = [ inputs.cryptpad.nixosModules.cryptpad ];
47+
{ pkgs, lib, config, ... }:
4848
49+
{
4950
services.cryptpad = {
5051
enable = true;
5152
configureNginx = true;
52-
config = {
53+
settings = {
5354
httpUnsafeOrigin = "https://cryptpad.example.com";
5455
httpSafeOrigin = "https://cryptpad-ui.example.com";
5556
5657
# Add this after you've signed up in your Cryptpad instance and copy your public key:
5758
adminKeys = [ "[[email protected]/Jil1apEPZ40j5M8nsjO1-deadbeefHkt+QExscMzKhs=]" ];
5859
};
5960
};
60-
6161
}
6262
```
6363

6464
3. Deploy and check your Cryptpad setup at `https://<domain>/checkup`
6565

66-
# Putting Cryptpad into Nixpkgs
66+
# Run tests
67+
This flake contains a simple integration test that will spin up a server NixOS container that will build and
68+
run Cryptpad and Nginx. And a client NixOS container that will test connectivity to the Cryptpad instance.
69+
70+
Execute `nix flake check` in this repository to run the integration test.
71+
72+
# Adding Cryptpad to nixpkgs
6773

68-
There is [an active, open PR](https://github.com/NixOS/nixpkgs/pull/251687) to add Cryptpad back into nixpkgs. I am
69-
contributing to that PR as well, but I found it hard to test and iterate quickly using my NixOS flake configuration.
74+
There is [an active, open PR](https://github.com/NixOS/nixpkgs/pull/251687) to add Cryptpad back to nixpkgs. I am
75+
contributing my work on this flake into that PR.

Diff for: flake.lock

+39-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: flake.nix

+77-21
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,87 @@
11
{
22
description = ''
3-
CryptPad is a collaborative office suite that is end-to-end encrypted and open-source.
3+
Package and module for CryptPad, a collaborative office suite that is end-to-end encrypted and open-source.
44
'';
55

6-
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
6+
inputs = {
7+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
8+
flake-utils.url = "github:numtide/flake-utils";
9+
};
710

8-
outputs = inputs@{ self, nixpkgs, ... }:
9-
let
10-
lib = nixpkgs.lib;
11-
12-
darwin = [ "x86_64-darwin" "aarch64-darwin" ];
13-
linux = [ "x86_64-linux" "aarch64-linux" ];
14-
15-
forEachSystem = systems: f: lib.genAttrs systems (system: f system);
16-
forAllSystems = forEachSystem (darwin ++ linux);
17-
in
18-
{
19-
nixosModules.cryptpad = import ./modules/cryptpad self;
20-
packages = forAllSystems (system:
11+
outputs = { self, nixpkgs, flake-utils }:
12+
flake-utils.lib.eachDefaultSystem
13+
(system:
2114
let
22-
pkgs = import nixpkgs {
23-
inherit system;
24-
};
15+
pkgs = nixpkgs.legacyPackages.${system};
2516
in
2617
{
27-
cryptpad = pkgs.callPackage ./pkgs/cryptpad { };
28-
default = self.packages.${system}.cryptpad;
29-
});
18+
packages = {
19+
default = self.packages.${system}.cryptpad;
20+
21+
cryptpad = pkgs.buildNpmPackage rec {
22+
pname = "cryptpad";
23+
version = "5.6.0";
24+
25+
src = pkgs.fetchFromGitHub {
26+
owner = "cryptpad";
27+
repo = "cryptpad";
28+
rev = version;
29+
hash = "sha256-A3tkXt4eAeg1lobCliGd2PghpkFG5CNYWnquGESx/zo=";
30+
};
31+
32+
npmDepsHash = "sha256-tQUsI5Oz3rkAlxJ1LpolJNqZfKUGKUYSgtuCTzHRcW4=";
33+
34+
makeCacheWritable = true;
35+
36+
dontNpmInstall = true;
37+
38+
installPhase = ''
39+
out_cryptpad="$out/lib/node_modules/cryptpad"
40+
41+
mkdir -p "$out_cryptpad"
42+
cp -r . "$out_cryptpad"
43+
44+
# Cryptpad runs in its source directory. This wrappers enables keeping the Cryptpad source code
45+
# in the nix store while still having writeable paths for storing state.
46+
# The 'customize' directory maintains customizations, so don't link it if it is a directory.
47+
makeWrapper ${pkgs.nodejs}/bin/node $out/bin/cryptpad \
48+
--add-flags "$out_cryptpad/server.js" \
49+
--run "for d in customize.dist lib www; do ln -sf $out_cryptpad/\$d .; done" \
50+
--run "if ! [ -e customize ] || [ -L customize ]; then ln -sf $out_cryptpad/customize .; fi"
51+
52+
# Cryptpad also expects www/components to link to node_modules
53+
ln -s ../node_modules "$out_cryptpad/www/components"
54+
'';
55+
56+
meta = with pkgs.lib; {
57+
description = "A collaborative office suite that is end-to-end encrypted and open-source";
58+
homepage = "https://cryptpad.org/";
59+
license = licenses.agpl3Only;
60+
maintainers = with maintainers; [ michaelshmitty ];
61+
};
62+
};
63+
};
64+
65+
checks = {
66+
integrationTest =
67+
let
68+
# Evaluate nixpkgs again because pkgs doesn't contain the cryptpad package and module.
69+
pkgsCryptpad = import nixpkgs {
70+
inherit system;
71+
overlays = [ self.overlays.default ];
72+
};
73+
in
74+
pkgsCryptpad.nixosTest (import ./integration-test.nix {
75+
inherit nixpkgs;
76+
cryptpadModule = self.nixosModules.cryptpad;
77+
});
78+
package = self.packages.${system}.cryptpad;
79+
};
80+
}) // {
81+
nixosModules.cryptpad = import ./module.nix;
82+
83+
overlays.default = final: prev: {
84+
inherit (self.packages.${prev.system}) cryptpad;
85+
};
3086
};
3187
}

Diff for: integration-test.nix

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{ nixpkgs, cryptpadModule }:
2+
{ pkgs, ... }:
3+
let
4+
certs = import "${nixpkgs}/nixos/tests/common/acme/server/snakeoil-certs.nix";
5+
serverDomain = certs.domain;
6+
in
7+
{
8+
name = "cryptpad";
9+
meta.maintainers = with pkgs.lib.maintainers; [ michaelshmitty ];
10+
11+
nodes.server = { config, pkgs, lib, ... }: {
12+
virtualisation.memorySize = 4096;
13+
14+
imports = [ cryptpadModule ];
15+
16+
services.cryptpad = {
17+
enable = true;
18+
configureNginx = false;
19+
settings = {
20+
httpUnsafeOrigin = "https://${serverDomain}";
21+
httpSafeOrigin = "https://${serverDomain}";
22+
};
23+
};
24+
25+
services.nginx = {
26+
enable = true;
27+
recommendedTlsSettings = true;
28+
29+
virtualHosts."${serverDomain}" = {
30+
enableACME = false;
31+
forceSSL = true;
32+
sslCertificate = certs."${serverDomain}".cert;
33+
sslCertificateKey = certs."${serverDomain}".key;
34+
35+
locations."/" = {
36+
proxyPass = "http://localhost:3000";
37+
proxyWebsockets = true;
38+
extraConfig = ''
39+
client_max_body_size 150m;
40+
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
41+
'';
42+
};
43+
};
44+
};
45+
46+
security.pki.certificateFiles = [ certs.ca.cert ];
47+
48+
networking.hosts."::1" = [ "${serverDomain}" ];
49+
networking.firewall.allowedTCPPorts = [ 80 443 ];
50+
};
51+
52+
nodes.client = { pkgs, nodes, ... }: {
53+
networking.hosts."${nodes.server.networking.primaryIPAddress}" = [ "${serverDomain}" ];
54+
security.pki.certificateFiles = [ certs.ca.cert ];
55+
};
56+
57+
testScript = ''
58+
server.wait_for_unit("cryptpad.service")
59+
client.wait_for_unit("multi-user.target")
60+
client.wait_until_succeeds("curl --fail https://${serverDomain}/")
61+
'';
62+
}

0 commit comments

Comments
 (0)