aboutsummaryrefslogtreecommitdiff
path: root/readme.md
diff options
context:
space:
mode:
Diffstat (limited to 'readme.md')
-rw-r--r--readme.md93
1 files changed, 1 insertions, 92 deletions
diff --git a/readme.md b/readme.md
index 853c3cc..649d53c 100644
--- a/readme.md
+++ b/readme.md
@@ -8,98 +8,7 @@ No promise on API stability.
8 8
9## Usage 9## Usage
10 10
11Functions documentation provided as comments below. 11See "./example/flake.nix" for a documented example.
12
13```nix
14{
15 description = "Example of a Flake using flaky-utils.";
16
17 inputs = {
18 nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
19 flake-utils.url = "github:numtide/flake-utils";
20 flaky-utils.url = "git+https://cgit.pacien.net/libs/flaky-utils";
21 };
22
23 outputs = { self, nixpkgs, flake-utils, flaky-utils }:
24 flake-utils.lib.eachDefaultSystem (system: let
25 pkgs = import nixpkgs { inherit system; };
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 }
56
57 # Convenience isolated environment using a QEMU virtual machine.
58 #
59 # This defines a triplet of nixosConfiguration, package and app with the
60 # given name, so that the virtual machine can be launched using
61 # a command like `nix run .#sandbox`.
62 #
63 # By default, the VM is launched in the current console without a graphical
64 # interface, dropping to a shell for the default dummy user within.
65 #
66 # The current working directory from which the Flake is run is mounted and
67 # made available within the virtual machine in /mnt. The root filesystem
68 # is ephemeral (written to a temporary file in /tmp).
69 #
70 # The virtual machine's network is isolated by default: it cannot access
71 # the Internet nor the host's local network. Ports may nevertheless be
72 # forwarded explicitly from host to guest and vice-versa.
73 #
74 (flaky-utils.lib.mkSandboxSystem {
75 inherit nixpkgs system;
76
77 name = "sandbox";
78 user = "dummy";
79
80 config = {
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 })
99
100 ]);
101}
102```
103 12
104 13
105## Contributing 14## Contributing