diff options
-rw-r--r-- | readme.md | 74 |
1 files changed, 74 insertions, 0 deletions
@@ -72,6 +72,80 @@ retained. | |||
72 | * `./flake.nix`: project runtime and development environment description | 72 | * `./flake.nix`: project runtime and development environment description |
73 | 73 | ||
74 | 74 | ||
75 | ## Development environment | ||
76 | |||
77 | The development and execution environment is fully described using the [Nix] | ||
78 | language and package manager as a [Nix Flake] in `./flake.nix`. This allows | ||
79 | creating reproducible environments containing all the software dependencies of | ||
80 | the program itself, as well as optional development tools. | ||
81 | |||
82 | (_Note: this projects requires Nix version 2.4 or higher_). | ||
83 | |||
84 | [Nix]: https://nixos.org/guides/how-nix-works.html | ||
85 | [Nix Flake]: https://www.tweag.io/blog/2020-05-25-flakes/ | ||
86 | |||
87 | This environment can be used on NixOS, MacOS, or any Linux system having Nix | ||
88 | installed. In principle, Nix should also be usable on Windows through the | ||
89 | Windows Subsystem for Linux ([WSL]) compatibility layer. Full virtual machines | ||
90 | and containers can also be derived from the same description file. | ||
91 | |||
92 | [WSL]: https://docs.microsoft.com/en-us/windows/wsl/about | ||
93 | |||
94 | All the commands in this section have to be run within the provided development | ||
95 | shell, which can be entered by running the following command at the root | ||
96 | directory of the project: | ||
97 | |||
98 | ```sh | ||
99 | nix develop | ||
100 | ``` | ||
101 | |||
102 | ### Local database | ||
103 | |||
104 | The Nix Flake development shell provides its own self-contained PostgreSQL | ||
105 | server, configured to operate independently of any other instances running on | ||
106 | the same system. | ||
107 | |||
108 | All data are written to the `./development_database/pgadata` directory. The | ||
109 | database server can be initialised by running the following command: | ||
110 | |||
111 | ```sh | ||
112 | initdb --no-locale --encoding UTF8 --auth-host reject --auth-local peer | ||
113 | ``` | ||
114 | |||
115 | The local development PostgreSQL server can then be started by running the | ||
116 | following command, with the `$PGHOST` environment variable automatically set | ||
117 | by the development shell: | ||
118 | |||
119 | ```sh | ||
120 | postgres -h "" -k "$PGHOST" -d 2 | ||
121 | ``` | ||
122 | |||
123 | This server listens to local requests through a UNIX domain socket located at | ||
124 | `./development_database/.s.PGSQL.5432`, to which programs run in the | ||
125 | development shell will implicitly automatically connect to. | ||
126 | |||
127 | The development shell ships with both the `psql` and [`pgcli`][pgcli] tools to | ||
128 | interact directly with the database. The latter provides additional features | ||
129 | such as syntax highlighting and better auto-completion. | ||
130 | |||
131 | [pgcli]: https://www.pgcli.com/ | ||
132 | |||
133 | A new local database for the application can be created and its table can be | ||
134 | initialised with: | ||
135 | |||
136 | ```sh | ||
137 | createdb app | ||
138 | psql app < ./sql/tables.sql | ||
139 | ``` | ||
140 | |||
141 | Should the need arise, this database can be deleted with the following command | ||
142 | before being created and initialised again: | ||
143 | |||
144 | ```sh | ||
145 | dropdb app | ||
146 | ``` | ||
147 | |||
148 | |||
75 | ## Copyright and licensing | 149 | ## Copyright and licensing |
76 | 150 | ||
77 | Copyright (C) 2021 Pacien TRAN-GIRARD. | 151 | Copyright (C) 2021 Pacien TRAN-GIRARD. |