aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpacien2022-11-12 22:14:34 +0100
committerpacien2022-11-12 22:14:34 +0100
commit8e578413b4ecb7871031155b792e21adbcdce3d9 (patch)
treeb9668a45dc27e49bd88dd139de2b133794546de0
parentbfa3be010c8c90f1bd0326747b9b424535381bb2 (diff)
downloadflaky-utils-8e578413b4ecb7871031155b792e21adbcdce3d9.tar.gz
readme: extract example to own runnable file
-rw-r--r--example/flake.nix88
-rwxr-xr-xexample/nix.sh8
-rw-r--r--readme.md93
3 files changed, 97 insertions, 92 deletions
diff --git a/example/flake.nix b/example/flake.nix
new file mode 100644
index 0000000..8557265
--- /dev/null
+++ b/example/flake.nix
@@ -0,0 +1,88 @@
1{
2 description = "Example of a Flake using flaky-utils.";
3
4 inputs = {
5 nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
6 flake-utils.url = "github:numtide/flake-utils";
7 flaky-utils.url = "git+https://cgit.pacien.net/libs/flaky-utils";
8 };
9
10 outputs = { self, nixpkgs, flake-utils, flaky-utils }:
11 flake-utils.lib.eachDefaultSystem (system: let
12 pkgs = import nixpkgs { inherit system; };
13 in pkgs.lib.fold pkgs.lib.recursiveUpdate { } [
14
15 {
16 # Convenience development shell providing some tools.
17 #
18 # The binaries made available and the environment variable set are
19 # printed when entering the shell.
20 #
21 # The user's default shell is used instead of Bash (sacrifying a bit of
22 # reproducibility for convenience).
23 #
24 devShell = flaky-utils.lib.mkDevShell {
25 inherit pkgs;
26
27 tools = with pkgs; [
28 postgresql_14
29 pgcli
30 ];
31
32 envVars = rec {
33 PGDATA = "$PWD/development_database/pgdata";
34 PGHOST = "$PWD/development_database";
35 PGPORT = "5432";
36 PGDATABASE = "app";
37 DATABASE_URL = "postgresql:///${PGDATABASE}?host=${PGHOST}";
38 };
39
40 shell = null;
41 };
42 }
43
44 # Convenience isolated environment using a QEMU virtual machine.
45 #
46 # This defines a triplet of nixosConfiguration, package and app with the
47 # given name, so that the virtual machine can be launched using
48 # a command like `nix run .#sandbox`.
49 #
50 # By default, the VM is launched in the current console without a graphical
51 # interface, dropping to a shell for the default dummy user within.
52 #
53 # The current working directory from which the Flake is run is mounted and
54 # made available within the virtual machine in /mnt. The root filesystem
55 # is ephemeral (written to a temporary file in /tmp).
56 #
57 # The virtual machine's network is isolated by default: it cannot access
58 # the Internet nor the host's local network. Ports may nevertheless be
59 # forwarded explicitly from host to guest and vice-versa.
60 #
61 (flaky-utils.lib.mkSandboxSystem {
62 inherit nixpkgs system;
63
64 name = "sandbox";
65 user = "dummy";
66
67 config = {
68 virtualisation.forwardPorts = [
69 { from = "host"; host.port = 5432; guest.port = 5432; } # postgres
70 ];
71
72 services.postgresql = {
73 enable = true;
74 enableTCPIP = true;
75
76 authentication = ''
77 host all all 0.0.0.0/0 trust
78 '';
79
80 initialScript = pkgs.writeText "init.sql" ''
81 create role dummy login superuser;
82 '';
83 };
84 };
85 })
86
87 ]);
88}
diff --git a/example/nix.sh b/example/nix.sh
new file mode 100755
index 0000000..748c80c
--- /dev/null
+++ b/example/nix.sh
@@ -0,0 +1,8 @@
1#!/bin/sh
2
3nix \
4 "$1" \
5 --no-update-lock-file \
6 --no-write-lock-file \
7 --override-input flaky-utils ../ \
8 "${@:2}"
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