-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpostgres_shell.nix
131 lines (115 loc) · 4.11 KB
/
postgres_shell.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# Quickstart with PostgreSQL
# ==========================
#
# createdb $(whoami) --host=$PGDATA --port=5432
# psql --host=$PGDATA --username=$(whoami) --dbname=$(whoami) --port=5432
#
# `--port` is only needed when used something other
# than the default port of 5432.
# TODOs {{-
#
# + `pga_hba.conf` in here is super-insecure;
# tighten it up (or, at least, make it
# configurable and/or add notes for best
# practices).
#
# + Make it possible to specify specific
# PostgreSQL version (currently, it
# depends on the latest version in the
# nixpkgs_commit)
# }}-
# QUESTIONs {{-
#
# + Currently, after running this Nix
# expression, the PostgreSQL superuser is
# whoever the current user is.
# +-> Is this normal?
# +-> How is it set?
# +-> Did I influence this with any of the settings
# below?
#
# }}-
# TEST ONE-LINERS {{-
# + mac
#
# * Calling from `shell.nixes` project root:
#
# nix-shell --argstr "nixpkgs_commit" "nixpkgs-22.11-darwin" --argstr "_utils_file" "file://$(realpath _utils.nix)" postgres/postgres_shell.nix --show-trace
#
# or
#
# source run.sh -g https://github.com/toraritte/shell.nixes/blob/main/postgres/postgres_shell.nix
#
# * Calling remotely (once commits are pushed, that is):
#
# source <(curl https://raw.githubusercontent.com/toraritte/shell.nixes/main/run.sh) -g https://github.com/toraritte/shell.nixes/blob/main/postgres/postgres_shell.nix
#
# + linux:
#
# same but replace "nixpkgs-22.11-darwin" with "22.11" (or other)
#
# }}-
# PERMANENT WARNING HEADER FOR ALL NIX FILES
#
# Relative paths will always be expanded
# relative to where the Nix expression is
# executed from. If a shell.nix is fetched,
# then it will be from Nix store. This
# should be super obvious, but I keep
# burning myself with not remembering this
# fact.
{ nixpkgs_commit # See head of `baseline_config.nix` if also want to pass pkg sets.
, raw_github_url_to_shell_nix_dir ? ""
# !! VVV !!
, _utils_file ? "https://github.com/toraritte/shell.nixes/raw/main/_utils.nix"
# !! ^^^ !!
}:
let
# The downloaded archive will be (temporarily?) housed in the Nix store
# e.g., "/nix/store/gk9x7syd0ic6hjrf0fs6y4bsd16zgscg-source"
# (Try any of the `fetchTarball` commands below in `nix repl`, and it
# will print out the path.)
nixpkgs_tarball =
builtins.fetchTarball
"https://github.com/nixos/nixpkgs/tarball/${nixpkgs_commit}"
;
pkgs =
(import nixpkgs_tarball)
{ config = {}; overlays = []; }
;
# short for shell.nixes_utils
sn_utils =
(import (builtins.fetchurl _utils_file)) raw_github_url_to_shell_nix_dir
;
fetchContents = sn_utils.fetchContents sn_utils.fetchLocalOrRemoteFile;
cleanUp = sn_utils.cleanUp sn_utils.fetchLocalOrRemoteFile;
in
pkgs.mkShell {
buildInputs = with pkgs; [
postgresql
];
# DECLARE ENVIRONMENT VARIABLE
# Simply leaving it here for future reference:
# this will resolve relative to the `shell.nix`
# and **not** to the store.
#
# T = builtins.toString (/. + ./_nix-shell);
shellHook =
fetchContents ./shell-hook.sh
+ cleanUp [ ./clean-up.sh ]
# + sn_utils.cleanUp [../t ./clean-up.sh ../t]
;
######################################################################
# Without this, almost everything fails with locale issues when #
# using `nix-shell --pure` (at least on NixOS). #
# See #
# + https://github.com/NixOS/nix/issues/318#issuecomment-52986702 #
# + http://lists.linuxfromscratch.org/pipermail/lfs-support/2004-June#023900.html
######################################################################
LOCALE_ARCHIVE =
if pkgs.stdenv.isLinux
then "${pkgs.glibcLocales}/lib/locale/locale-archive"
else ""
;
}
# vim: set foldmethod=marker foldmarker={{-,}}- foldlevelstart=0 tabstop=2 shiftwidth=2 expandtab: