1import ./make-test-python.nix ({ pkgs, ... }:
2 let
3 accessKey = "BKIKJAA5BMMU2RHO6IBB";
4 secretKey = "V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12";
5 minioPythonScript = pkgs.writeScript "minio-test.py" ''
6 #! ${pkgs.python3.withPackages(ps: [ ps.minio ])}/bin/python
7 import io
8 import os
9 from minio import Minio
10 minioClient = Minio('localhost:9000',
11 access_key='${accessKey}',
12 secret_key='${secretKey}',
13 secure=False)
14 sio = io.BytesIO()
15 sio.write(b'Test from Python')
16 sio.seek(0, os.SEEK_END)
17 sio_len = sio.tell()
18 sio.seek(0)
19 minioClient.put_object('test-bucket', 'test.txt', sio, sio_len, content_type='text/plain')
20 '';
21 rootCredentialsFile = "/etc/nixos/minio-root-credentials";
22 credsPartial = pkgs.writeText "minio-credentials-partial" ''
23 MINIO_ROOT_USER=${accessKey}
24 '';
25 credsFull = pkgs.writeText "minio-credentials-full" ''
26 MINIO_ROOT_USER=${accessKey}
27 MINIO_ROOT_PASSWORD=${secretKey}
28 '';
29 in
30 {
31 name = "minio";
32 meta = with pkgs.lib.maintainers; {
33 maintainers = [ bachp ];
34 };
35
36 nodes = {
37 machine = { pkgs, ... }: {
38 services.minio = {
39 enable = true;
40 inherit rootCredentialsFile;
41 };
42 environment.systemPackages = [ pkgs.minio-client ];
43
44 # Minio requires at least 1GiB of free disk space to run.
45 virtualisation.diskSize = 4 * 1024;
46 };
47 };
48
49 testScript = ''
50 import time
51
52 start_all()
53 # simulate manually editing root credentials file
54 machine.wait_for_unit("multi-user.target")
55 machine.copy_from_host("${credsPartial}", "${rootCredentialsFile}")
56 time.sleep(3)
57 machine.copy_from_host("${credsFull}", "${rootCredentialsFile}")
58
59 machine.wait_for_unit("minio.service")
60 machine.wait_for_open_port(9000)
61
62 # Create a test bucket on the server
63 machine.succeed(
64 "mc config host add minio http://localhost:9000 ${accessKey} ${secretKey} --api s3v4"
65 )
66 machine.succeed("mc mb minio/test-bucket")
67 machine.succeed("${minioPythonScript}")
68 assert "test-bucket" in machine.succeed("mc ls minio")
69 assert "Test from Python" in machine.succeed("mc cat minio/test-bucket/test.txt")
70 machine.shutdown()
71 '';
72 })