aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpacien2022-08-22 18:31:14 +0200
committerpacien2022-08-22 18:31:14 +0200
commit96411aaa21543c81ce53fd9210e63c5e3d4ac519 (patch)
tree55d97ba83bc9ae6fad1ca4f9a8b17df7c114131f
parent24a5cf35ea3b4c46a1a9dc6d39dd6a45d7b1c70c (diff)
downloadflaky-utils-96411aaa21543c81ce53fd9210e63c5e3d4ac519.tar.gz
bootstrap lib, add mkDevShell
-rw-r--r--flake.nix9
-rw-r--r--lib/mk-dev-shell.nix30
-rw-r--r--readme.md68
3 files changed, 107 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..57a6896
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,9 @@
1{
2 description = "Additional flake utils for convenience.";
3
4 outputs = { self }: {
5 lib = {
6 mkDevShell = import ./lib/mk-dev-shell.nix;
7 };
8 };
9}
diff --git a/lib/mk-dev-shell.nix b/lib/mk-dev-shell.nix
new file mode 100644
index 0000000..e0bb441
--- /dev/null
+++ b/lib/mk-dev-shell.nix
@@ -0,0 +1,30 @@
1{ pkgs
2, tools ? []
3, envVars ? {}
4}:
5
6let
7 # TODO: escape values properly
8 exportEnvVar = k: v: ''export ${k}="${v}"; echo ${k}=\"${v}\"'';
9 exportedEnvVars = pkgs.lib.mapAttrsToList exportEnvVar envVars;
10
11in pkgs.mkShell {
12 buildInputs = tools;
13
14 # TODO: handle case with no env variable set
15 # TODO: handle case with no package in tools
16 # TODO: allow custom shell
17 shellHook = ''
18 echo -e "\nDEVSHELL ENVIRONMENT VARIABLES:"
19 ${pkgs.lib.concatStringsSep "\n" exportedEnvVars}
20
21 echo -e "\nDEVSHELL COMMANDS:"
22 ls "${pkgs.symlinkJoin { name = "env"; paths = tools; }}/bin"
23
24 # Use the default user shell instead of Bash
25 $(${pkgs.finger_bsd}/bin/finger $USER \
26 | ${pkgs.gnugrep}/bin/grep -oP 'Shell: \K.*')
27
28 exit $?
29 '';
30}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..88c4d4a
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,68 @@
1# flaky-utils
2
3Additional Nix Flake utility functions for personal convenience (mainly
4reducing boilerplate).
5
6No promise on API stability.
7
8
9## Usage
10
11Functions documentation provided as comments below.
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 {
27
28 # Convenience development shell providing some tools.
29 #
30 # The binaries made available and the environment variable set are printed
31 # when entering the shell.
32 #
33 # The user's default shell is used instead of Bash (sacrifying a bit of
34 # reproducibility for convenience).
35 #
36 devShell = flaky-utils.lib.mkDevShell {
37 inherit pkgs;
38
39 tools = with pkgs; [
40 postgresql_14
41 pgcli
42 ];
43
44 envVars = rec {
45 PGDATA = "$PWD/development_database/pgdata";
46 PGHOST = "$PWD/development_database";
47 PGPORT = "5432";
48 PGDATABASE = "app";
49 DATABASE_URL = "postgresql:///${PGDATABASE}?host=${PGHOST}";
50 };
51 };
52
53 });
54}
55```
56
57
58## Contributing
59
60Issues and patches: email the author.
61
62
63## Licence and copyright
64
65Copyright (C) 2022 Pacien TRAN-GIRARD.
66
67This project is distributed under the terms of European Union Public Licence
68version 1.2, a copy of which is provided in `./licence.txt`.