-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
140 lines (123 loc) · 4.33 KB
/
flake.nix
File metadata and controls
140 lines (123 loc) · 4.33 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
crane.url = "github:ipetkov/crane";
};
outputs = { self, nixpkgs, rust-overlay, crane }:
let
inherit (nixpkgs) lib;
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
"armv7l-linux"
];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [
(import rust-overlay)
];
};
rust-bin = rust-overlay.lib.mkRustBin { } pkgs.buildPackages;
toolchain = rust-bin.stable.latest.default.override {
extensions = [ "rust-src" ];
};
in f system pkgs toolchain);
in {
apps = let
mkApp = program: description: {
type = "app";
program = toString program;
meta = {
inherit description;
};
};
mkVm = name: mkApp "${self.nixosConfigurations.${name}.config.system.build.vm}/bin/run-nixos-vm";
in forAllSystems (system: pkgs: _: {
muscl = mkApp (lib.getExe self.packages.${system}.muscl) "Run muscl without any setup";
coverage = mkApp (pkgs.writeShellScript "muscl-coverage" ''
${lib.getExe pkgs.python3} -m http.server -d "${self.packages.${system}.coverage}/html"
'') "Serve code coverage report at http://localhost:8000";
vm = mkVm "vm" "Start a NixOS VM with muscl and mariadb installed";
vm-mysql = mkVm "vm-mysql" "Start a NixOS VM with muscl and mysql installed";
vm-suid = mkVm "vm-suid" "Start a NixOS VM with muscl as SUID/SGID installed";
});
nixosConfigurations = {
vm = import ./nix/nixos-configurations/vm.nix { inherit self nixpkgs; useMariadb = true; };
vm-mysql = import ./nix/nixos-configurations/vm.nix { inherit self nixpkgs; useMariadb = false; };
vm-suid = import ./nix/nixos-configurations/vm-suid.nix { inherit self nixpkgs; };
};
devShell = forAllSystems (system: pkgs: toolchain: pkgs.mkShell {
nativeBuildInputs = with pkgs; [
toolchain
mariadb.client
cargo-nextest
cargo-edit
cargo-deny
cargo-deb
dpkg
];
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
});
overlays = {
default = self.overlays.muscl;
muscl = final: prev: {
inherit (self.packages.${prev.stdenv.hostPlatform.system}) muscl;
};
muscl-crane = final: prev: {
muscl = self.packages.${prev.stdenv.hostPlatform.system}.muscl-crane;
};
muscl-suid = final: prev: {
muscl = self.packages.${prev.stdenv.hostPlatform.system}.muscl-suid;
};
muscl-suid-crane = final: prev: {
muscl = self.packages.${prev.stdenv.hostPlatform.system}.muscl-suid-crane;
};
};
nixosModules = {
default = self.nixosModules.muscl;
muscl = import ./nix/module.nix;
};
packages = forAllSystems (system: pkgs: _:
let
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
cargoLock = ./Cargo.lock;
craneLib = crane.mkLib pkgs;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
(craneLib.fileset.commonCargoSources ./.)
./assets
];
};
in {
default = self.packages.${system}.muscl-crane;
muscl = pkgs.callPackage ./nix/default.nix { inherit cargoToml cargoLock src; };
muscl-crane = pkgs.callPackage ./nix/default.nix {
useCrane = true;
inherit cargoToml cargoLock src craneLib;
};
muscl-suid = pkgs.callPackage ./nix/default.nix {
suidSgidSupport = true;
inherit cargoToml cargoLock src;
};
muscl-suid-crane = pkgs.callPackage ./nix/default.nix {
useCrane = true;
suidSgidSupport = true;
inherit cargoToml cargoLock src craneLib;
};
coverage = pkgs.callPackage ./nix/coverage.nix { inherit cargoToml cargoLock src; };
filteredSource = pkgs.runCommandLocal "filtered-source" { } ''
ln -s ${src} $out
'';
});
checks = forAllSystems (system: pkgs: _: {
# NOTE: the non-crane build runs tests during checkPhase
inherit (self.packages.${system}) muscl muscl-suid;
});
};
}