Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add option to build project with nix #4263

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extras/
/dist/
/data/
datastore/migration/testfiles/
result

docs/venv

Expand Down
90 changes: 89 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,108 @@
};

outputs =
{ nixpkgs, flake-utils, ... }:
{
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};

# Common attributes for all components
commonAttrs = {
version = "0.0.0";
vendorHash = "sha256-0hInlX2yXf9IBW1h9lYeG1pn9v3LtVRoWNJJIiIdPaU=";
};

# Common builder function for woodpecker components
mkWoodpeckerComponent =
{
pname,
subPackages ? [ ],
buildTags ? [ ],
nativeBuildInputs ? [ ],
preBuild ? "",
CGO_ENABLED ? "0",
}:
pkgs.buildGoModule ({
inherit pname;
inherit (commonAttrs)
version
vendorHash
;
inherit
subPackages
buildTags
nativeBuildInputs
preBuild
CGO_ENABLED
;

src = ./.;

meta = {
mainProgram = pname;
description = "A distributed CI/CD system";
homepage = "https://woodpecker-ci.org";
license = pkgs.lib.licenses.asl20;
};
});

in
{
packages = rec {
cli = mkWoodpeckerComponent {
pname = "woodpecker-cli";
subPackages = [ "cmd/cli" ];
};

server = mkWoodpeckerComponent {
pname = "woodpecker-server";
subPackages = [ "cmd/server" ];
CGO_ENABLED = "1";
nativeBuildInputs = with pkgs; [
nodejs_20
pnpm
gnumake
];
preBuild = ''
export HOME=$(mktemp -d)

cd web
pnpm install --frozen-lockfile
pnpm build
cd ..

go generate cmd/server/swagger.go
'';
};

agent = mkWoodpeckerComponent {
pname = "woodpecker-agent";
subPackages = [ "cmd/agent" ];
};

default = pkgs.symlinkJoin {
name = "woodpecker";
paths = [
cli
agent
# server # need impure because of pnpm
];
};
};

devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
# generic
gnumake
gnutar
zip
tree
git

# frontend
nodejs_20
Expand Down