-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
85 lines (78 loc) · 2.96 KB
/
flake.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
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = import nixpkgs { inherit system; };
in {
packages = rec {
uno = pkgs.stdenv.mkDerivation {
name = "uno";
src = ./.;
nativeBuildInputs = [ pkgs.makeWrapper ];
installPhase = ''
mkdir -p $out/bin
cp uno.sh $out/bin/uno
chmod +x $out/bin/uno
wrapProgram $out/bin/uno \
--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.foreman ]}
'';
};
default = uno;
};
devShell =
pkgs.mkShell { buildInputs = [ self.packages.${system}.uno ]; };
unoConfigurations.example = self.lib.configuration {
inherit system;
processes.echo = {
environment = { YOUR_NAME = "World"; };
command = "echo Hello, $YOUR_NAME && sleep 5000";
};
};
}) // {
lib = {
configuration = { system, processes }:
let pkgs = import nixpkgs { inherit system; };
in rec {
procfile = pkgs.writeText "Procfile"
(builtins.concatStringsSep "\n" (builtins.attrValues
(builtins.mapAttrs (name:
{ command, environment ? { } }:
let
exportStatements = builtins.concatStringsSep "\n"
(builtins.attrValues (builtins.mapAttrs (name: value:
''export ${name}="${builtins.toString value}"'')
environment));
script = pkgs.writers.writeBash name ''
${exportStatements}
${command}
'';
in "${name}: ${script}") processes)));
start = pkgs.writers.writeBashBin "start" ''
exec ${pkgs.foreman}/bin/foreman start --procfile=${procfile} --root=$PWD
'';
};
processes = {
postgres = { system
, package ? nixpkgs.legacyPackages.${system}.postgresql, dataDir
, host ? "localhost", port ? 5432, initialize ? true
, superuser ? "postgres" }:
let
pkgs = import nixpkgs { inherit system; };
initScript = pkgs.writers.writeBash "postgres-init" ''
if [ ! -f ${dataDir}/postgresql.conf ]; then
${package}/bin/initdb --username ${superuser} ${dataDir}
fi
'';
in {
command =
"${initScript} && ${package}/bin/postgres -D ${dataDir} -h ${host} -p ${
builtins.toString port
} -k ''";
};
};
};
};
}