-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
135 lines (117 loc) · 4.16 KB
/
Copy pathflake.nix
File metadata and controls
135 lines (117 loc) · 4.16 KB
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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
# Add the backend flake as an input
backend = {
url = "./backend"; # Points to the flake in the backend directory
inputs.nixpkgs.follows = "nixpkgs";
};
static = {
url = "./blog-static";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { nixpkgs, disko, sops-nix, backend, static, ... }@attrs:
let
# The system we are building for. It will not work on other systems.
# One might use flake-utils to make it work on other systems.
system = "x86_64-linux";
# Import the Nix packages from nixpkgs
pkgs = import nixpkgs { inherit system; };
# Integration that are run using kvm virtual machines
integration = pkgs.testers.nixosTest (import ./integration.nix {
inherit pkgs system backend static;
});
# Browser E2E tests using nixosTest framework
browser-e2e-test = import ./browser-e2e.nix { inherit pkgs backend static; };
# Python with properly compiled packages
pythonEnv = pkgs.python3.withPackages (ps: with ps; [
playwright
termcolor
setuptools
greenlet
]);
# Browser E2E test script
browser-e2e-script = pkgs.writeShellScriptBin "browser-e2e-test" ''
set -e
echo "Running browser E2E tests..."
# Set up environment for Playwright
export PLAYWRIGHT_BROWSERS_PATH="${pkgs.playwright-driver.browsers}"
export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true
# Check if we have a display or need xvfb-run
if [[ -z "$DISPLAY" ]]; then
echo "No display found, using xvfb-run..."
exec ${pkgs.xvfb-run}/bin/xvfb-run -a -s '-screen 0 1280x720x24' \
${pythonEnv}/bin/python3 ${./browser_e2e_tests.py}
else
echo "Display found, running directly..."
exec ${pythonEnv}/bin/python3 ${./browser_e2e_tests.py}
fi
'';
in
{
# Define a formatter package for the system to enable `nix fmt`
formatter.${system} = pkgs.nixpkgs-fmt;
# NixOS configuration for the 'blog' system
nixosConfigurations.blog = nixpkgs.lib.nixosSystem {
inherit system;
specialArgs = attrs;
modules = [
disko.nixosModules.disko # Include disko module
sops-nix.nixosModules.sops # Include sops module
./configuration.nix # Include custom configuration
./plausible.nix
];
};
# Merge the checks from the backend flake into the root flake's checks
checks.${system} = nixpkgs.lib.recursiveUpdate
(backend.checks.${system} or { })
{
itg = integration;
browser-e2e = browser-e2e-test;
};
# Development shell environment
# It will include the packages specified in the buildInputs attribute
# once the shell is entered using `nix develop` or direnv integration.
devShells.${system}.default = pkgs.mkShell {
DATABASE_URL = "postgresql://blog:blog@localhost:5432/blog";
PLAYWRIGHT_BROWSERS_PATH = "${pkgs.playwright-driver.browsers}";
PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = "true";
SQLX_OFFLINE = "true";
buildInputs = with pkgs; [
# Rust toolchain from backend
rustc
cargo
rustfmt
clippy
rust-analyzer
pkg-config
openssl
# Root project tools
opentofu # provisioning tool for the OpenTofu project
ponysay # just for fun run `ponysay hello`
hugo
tailwindcss_4
sqlx-cli
python3
python3Packages.cairosvg
python3Packages.pillow
python3Packages.svgwrite
# Browser E2E testing tools
browser-e2e-script
xvfb-run
python3Packages.playwright
python3Packages.greenlet
python3Packages.termcolor
];
};
};
}