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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
{
description = "git + woodpecker";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
outputs =
{
self,
nixpkgs,
...
}:
let
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
forAllSystems = f: nixpkgs.lib.genAttrs systems f;
in
{
packages = forAllSystems (
system:
let
pkgs = import nixpkgs { inherit system; };
in
{
default = self.packages.${system}.gitpecker;
gitpecker = pkgs.buildGoModule rec {
pname = "gitpecker";
version = self.rev or "dev";
src = pkgs.nix-gitignore.gitignoreSource [ ] (
builtins.path {
name = pname;
path = ./.;
}
);
vendorHash = nixpkgs.lib.fileContents ./go.mod.sri;
meta = {
description = "git + woodpecker";
homepage = "https://github.com/jolheiser/gitpecker";
mainProgram = "gitpecker";
};
};
}
);
devShells = forAllSystems (
system:
let
pkgs = import nixpkgs { inherit system; };
in
{
default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
go
gopls
gofumpt
woodpecker-server
];
};
}
);
nixosConfigurations.gitpeckerVM = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
(
{ pkgs, ... }:
{
services.getty.autologinUser = "root";
services.woodpecker-server = {
enable = true;
package = pkgs.woodpecker-server.overrideAttrs (oldAttrs: {
doCheck = false;
patches = (oldAttrs.patches or [ ]) ++ [ ./debug.patch ];
});
environment = {
WOODPECKER_HOST = "http://0.0.0.0:8000";
WOODPECKER_OPEN = "true";
WOODPECKER_ADDON_FORGE = "${self.packages.x86_64-linux.gitpecker}/bin/gitpecker";
WOODPECKER_LOG_LEVEL = "trace";
WOODPECKER_ADMIN = "jolheiser";
WOODPECKER_AGENT_SECRET = "Testing123";
GITPECKER_REPOS = "/var/lib/forge/";
GITPECKER_URL = "/var/lib/forge/";
GITPECKER_PROVIDER = "";
GITPECKER_CLIENT_ID = "";
GITPECKER_CLIENT_SECRET = "";
GITPECKER_REDIRECT = "http://localhost:8000/authorize";
GITPECKER_LOG_FILE = "/var/lib/woodpecker-server/addon.log";
GITPECKER_LOG_LEVEL = "debug";
};
};
services.woodpecker-agents.agents."007" = {
enable = true;
path = with pkgs; [
git
git-lfs
bash
coreutils
woodpecker-plugin-git
];
environment = {
WOODPECKER_AGENT_SECRET = "Testing123";
};
};
virtualisation.vmVariant.virtualisation = {
cores = 2;
memorySize = 2048;
graphics = false;
};
networking.firewall.enable = false;
systemd.services."setup-vm" = {
wantedBy = [ "multi-user.target" ];
path = with pkgs; [
git
];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
User = "root";
Group = "root";
ExecStart =
let
pipeline = {
steps = [
{
name = "honk";
image = "bash";
commands = [ ''echo "honk!"'' ];
}
];
};
in
pkgs.writeShellScript "setup-vm-script" ''
git config --global user.name "NixUser"
git config --global user.email "nixuser@example.com"
git config --global init.defaultBranch main
git config --global push.autoSetupRemote true
mkdir -p /var/lib/forge
pushd /var/lib/forge
git init --bare test1.git
git init --bare test2.git
popd
git clone /var/lib/forge/test1.git
pushd test1
cp ${(pkgs.formats.yaml { }).generate "pipeline.yaml" pipeline} .woodpecker.yaml
git add .
git commit -m "honk"
git push
popd
'';
};
};
environment.systemPackages = with pkgs; [
git
];
system.stateVersion = "23.11";
}
)
];
};
apps = forAllSystems (
system:
let
pkgs = import nixpkgs { inherit system; };
in
{
vm = {
type = "app";
program = "${pkgs.writeShellScript "vm" ''
nixos-rebuild build-vm --flake .#gitpeckerVM
export QEMU_NET_OPTS="hostfwd=tcp::8000-:8000"
./result/bin/run-nixos-vm
rm nixos.qcow2
''}";
};
}
);
};
}
|