diff options
Diffstat (limited to 'example')
-rw-r--r-- | example/flake.nix | 88 | ||||
-rwxr-xr-x | example/nix.sh | 8 |
2 files changed, 96 insertions, 0 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 | |||
3 | nix \ | ||
4 | "$1" \ | ||
5 | --no-update-lock-file \ | ||
6 | --no-write-lock-file \ | ||
7 | --override-input flaky-utils ../ \ | ||
8 | "${@:2}" | ||