mirror of
https://github.com/grafana/loki.git
synced 2026-03-13 09:33:58 +08:00
ci: fix nix build (#15308)
This commit is contained in:
3
.github/workflows/nix-ci.yaml
vendored
3
.github/workflows/nix-ci.yaml
vendored
@@ -1,6 +1,9 @@
|
||||
---
|
||||
name: "Lint And Build Nix Flake"
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
paths:
|
||||
- "flake.nix"
|
||||
|
||||
@@ -12,5 +12,9 @@
|
||||
# The observability logs team is listed as co-codeowner for grammar file. This is to receive notifications about updates, so these can be implemented in https://github.com/grafana/lezer-logql
|
||||
/pkg/logql/syntax/expr.y @grafana/observability-logs @grafana/loki-team
|
||||
|
||||
# Nix
|
||||
/nix/ @trevorwhitney
|
||||
flake.nix @trevorwhitney
|
||||
|
||||
# No owners - allows sub-maintainers to merge changes.
|
||||
CHANGELOG.md
|
||||
|
||||
81
flake.nix
81
flake.nix
@@ -6,41 +6,21 @@
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
# Nixpkgs / NixOS version to use.
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
let
|
||||
nix = import ./nix { inherit self; };
|
||||
in
|
||||
{
|
||||
overlays = {
|
||||
default = nix.overlay;
|
||||
};
|
||||
} //
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [
|
||||
nix.overlay
|
||||
];
|
||||
config = { allowUnfree = true; };
|
||||
};
|
||||
pkgs = import nixpkgs
|
||||
{
|
||||
inherit system;
|
||||
config = { allowUnfree = true; };
|
||||
};
|
||||
in
|
||||
{
|
||||
# The default package for 'nix build'. This makes sense if the
|
||||
# flake provides only one package or there is a clear "main"
|
||||
# package.
|
||||
rec {
|
||||
defaultPackage = pkgs.loki;
|
||||
|
||||
packages = with pkgs; {
|
||||
inherit
|
||||
logcli
|
||||
loki
|
||||
loki-canary
|
||||
loki-helm-test
|
||||
loki-helm-test-docker
|
||||
promtail;
|
||||
packages = import ./nix {
|
||||
inherit self pkgs;
|
||||
inherit (pkgs) lib;
|
||||
};
|
||||
|
||||
apps = {
|
||||
@@ -56,18 +36,31 @@
|
||||
|
||||
test = {
|
||||
type = "app";
|
||||
program = with pkgs; "${
|
||||
(writeShellScriptBin "test.sh" ''
|
||||
${loki.overrideAttrs(old: {
|
||||
buildInputs =
|
||||
let
|
||||
inherit (old) buildInputs;
|
||||
in
|
||||
if pkgs.stdenv.hostPlatform.isLinux then
|
||||
buildInputs ++ (with pkgs; [ systemd ])
|
||||
else buildInputs;
|
||||
doCheck = true;
|
||||
})}/bin/loki --version
|
||||
program =
|
||||
let
|
||||
loki = packages.loki.overrideAttrs (old: {
|
||||
buildInputs = with pkgs; lib.optionals stdenv.hostPlatform.isLinux [ systemd.dev ];
|
||||
doCheck = true;
|
||||
checkFlags = [
|
||||
"-covermode=atomic"
|
||||
"-coverprofile=coverage.txt"
|
||||
"-p=4"
|
||||
];
|
||||
subPackages = [
|
||||
"./..." # for tests
|
||||
"cmd/loki"
|
||||
"cmd/logcli"
|
||||
"cmd/loki-canary"
|
||||
"clients/cmd/promtail"
|
||||
];
|
||||
});
|
||||
in
|
||||
"${
|
||||
(pkgs.writeShellScriptBin "test.sh" ''
|
||||
${loki}/bin/loki --version
|
||||
${loki}/bin/logcli --version
|
||||
${loki}/bin/loki-canary --version
|
||||
${loki}/bin/promtail --version
|
||||
'')
|
||||
}/bin/test.sh";
|
||||
};
|
||||
@@ -80,10 +73,6 @@
|
||||
inherit (pkgs) buildGoModule fetchFromGitHub;
|
||||
})
|
||||
|
||||
(pkgs.callPackage ./nix/packages/faillint.nix {
|
||||
inherit (pkgs) lib buildGoModule fetchFromGitHub;
|
||||
})
|
||||
|
||||
chart-testing
|
||||
gcc
|
||||
go
|
||||
@@ -94,7 +83,7 @@
|
||||
nixpkgs-fmt
|
||||
statix
|
||||
yamllint
|
||||
];
|
||||
] // packages;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
155
nix/default.nix
155
nix/default.nix
@@ -1,92 +1,91 @@
|
||||
{ self }:
|
||||
{ self, pkgs, lib }:
|
||||
let
|
||||
# self.rev is only set on a clean git tree
|
||||
gitRevision = if (self ? rev) then self.rev else "dirty";
|
||||
shortGitRevsion = with lib;
|
||||
if (self ? rev) then
|
||||
(strings.concatStrings
|
||||
(lists.take 8 (strings.stringToCharacters gitRevision)))
|
||||
else
|
||||
"dirty";
|
||||
|
||||
# the image tag script is hard coded to take only 7 characters
|
||||
imageTagVersion = with lib;
|
||||
if (self ? rev) then
|
||||
(strings.concatStrings
|
||||
(lists.take 8 (strings.stringToCharacters gitRevision)))
|
||||
else
|
||||
"dirty";
|
||||
|
||||
imageTag =
|
||||
if (self ? rev) then
|
||||
"${imageTagVersion}"
|
||||
else
|
||||
"${imageTagVersion}-WIP";
|
||||
|
||||
meta = with lib; {
|
||||
homepage = "https://grafana.com/oss/loki/";
|
||||
changelog = "https://github.com/grafana/loki/commit/${shortGitRevsion}";
|
||||
maintainers = with maintainers; [ trevorwhitney ];
|
||||
|
||||
};
|
||||
|
||||
loki-helm-test = pkgs.callPackage ../production/helm/loki/src/helm-test {
|
||||
inherit pkgs;
|
||||
inherit (pkgs) lib buildGoModule dockerTools;
|
||||
rev = gitRevision;
|
||||
};
|
||||
in
|
||||
{
|
||||
overlay = final: prev:
|
||||
let
|
||||
# self.rev is only set on a clean git tree
|
||||
gitRevision = if (self ? rev) then self.rev else "dirty";
|
||||
shortGitRevsion = with prev.lib;
|
||||
if (self ? rev) then
|
||||
(strings.concatStrings
|
||||
(lists.take 8 (strings.stringToCharacters gitRevision)))
|
||||
else
|
||||
"dirty";
|
||||
inherit (loki-helm-test) loki-helm-test loki-helm-test-docker;
|
||||
} // rec {
|
||||
loki = pkgs.callPackage ./packages/loki.nix {
|
||||
inherit imageTag pkgs;
|
||||
version = shortGitRevsion;
|
||||
};
|
||||
|
||||
# the image tag script is hard coded to take only 7 characters
|
||||
imageTagVersion = with prev.lib;
|
||||
if (self ? rev) then
|
||||
(strings.concatStrings
|
||||
(lists.take 8 (strings.stringToCharacters gitRevision)))
|
||||
else
|
||||
"dirty";
|
||||
logcli = loki.overrideAttrs (oldAttrs: {
|
||||
pname = "logcli";
|
||||
|
||||
imageTag =
|
||||
if (self ? rev) then
|
||||
"${imageTagVersion}"
|
||||
else
|
||||
"${imageTagVersion}-WIP";
|
||||
subPackages = [ "cmd/logcli" ];
|
||||
|
||||
loki-helm-test = prev.callPackage ../production/helm/loki/src/helm-test {
|
||||
inherit (prev) pkgs lib buildGoModule dockerTools;
|
||||
rev = gitRevision;
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit (loki-helm-test) loki-helm-test loki-helm-test-docker;
|
||||
} // rec {
|
||||
loki = prev.callPackage ./packages/loki.nix {
|
||||
inherit imageTag;
|
||||
version = shortGitRevsion;
|
||||
pkgs = prev;
|
||||
};
|
||||
meta = with lib; {
|
||||
description = "LogCLI is a command line tool for interacting with Loki.";
|
||||
mainProgram = "logcli";
|
||||
license = with licenses; [ agpl3Only ];
|
||||
} // meta;
|
||||
});
|
||||
|
||||
logcli = loki.overrideAttrs (oldAttrs: {
|
||||
pname = "logcli";
|
||||
loki-canary = loki.overrideAttrs (oldAttrs: {
|
||||
pname = "loki-canary";
|
||||
|
||||
buildPhase = ''
|
||||
export GOCACHE=$TMPDIR/go-cache
|
||||
make clean logcli
|
||||
'';
|
||||
subPackages = [ "cmd/loki-canary" ];
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
install -m755 cmd/logcli/logcli $out/bin/logcli
|
||||
'';
|
||||
});
|
||||
meta = with lib; {
|
||||
description = "Loki Canary is a canary for the Loki project.";
|
||||
mainProgram = "loki-canary";
|
||||
license = with licenses; [ agpl3Only ];
|
||||
} // meta;
|
||||
});
|
||||
|
||||
loki-canary = loki.overrideAttrs (oldAttrs: {
|
||||
pname = "loki-canary";
|
||||
promtail = loki.overrideAttrs (oldAttrs: {
|
||||
pname = "promtail";
|
||||
|
||||
buildPhase = ''
|
||||
export GOCACHE=$TMPDIR/go-cache
|
||||
make clean loki-canary
|
||||
'';
|
||||
buildInputs = with pkgs; lib.optionals stdenv.hostPlatform.isLinux [ systemd.dev ];
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
install -m755 cmd/loki-canary/loki-canary $out/bin/loki-canary
|
||||
'';
|
||||
});
|
||||
tags = [ "promtail_journal_enabled" ];
|
||||
|
||||
promtail = loki.overrideAttrs (oldAttrs: {
|
||||
pname = "promtail";
|
||||
subPackages = [ "clients/cmd/promtail" ];
|
||||
|
||||
buildInputs =
|
||||
let
|
||||
inherit (oldAttrs) buildInputs;
|
||||
in
|
||||
if prev.stdenv.hostPlatform.isLinux then
|
||||
buildInputs ++ (with prev; [ systemd ])
|
||||
else buildInputs;
|
||||
preFixup = lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
|
||||
wrapProgram $out/bin/promtail \
|
||||
--prefix LD_LIBRARY_PATH : "${lib.getLib pkgs.systemd}/lib"
|
||||
'';
|
||||
|
||||
buildPhase = ''
|
||||
export GOCACHE=$TMPDIR/go-cache
|
||||
make clean promtail
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
install -m755 clients/cmd/promtail/promtail $out/bin/promtail
|
||||
'';
|
||||
});
|
||||
};
|
||||
meta = with lib; {
|
||||
description = "Client for sending logs to Loki";
|
||||
mainProgram = "promtail";
|
||||
license = with licenses; [ asl20 ];
|
||||
} // meta;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
{ lib, buildGoModule, fetchFromGitHub }:
|
||||
|
||||
buildGoModule rec {
|
||||
pname = "faillint";
|
||||
version = "v1.14.0";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "fatih";
|
||||
repo = "faillint";
|
||||
rev = "${version}";
|
||||
sha256 = "NV+wbu547mtTa6dTGv7poBwWXOmu5YjqbauzolCg5qs=";
|
||||
};
|
||||
|
||||
vendorHash = "sha256-vWt4HneDA7YwXYnn8TbfWCKzSv7RcgXxn/HAh6a+htQ=";
|
||||
doCheck = false;
|
||||
}
|
||||
@@ -1,78 +1,38 @@
|
||||
{ pkgs, version, imageTag }:
|
||||
let
|
||||
lambda-promtail-gomod = pkgs.buildGoModule {
|
||||
inherit version;
|
||||
pname = "lambda-promtail";
|
||||
|
||||
src = ./../../tools/lambda-promtail;
|
||||
vendorHash = "sha256-yQIRFUhod91HiPS5IKm7eNeIXJzBWVcvIXf9qMncTKw=";
|
||||
|
||||
doCheck = false;
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
cp -r --reflink=auto vendor $out
|
||||
runHook postInstall
|
||||
'';
|
||||
};
|
||||
in
|
||||
pkgs.stdenv.mkDerivation {
|
||||
{ pkgs, version, imageTag, lib }:
|
||||
pkgs.buildGo123Module {
|
||||
inherit version;
|
||||
|
||||
pname = "loki";
|
||||
|
||||
src = ./../..;
|
||||
vendorHash = null;
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
bash
|
||||
gcc
|
||||
git
|
||||
go_1_23
|
||||
golangci-lint
|
||||
gotools
|
||||
nettools
|
||||
yamllint
|
||||
ldflags =
|
||||
let
|
||||
prefix = "github.com/grafana/loki/v3/pkg/util/build";
|
||||
in
|
||||
[
|
||||
"-s"
|
||||
"-w"
|
||||
"-X ${prefix}.Branch=nix"
|
||||
"-X ${prefix}.Version=${imageTag}"
|
||||
"-X ${prefix}.Revision=${version}"
|
||||
"-X ${prefix}.BuildUser=nix@nixpkgs"
|
||||
"-X ${prefix}.BuildDate=unknown"
|
||||
];
|
||||
|
||||
(import ./faillint.nix {
|
||||
inherit (pkgs) lib buildGoModule fetchFromGitHub;
|
||||
})
|
||||
];
|
||||
subPackages = [ "cmd/loki" ];
|
||||
|
||||
configurePhase = with pkgs; ''
|
||||
patchShebangs tools
|
||||
|
||||
substituteInPlace Makefile \
|
||||
--replace "SHELL = /usr/bin/env bash -o pipefail" "SHELL = ${bash}/bin/bash -o pipefail" \
|
||||
--replace "IMAGE_TAG ?= \$(shell ./tools/image-tag)" "IMAGE_TAG ?= ${imageTag}" \
|
||||
--replace "GIT_REVISION := \$(shell git rev-parse --short HEAD)" "GIT_REVISION := ${version}" \
|
||||
--replace "GIT_BRANCH := \$(shell git rev-parse --abbrev-ref HEAD)" "GIT_BRANCH := nix"
|
||||
|
||||
substituteInPlace clients/cmd/fluentd/Makefile \
|
||||
--replace "SHELL = /usr/bin/env bash -o pipefail" "SHELL = ${bash}/bin/bash -o pipefail"
|
||||
'';
|
||||
|
||||
buildPhase = ''
|
||||
export GOCACHE=$TMPDIR/go-cache
|
||||
export GOMODCACHE=$TMPDIR/gomodcache
|
||||
export GOPROXY=off
|
||||
|
||||
cp -r ${lambda-promtail-gomod} tools/lambda-promtail/vendor
|
||||
make clean loki
|
||||
'';
|
||||
nativeBuildInputs = with pkgs; [ makeWrapper ];
|
||||
|
||||
doCheck = false;
|
||||
checkPhase = ''
|
||||
export GOCACHE=$TMPDIR/go-cache
|
||||
export GOMODCACHE=$TMPDIR/gomodcache
|
||||
export GOLANGCI_LINT_CACHE=$TMPDIR/go-cache
|
||||
export GOPROXY=off
|
||||
export BUILD_IN_CONTAINER=false
|
||||
|
||||
make lint test
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
install -m755 cmd/loki/loki $out/bin/loki
|
||||
'';
|
||||
meta = with lib; {
|
||||
description = "Like Prometheus, but for logs";
|
||||
mainProgram = "loki";
|
||||
license = with licenses; [ agpl3Only ];
|
||||
homepage = "https://grafana.com/oss/loki/";
|
||||
changelog = "https://github.com/grafana/loki/commit/${version}";
|
||||
maintainers = with maintainers; [ trevorwhitney ];
|
||||
};
|
||||
}
|
||||
|
||||
@@ -188,6 +188,7 @@ server:
|
||||
common:
|
||||
compactor_address: http://localhost:%d
|
||||
path_prefix: /tmp/loki
|
||||
instance_addr: localhost
|
||||
ring:
|
||||
kvstore:
|
||||
store: inmemory
|
||||
|
||||
@@ -406,6 +406,7 @@ func minimalWorkingConfig(t *testing.T, dir, target string, cfgTransformers ...f
|
||||
}
|
||||
|
||||
cfg.Common.InstanceAddr = localhost
|
||||
cfg.MemberlistKV.AdvertiseAddr = localhost
|
||||
cfg.Ingester.LifecyclerConfig.Addr = localhost
|
||||
cfg.Distributor.DistributorRing.InstanceAddr = localhost
|
||||
cfg.IndexGateway.Mode = indexgateway.SimpleMode
|
||||
|
||||
Reference in New Issue
Block a user