-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflake.nix
More file actions
156 lines (142 loc) · 4.84 KB
/
Copy pathflake.nix
File metadata and controls
156 lines (142 loc) · 4.84 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
{
description = "PAM bindings for writing service modules in Golang";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
git-hooks-nix = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.git-hooks-nix.flakeModule
];
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];
perSystem =
{
pkgs,
system,
config,
...
}:
let
buildGoPAMModule =
{ pname, ... }@args:
pkgs.buildGoModule (
args
// {
env.CGO_CFLAGS = "-I${pkgs.pam}/include";
buildPhase = ''
runHook preBuild
if [ -z "$enableParallelBuilding" ]; then
export NIX_BUILD_CORES=1
fi
go build '-ldflags=-buildid= -extldflags="-L${pkgs.pam}/lib"' -buildmode=c-shared -o ${pname}.so -p "$NIX_BUILD_CORES" .
go build '-ldflags=-buildid= -extldflags="-L${pkgs.pam}/lib"' -o ${pname}-helper -p "$NIX_BUILD_CORES" .
chmod +x ${pname}.so
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/lib/security
mkdir -p $out/bin
cp ${pname}.so $out/lib/security
cp ${pname}-helper $out/bin
runHook postInstall
'';
}
);
in
{
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
(final: prev: {
pamtester = prev.pamtester.overrideAttrs (_: _: { meta.platform = prev.lib.platforms.unix; });
})
];
config = { };
};
packages = {
pam_spicedb = buildGoPAMModule {
pname = "pam_spicedb";
version = "0.0.1";
src = ./examples/pam_spicedb;
vendorHash = null;
meta = {
description = "pam_spicedb.so is a PAM module that validates a user's account by checking a permission in SpiceDB.";
mainProgram = "lib/security/pam_spicedb.so";
homepage = "https://github.com/squat/pam";
};
};
pam_print = buildGoPAMModule {
pname = "pam_print";
version = "0.0.1";
src = ./examples/pam_print;
vendorHash = null;
meta = {
description = "pam_print.so is a PAM module that prints the user, flags, arguments, and environment variables provided to the module.";
mainProgram = "lib/security/pam_print.so";
homepage = "https://github.com/squat/pam";
};
};
};
pre-commit = {
check.enable = true;
settings = {
src = ./.;
hooks = {
actionlint.enable = true;
nixfmt-rfc-style.enable = true;
gofmt.enable = true;
gofmt.excludes = [ "examples/pam_.*/vendor" ];
govet.enable = true;
govet.excludes = [ "examples/pam_.*/vendor" ];
govet.extraPackages = [ pkgs.pam ];
readme = {
enable = true;
name = "README.md";
entry =
let
readmeCheck = pkgs.writeShellApplication {
name = "readme-check";
text = ''
for f in "$@"; do
if ! grep -q embedmd "$f"; then continue; fi
(cd "$(dirname "$f")" && go run ./... --help 2>help.txt)
go tool embedmd -d "$f"
done
'';
};
in
pkgs.lib.getExe readmeCheck;
files = "README\\.md$";
extraPackages = [ pkgs.go ];
excludes = [ "examples/pam_.*/vendor" ];
};
};
};
};
devShells = {
default = pkgs.mkShell {
inherit (config.pre-commit.devShell) shellHook;
packages =
with pkgs;
[
go
pam
pamtester
]
++ config.pre-commit.settings.enabledPackages;
};
};
};
};
}