-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
166 lines (147 loc) · 4.83 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
{
description = "Receptdatabasen";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.nixpkgs_24_05.url = "github:NixOS/nixpkgs/nixpkgs-24.05-darwin";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs =
{
self,
nixpkgs,
nixpkgs_24_05,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
pkgs_24_05 = nixpkgs_24_05.legacyPackages.${system};
pyPkgs = pkgs.python311Packages;
soft-webauthn = (
pyPkgs.buildPythonPackage rec {
pname = "soft-webauthn";
version = "0.1.4";
src = pkgs.fetchPypi {
inherit pname version;
sha256 = "sha256-6WUTNC5pu/3lpgrcsDqw1WLXDV0uIO5yA/z7308bBtA=";
};
doCheck = false;
# format = "pyproject";
propagatedBuildInputs = with pyPkgs; [
cryptography
fido2
];
pythonImportsCheck = [ "soft_webauthn" ];
}
);
# );
pythonEnv = pkgs.python311.withPackages (ps: [
ps.requests
ps.pytest
ps.webauthn
soft-webauthn
]);
pg = pkgs_24_05.postgresql_12;
import_prod = pkgs.writeShellApplication {
name = "import-prod";
runtimeInputs = [
pkgs.docker
pkgs.docker-compose
];
text = pkgs.lib.strings.fileContents ./scripts/import_prod_db.sh;
};
db = pkgs.writeShellApplication {
name = "db";
# TODO: isolate pgcli config file? e.g. pspg dep...
runtimeInputs = [
pkgs.pgcli
pkgs.pspg
];
text = ''
pgcli "postgresql://$SUPER_USER:$SUPER_USER_PASSWORD@localhost:$DB_PORT/$DB_NAME"
'';
};
hot-reload = pkgs.writeShellApplication {
name = "hot-reload";
runtimeInputs = [ pkgs.fswatch ];
text = pkgs.lib.strings.fileContents ./scripts/hot-reload.sh;
};
vm-config = import ./nix/vm-configuration.nix {
inherit system nixpkgs;
module = self.nixosModules.default;
};
in {
devShells.default = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = [
import_prod
db
hot-reload
pkgs.shellcheck
pkgs.sqitchPg
pg
pythonEnv
pkgs.ruff
pkgs.pyright
pkgs.lua-language-server
# for local dev shell only - to give hint for lua lsp
(pkgs.luajit.withPackages (
ps: with ps; [
lua-resty-core
cjson
]
))
];
# source the .env file
shellHook = ''
set -a
source .env
set +a
'';
};
apps.nixos-vm = {
type = "app";
program = "${vm-config.run-vm}";
};
packages = {
docker-compose-file = pkgs.writeTextFile {
name = "docker-compose.yml";
text = pkgs.lib.readFile ./nix/docker-compose.nixos.yml;
};
inherit (self.checks.${system}.default) driverInteractive;
};
checks.default = nixpkgs.legacyPackages."${system}".nixosTest {
name = "Integration test of the NixOS module";
nodes = {
server = { modulesPath, ... }: {
imports = [ self.nixosModules.default ];
config = {
virtualisation = {
# 2 GiB - the project needs a little bit more space
diskSize = 3 * 1024;
};
services.receptdatabasen.enable = true;
services.receptdatabasen.jwtSecret =
"3ARDEfnJWEXlnJE0GRp5NRFUiLbuNZlF";
services.receptdatabasen.cookieSessionSecret =
"SkNUZkQNePjYlOfBbLM641wqzFhi0I7u";
};
};
client = { pkgs, ... }: {
config = { environment.defaultPackages = [ pkgs.curl ]; };
};
};
testScript = { nodes }: pkgs.lib.readFile ./nix/integration_test.py;
};
}) // {
nixosModules.default = { pkgs, ... }:
let
# we wrap the actual module in a new module to be able to make it platform-agnostic
# and can access pkgs.system when referring to the self.packages
docker-compose-file =
self.packages.${pkgs.system}.docker-compose-file;
in {
# to get the actual module, we must first apply the docker-compose-file arg
imports = [ ((import ./nix/module.nix) docker-compose-file) ];
};
};
}