-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.nix
134 lines (134 loc) · 3.74 KB
/
default.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
{ inputs, moduleWithSystem, ... }:
{
systems = [ "x86_64-linux" ];
perSystem =
{ system, pkgs, ... }:
{
config = {
_module.args = {
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
inputs.configuration.overlays.default
];
};
};
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
coreutils-full
nodejs
nodePackages_latest.prettier
rustc
rust-analyzer
rustfmt
cargo
pkg-config
openssl
hurl
(nvim.extend {
plugins = {
lsp.servers = {
svelte.enable = true;
html.enable = true;
ts_ls.enable = true;
jsonls.enable = true;
tailwindcss.enable = true;
cssls.enable = true;
rust_analyzer = {
installCargo = false;
installRustc = false;
};
};
rustaceanvim = {
enable = true;
};
};
})
];
};
packages = {
default = pkgs.buildNpmPackage {
pname = "idimitrov.dev";
version = "0.1.1";
nodejs = pkgs.nodejs_22;
src = ./.;
npmDepsHash = "sha256-FuJoTmqwolzWuUK5lrh8Z1LYfU/RxKk+hlHGCGgbPbE=";
npmFlags = [ "--legacy-peer-deps" ];
postInstall = ''
rm -rf $out/*
rm -rf $out/.*
cp -r ./build/* $out/
'';
};
api = pkgs.rustPlatform.buildRustPackage {
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ pkgs.openssl ];
pname = "api";
version = "0.0.1";
src = ./api;
cargoLock = {
lockFile = ./api/Cargo.lock;
};
};
};
};
};
flake.nixosModules.default = moduleWithSystem (
{ config, ... }:
perSystem@{ lib, ... }:
let
inherit (lib) mkIf mkMerge mkEnableOption;
cfg = perSystem.config.webshite;
packages = config.packages;
in
{
options.webshite = {
enable = mkEnableOption "enable webshite config";
};
config = mkIf cfg.enable {
services.nginx.virtualHosts =
let
extensions = [
"html"
"txt"
"png"
"jpg"
"jpeg"
];
serveStatic = exts: ''
try_files ${lib.strings.concatStringsSep " " (builtins.map (x: "$uri.${x}") exts)} $uri $uri/ =404;
'';
webshiteConfig = {
enableACME = true;
forceSSL = true;
locations = {
"/" = {
root = "${packages.default}";
extraConfig = serveStatic extensions;
};
"/api" = {
proxyPass = "http://127.0.0.1:8000";
};
};
extraConfig = ''
add_header 'Referrer-Policy' 'origin-when-cross-origin';
add_header X-Content-Type-Options nosniff;
'';
};
in
{
"idimitrov.dev" = webshiteConfig;
"www.idimitrov.dev" = webshiteConfig;
};
systemd.services.webshiteApi = {
enable = true;
serviceConfig = {
ExecStart = "${packages.api}/bin/api";
Restart = "always";
};
wantedBy = [ "multi-user.target" ];
};
};
}
);
}