1 import ./make-test-python.nix ({ pkgs, ... }:
3 accessKey = "BKIKJAA5BMMU2RHO6IBB";
4 secretKey = "V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12";
5 minioPythonScript = pkgs.writeScript "minio-test.py" ''
6 #! ${pkgs.python3.withPackages(ps: [ ps.minio ])}/bin/python
9 from minio import Minio
10 minioClient = Minio('localhost:9000',
11 access_key='${accessKey}',
12 secret_key='${secretKey}',
15 sio.write(b'Test from Python')
16 sio.seek(0, os.SEEK_END)
19 minioClient.put_object('test-bucket', 'test.txt', sio, sio_len, content_type='text/plain')
21 rootCredentialsFile = "/etc/nixos/minio-root-credentials";
22 credsPartial = pkgs.writeText "minio-credentials-partial" ''
23 MINIO_ROOT_USER=${accessKey}
25 credsFull = pkgs.writeText "minio-credentials-full" ''
26 MINIO_ROOT_USER=${accessKey}
27 MINIO_ROOT_PASSWORD=${secretKey}
32 meta = with pkgs.lib.maintainers; {
33 maintainers = [ bachp ];
37 machine = { pkgs, ... }: {
40 inherit rootCredentialsFile;
42 environment.systemPackages = [ pkgs.minio-client ];
44 # Minio requires at least 1GiB of free disk space to run.
45 virtualisation.diskSize = 4 * 1024;
47 # Minio pre allocates 2GiB or memory, reserve some more
48 virtualisation.memorySize = 4096;
55 # simulate manually editing root credentials file
56 machine.wait_for_unit("multi-user.target")
57 machine.copy_from_host("${credsFull}", "${rootCredentialsFile}")
59 machine.wait_for_unit("minio.service")
60 machine.wait_for_open_port(9000)
62 # Create a test bucket on the server
64 "mc config host add minio http://localhost:9000 ${accessKey} ${secretKey} --api s3v4"
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")