This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
123 lines (111 loc) · 4 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, gitignore, rust-overlay }:
let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
overlays = [ rust-overlay.overlays.default ];
};
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
rustPlatform = pkgs.makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};
buildInputs = with pkgs; [
openssl.dev
];
nativeBuildInputs = with pkgs; [
clang
coreutils
pkg-config
protobuf
rustToolchain
];
vm-base = import ./integration-tests/vm.nix self.packages.${system}.default;
in
{
apps.${system} =
let
mkApp = script: extraDeps: {
type = "app";
program = toString (pkgs.writeShellScript "script.sh" ''
export PKG_CONFIG_PATH=${pkgs.openssl.dev}/lib/pkgconfig
PATH=${pkgs.lib.makeBinPath (buildInputs ++ nativeBuildInputs ++ extraDeps)}
${pkgs.lib.fileContents script}
'');
};
in
{
lint = mkApp ./scripts/lint.sh (with pkgs; [ findutils shellcheck ]);
documentation = mkApp ./scripts/documentation.sh (with pkgs; [ gnused mdbook mdbook-admonish ]);
fmt = mkApp ./scripts/fmt.sh (with pkgs; [ git nix ]);
test = mkApp ./scripts/test.sh [ ];
};
checks.${system} =
let runTest = f: (pkgs.testers.runNixOSTest (import f { inherit pkgs; defaults = vm-base; })).config.result; in
{
container-networking = runTest ./integration-tests/test-container-networking.nix;
vm-works = runTest ./integration-tests/test-vm-works.nix;
};
devShells.${system}.default = pkgs.mkShell {
packages = buildInputs ++ nativeBuildInputs;
};
formatter.${system} = pkgs.nixpkgs-fmt;
packages.${system} = {
default = rustPlatform.buildRustPackage rec {
inherit buildInputs nativeBuildInputs;
pname = "thing-doer";
version = "0.0.0";
src = gitignore.lib.gitignoreSource ./.;
cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = {
"dns-resolver-0.1.0" = "sha256-gr8MiHzCS+VPq09VlpPpeZlSW63KJ5u/CB/OEhITnBY=";
};
};
doCheck = false;
meta = {
description = "A simple container orchestrator.";
homepage = "https://github.com/barrucadu/thing-doer";
};
};
vm =
let
vm-config = { config, lib, pkgs, ... }: {
networking.hostName = "thing-doer";
services.openssh.enable = true;
services.openssh.settings.PermitRootLogin = "yes";
users.users.root.password = "root";
thingDoer.nodeName = null; # force randomly-generated names
# qemu options
virtualisation.diskImage = null;
virtualisation.graphics = false;
virtualisation.sharedDirectories.host = { source = "$VM_SHARED_DIR"; target = "/mnt/host"; };
virtualisation.qemu.networkingOptions = [
"-net nic,macaddr=52:54:00:$(head -c 1 /dev/urandom | xxd -p):$(head -c 1 /dev/urandom | xxd -p):$(head -c 1 /dev/urandom | xxd -p),model=virtio -net bridge,br=br0"
];
};
vm-system = nixpkgs.lib.nixosSystem {
inherit system;
modules = [
vm-config
vm-base
"${nixpkgs}/nixos/modules/virtualisation/qemu-vm.nix"
];
};
in
vm-system.config.system.build.vm;
};
};
}