-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
111 lines (103 loc) · 3.5 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
{
description = "Nix support for the AppArmor user space development project.";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# nixpkgs.url = "git+file:/home/grimmauld/coding/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
nix-github-actions = {
url = "github:nix-community/nix-github-actions";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
nix-github-actions,
flake-utils,
}:
let
gen_aa_pkgs = pkgs: {
inherit (pkgs.callPackages ./pkgs { })
libapparmor
apparmor-utils
apparmor-bin-utils
apparmor-parser
apparmor-pam
apparmor-profiles
apparmor-kernel-patches
apparmor-regression-test
;
};
in
(flake-utils.lib.eachSystem [ "aarch64-linux" "x86_64-linux" ] (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
nixos-lib = import (nixpkgs + "/nixos/lib") { };
inherit (pkgs) lib;
aa_pkgs = gen_aa_pkgs pkgs;
in
{
packages = aa_pkgs;
checks =
let
overlayed = pkgs.extend self.overlays.default;
aa-nixos-test-config = overlayed.nixosTests.apparmor.config;
in
aa_pkgs
// {
apparmor-nixpkgs-test = nixos-lib.runTest {
hostPkgs = overlayed;
imports = lib.singleton {
inherit (aa-nixos-test-config) name;
nodes.machine = {
# cursed stuff to make the overlay actually apply with all the reimports of nixpkgs
security.apparmor = {
inherit (aa-nixos-test-config.nodes.machine.security.apparmor) enable policies;
};
security.apparmor.includes."abstractions/base" = ''
/nix/store/*/bin/** mr,
/nix/store/*/lib/** mr,
/nix/store/** r,
'';
nixpkgs.overlays = [ self.overlays.default ];
};
};
inherit (aa-nixos-test-config) testScript;
};
apparmor-regression-test = nixos-lib.runTest {
hostPkgs = overlayed;
imports = lib.singleton {
name = "appaarmor-regression-test-vm";
nodes.test = {
security.apparmor.enable = true;
security.apparmor.enableCache = true; # e2e tess expects caches
security.auditd.enable = true;
nixpkgs.overlays = [ self.overlays.default ];
};
};
testScript = ''
print("Starting VM test...")
machine.wait_for_unit("default.target")
machine.succeed("journalctl -u apparmor -b 0")
machine.succeed("${lib.getExe aa_pkgs.apparmor-regression-test}")
'';
};
};
lib = {
apparmorRulesFromClosure = pkgs.callPackage ./nix/apparmorRulesFromClosure.nix { };
};
formatter = pkgs.nixfmt-rfc-style;
}
))
// {
overlays.default = final: prev: (gen_aa_pkgs prev);
githubActions = nix-github-actions.lib.mkGithubMatrix {
checks = nixpkgs.lib.getAttrs [ "x86_64-linux" ] self.checks;
}; # todo: figure out testing on aarch64-linux
nixosModules.default = {
nixpkgs.overlays = [ self.overlays.default ];
};
};
}