-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
144 lines (128 loc) · 3.99 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
# needed to set up the schema in test vm database
tlms-rs = {
url = "github:tlm-solutions/tlms.rs";
inputs.nixpkgs.follows = "nixpkgs";
};
utils = {
url = "github:numtide/flake-utils";
};
fenix = {
url = "github:nix-community/fenix";
};
};
outputs = inputs@{ self, nixpkgs, naersk, tlms-rs, utils, fenix, ... }:
utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
toolchain = with fenix.packages.${system}; combine [
latest.cargo
latest.rustc
];
package = pkgs.callPackage ./derivation.nix {
buildPackage = (naersk.lib.${system}.override {
cargo = toolchain;
rustc = toolchain;
}).buildPackage;
};
test-vm-pkg = self.nixosConfigurations.trekkie-mctest.config.system.build.vm;
in
rec {
checks = packages;
packages = {
trekkie = package;
test-vm = test-vm-pkg;
test-vm-wrapper = pkgs.writeScript "trekkie-test-vm-wrapper"
''
set -e
echo Trekkie-McTest: enterprise-grade, free-range, grass fed testing vm
echo
echo "ALL RELEVANT SERVICES WILL BE EXPOSED TO THE HOST:"
echo -e "Service\t\tPort"
echo -e "SSH:\t\t2222\troot:lol"
echo -e "postgres:\t8888"
echo -e "trekkie:\t8060"
echo -e "redis:\t\t8061"
echo
set -x
export QEMU_NET_OPTS="hostfwd=tcp::2222-:22,hostfwd=tcp::8888-:5432,hostfwd=tcp::8060-:8060,hostfwd=tcp::8061-:6379"
echo "running the vm now..."
${self.packages.${system}.test-vm}/bin/run-nixos-vm
'';
default = package;
docs = (pkgs.nixosOptionsDoc {
options = (nixpkgs.lib.nixosSystem {
inherit system;
modules = [ self.nixosModules.default ];
}).options.TLMS;
}).optionsCommonMark;
};
# to get yourself a virtualized testing playground:
# nix run .\#mctest
apps = {
mctest = {
type = "app";
program = "${self.packages.${system}.test-vm-wrapper}";
};
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = (with packages.default; nativeBuildInputs ++ buildInputs) ++ [
# python for running test scripts
(pkgs.python3.withPackages (p: with p; [
requests
]))
];
};
}
) // {
overlays.default = final: prev: {
inherit (self.packages.${prev.system})
trekkie;
};
nixosModules = rec {
default = trekkie;
trekkie = import ./nixos-module;
};
# qemu vm for testing
nixosConfigurations.trekkie-mctest = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs; };
modules = [
self.nixosModules.default
./tests/vm
{
nixpkgs.overlays = [
self.overlays.default
];
}
];
};
hydraJobs =
let
hydraSystems = [
"x86_64-linux"
"aarch64-linux"
];
in
builtins.foldl'
(hydraJobs: system:
builtins.foldl'
(hydraJobs: pkgName:
nixpkgs.lib.recursiveUpdate hydraJobs {
${pkgName}.${system} = self.packages.${system}.${pkgName};
}
)
hydraJobs
(builtins.attrNames self.packages.${system})
)
{ }
hydraSystems;
};
}