-
-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathflake.nix
More file actions
219 lines (208 loc) · 7.24 KB
/
flake.nix
File metadata and controls
219 lines (208 loc) · 7.24 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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
{
description = "Code behind search.nixos.org";
nixConfig = {
extra-substituters = [ "https://nixos-search.cachix.org" ];
extra-trusted-public-keys = [
"nixos-search.cachix.org-1:1HV3YF8az4fywnH+pAd+CXFEdpTXtv9WpoivPi+H70o="
];
};
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
# https://github.com/nix-community/npmlock2nix/blob/master/nix/sources.json
nixpkgs-npmlock2nix.url = "nixpkgs/c5ed8beb478a8ca035f033f659b60c89500a3034";
npmlock2nix.url = "github:nix-community/npmlock2nix";
npmlock2nix.flake = false;
nixos-infra.url = "github:NixOS/infra";
nixos-infra.flake = false;
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
nixpkgs-npmlock2nix,
flake-utils,
npmlock2nix,
nixos-infra,
treefmt-nix,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
pkgsNpmlock2nix = import nixpkgs-npmlock2nix {
inherit system;
overlays = [
(self: super: {
npmlock2nix = super.callPackage npmlock2nix { };
})
];
};
lib = nixpkgs.lib;
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
warnToUpgradeNix = lib.warn "Please upgrade Nix to 2.7 or later.";
version = (import ./version.nix).frontend;
nixosChannels =
let
allChannels = (import "${nixos-infra}/channels.nix").channels;
filteredChannels = lib.filterAttrs (
n: v:
builtins.elem v.status [
"rolling"
"beta"
"stable"
"deprecated"
]
&& lib.hasPrefix "nixos-" n
&& v ? variant
&& v.variant == "primary"
) allChannels;
in
{
channels = lib.mapAttrsToList (n: v: {
id = lib.removePrefix "nixos-" n;
status = v.status;
jobset = builtins.concatStringsSep "/" (lib.init (lib.splitString "/" v.job));
branch = n;
}) filteredChannels;
default = builtins.head (
builtins.sort (e1: e2: !(builtins.lessThan e1 e2)) (
builtins.map (lib.removePrefix "nixos-") (
builtins.attrNames (lib.filterAttrs (_: v: v.status == "stable") filteredChannels)
)
)
);
};
nixosChannelsFile = pkgs.runCommand "nixosChannels.json" { } ''
echo '${builtins.toJSON (builtins.map (c: c.id) nixosChannels.channels)}' > $out
'';
treefmt = treefmtEval.config.build.wrapper;
mkDevShell =
{
inputsFrom ? [ ],
extraPackages ? [ ],
extraShellHook ? "",
}:
pkgs.mkShell {
inherit inputsFrom;
packages = [ treefmt ] ++ extraPackages;
shellHook = ''
export NIXOS_CHANNELS='${builtins.toJSON nixosChannels}';
export ELASTICSEARCH_MAPPING_SCHEMA_VERSION="${version}";
''
+ extraShellHook;
};
in
rec {
packages = {
default = packages.flake-info;
flake-info = import ./flake-info { inherit pkgs; };
frontend = import ./frontend {
pkgs = pkgs // {
inherit (pkgsNpmlock2nix) npmlock2nix;
};
inherit nixosChannels version;
};
nixosChannels = nixosChannelsFile;
};
formatter = treefmt;
devShells = {
default = mkDevShell {
inputsFrom = [
packages.flake-info
packages.frontend
];
extraPackages = with pkgs; [
opensearch-cli
rustfmt
rust-analyzer
yarn
];
extraShellHook = ''
export RUST_SRC_PATH="${pkgs.rustPlatform.rustLibSrc}";
export LINK_MANPAGES_PANDOC_FILTER="${packages.flake-info.LINK_MANPAGES_PANDOC_FILTER}";
export PATH=$PWD/frontend/node_modules/.bin:$PATH
'';
};
flake-info = mkDevShell {
inputsFrom = [ packages.flake-info ];
extraPackages = with pkgs; [
rustfmt
rust-analyzer
];
extraShellHook = ''
export RUST_SRC_PATH="${pkgs.rustPlatform.rustLibSrc}";
export LINK_MANPAGES_PANDOC_FILTER="${packages.flake-info.LINK_MANPAGES_PANDOC_FILTER}";
'';
};
frontend = mkDevShell {
inputsFrom = [ packages.frontend ];
extraPackages = with pkgs; [
rustfmt
yarn
];
extraShellHook = ''
export PATH=$PWD/frontend/node_modules/.bin:$PATH
rm -rf frontend/node_modules
ln -sf ${packages.frontend.node_modules}/node_modules frontend/
echo "========================================================"
echo "= To develop the frontend run: cd frontend && yarn dev ="
echo "========================================================"
'';
};
};
# XXX: for backwards compatibility
devShell = warnToUpgradeNix devShells.default;
defaultPackage = warnToUpgradeNix packages.default;
apps.opensearch-vm = {
type = "app";
program = "${self.nixosConfigurations.opensearch-vm.config.system.build.vm}/bin/run-nixos-vm";
meta.description = "Run OpenSearch on port 9200 in an ephemeral VM for local testing";
};
}
)
// {
# Local testing VM configuration
nixosConfigurations.opensearch-vm = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
(import "${nixpkgs}/nixos/modules/virtualisation/qemu-vm.nix")
(
{ lib, pkgs, ... }:
{
system.stateVersion = "25.05";
services.getty.autologinUser = "root";
virtualisation = {
diskImage = null; # makes VM ephemeral
graphics = false;
forwardPorts = [
{
guest.port = 9200;
host.port = 9200;
}
]; # expose :9200 from guest to host
memorySize = 1024 * 8; # 8 GB
};
environment.systemPackages = with pkgs; [ opensearch-cli ];
networking.firewall.allowedTCPPorts = [ 9200 ];
services.opensearch = {
enable = true;
settings = {
"network.host" = "0.0.0.0";
"http.cors.enabled" = "true";
"http.cors.allow-origin" = "http://localhost:3000";
"http.cors.allow-credentials" = "true";
"http.cors.allow-headers" =
"X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization";
};
};
}
)
];
};
};
}