diff options
Diffstat (limited to 'readme.md')
-rw-r--r-- | readme.md | 93 |
1 files changed, 69 insertions, 24 deletions
@@ -23,36 +23,81 @@ Functions documentation provided as comments below. | |||
23 | outputs = { self, nixpkgs, flake-utils, flaky-utils }: | 23 | outputs = { self, nixpkgs, flake-utils, flaky-utils }: |
24 | flake-utils.lib.eachDefaultSystem (system: let | 24 | flake-utils.lib.eachDefaultSystem (system: let |
25 | pkgs = import nixpkgs { inherit system; }; | 25 | pkgs = import nixpkgs { inherit system; }; |
26 | in { | 26 | in pkgs.lib.fold pkgs.lib.recursiveUpdate { } [ |
27 | |||
28 | { | ||
29 | # Convenience development shell providing some tools. | ||
30 | # | ||
31 | # The binaries made available and the environment variable set are | ||
32 | # printed when entering the shell. | ||
33 | # | ||
34 | # The user's default shell is used instead of Bash (sacrifying a bit of | ||
35 | # reproducibility for convenience). | ||
36 | # | ||
37 | devShell = flaky-utils.lib.mkDevShell { | ||
38 | inherit pkgs; | ||
39 | |||
40 | tools = with pkgs; [ | ||
41 | postgresql_14 | ||
42 | pgcli | ||
43 | ]; | ||
44 | |||
45 | envVars = rec { | ||
46 | PGDATA = "$PWD/development_database/pgdata"; | ||
47 | PGHOST = "$PWD/development_database"; | ||
48 | PGPORT = "5432"; | ||
49 | PGDATABASE = "app"; | ||
50 | DATABASE_URL = "postgresql:///${PGDATABASE}?host=${PGHOST}"; | ||
51 | }; | ||
52 | |||
53 | shell = null; | ||
54 | }; | ||
55 | } | ||
27 | 56 | ||
28 | # Convenience development shell providing some tools. | 57 | # Convenience isolated environment using a QEMU virtual machine. |
29 | # | 58 | # |
30 | # The binaries made available and the environment variable set are printed | 59 | # This defines a triplet of nixosConfiguration, package and app with the |
31 | # when entering the shell. | 60 | # given name, so that the virtual machine can be launched using |
61 | # a command like `nix run .#sandbox`. | ||
32 | # | 62 | # |
33 | # The user's default shell is used instead of Bash (sacrifying a bit of | 63 | # By default, the VM is launched in the current console without a graphical |
34 | # reproducibility for convenience). | 64 | # interface, dropping to a shell for the default dummy user within. |
35 | # | 65 | # |
36 | devShell = flaky-utils.lib.mkDevShell { | 66 | # The current working directory from which the Flake is run is mounted and |
37 | inherit pkgs; | 67 | # made available within the virtual machine in /mnt. The root filesystem |
38 | 68 | # is ephemeral (written to a temporary file in /tmp). | |
39 | tools = with pkgs; [ | 69 | # |
40 | postgresql_14 | 70 | # The virtual machine's network is isolated by default: it cannot access |
41 | pgcli | 71 | # the Internet nor the host's local network. Ports may nevertheless be |
42 | ]; | 72 | # forwarded explicitly from host to guest and vice-versa. |
43 | 73 | # | |
44 | envVars = rec { | 74 | (flaky-utils.lib.mkSandboxSystem { |
45 | PGDATA = "$PWD/development_database/pgdata"; | 75 | inherit nixpkgs system; |
46 | PGHOST = "$PWD/development_database"; | 76 | |
47 | PGPORT = "5432"; | 77 | name = "sandbox"; |
48 | PGDATABASE = "app"; | 78 | user = "dummy"; |
49 | DATABASE_URL = "postgresql:///${PGDATABASE}?host=${PGHOST}"; | ||
50 | }; | ||
51 | 79 | ||
52 | shell = null; | 80 | config = { |
53 | }; | 81 | virtualisation.forwardPorts = [ |
82 | { from = "host"; host.port = 5432; guest.port = 5432; } # postgres | ||
83 | ]; | ||
84 | |||
85 | services.postgresql = { | ||
86 | enable = true; | ||
87 | enableTCPIP = true; | ||
88 | |||
89 | authentication = '' | ||
90 | host all all 0.0.0.0/0 trust | ||
91 | ''; | ||
92 | |||
93 | initialScript = pkgs.writeText "init.sql" '' | ||
94 | create role dummy login superuser; | ||
95 | ''; | ||
96 | }; | ||
97 | }; | ||
98 | }) | ||
54 | 99 | ||
55 | }); | 100 | ]); |
56 | } | 101 | } |
57 | ``` | 102 | ``` |
58 | 103 | ||