Skip to content

Commit

Permalink
ci: fix nix build (#15308)
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorwhitney authored Dec 9, 2024
1 parent f5d62bd commit 03a0587
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 221 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/nix-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
name: "Lint And Build Nix Flake"
on:
push:
branches:
- main
pull_request:
paths:
- "flake.nix"
Expand Down
4 changes: 4 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 35 additions & 46 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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";
};
Expand All @@ -80,10 +73,6 @@
inherit (pkgs) buildGoModule fetchFromGitHub;
})

(pkgs.callPackage ./nix/packages/faillint.nix {
inherit (pkgs) lib buildGoModule fetchFromGitHub;
})

chart-testing
gcc
go
Expand All @@ -94,7 +83,7 @@
nixpkgs-fmt
statix
yamllint
];
] // packages;
};
});
}
179 changes: 89 additions & 90 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -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";

# 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";

imageTag =
if (self ? rev) then
"${imageTagVersion}"
else
"${imageTagVersion}-WIP";

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;
};

logcli = loki.overrideAttrs (oldAttrs: {
pname = "logcli";

buildPhase = ''
export GOCACHE=$TMPDIR/go-cache
make clean logcli
'';

installPhase = ''
mkdir -p $out/bin
install -m755 cmd/logcli/logcli $out/bin/logcli
'';
});

loki-canary = loki.overrideAttrs (oldAttrs: {
pname = "loki-canary";

buildPhase = ''
export GOCACHE=$TMPDIR/go-cache
make clean loki-canary
'';

installPhase = ''
mkdir -p $out/bin
install -m755 cmd/loki-canary/loki-canary $out/bin/loki-canary
'';
});

promtail = loki.overrideAttrs (oldAttrs: {
pname = "promtail";

buildInputs =
let
inherit (oldAttrs) buildInputs;
in
if prev.stdenv.hostPlatform.isLinux then
buildInputs ++ (with prev; [ systemd ])
else buildInputs;

buildPhase = ''
export GOCACHE=$TMPDIR/go-cache
make clean promtail
'';

installPhase = ''
mkdir -p $out/bin
install -m755 clients/cmd/promtail/promtail $out/bin/promtail
'';
});
};
inherit (loki-helm-test) loki-helm-test loki-helm-test-docker;
} // rec {
loki = pkgs.callPackage ./packages/loki.nix {
inherit imageTag pkgs;
version = shortGitRevsion;
};

logcli = loki.overrideAttrs (oldAttrs: {
pname = "logcli";

subPackages = [ "cmd/logcli" ];

meta = with lib; {
description = "LogCLI is a command line tool for interacting with Loki.";
mainProgram = "logcli";
license = with licenses; [ agpl3Only ];
} // meta;
});

loki-canary = loki.overrideAttrs (oldAttrs: {
pname = "loki-canary";

subPackages = [ "cmd/loki-canary" ];

meta = with lib; {
description = "Loki Canary is a canary for the Loki project.";
mainProgram = "loki-canary";
license = with licenses; [ agpl3Only ];
} // meta;
});

promtail = loki.overrideAttrs (oldAttrs: {
pname = "promtail";

buildInputs = with pkgs; lib.optionals stdenv.hostPlatform.isLinux [ systemd.dev ];

tags = [ "promtail_journal_enabled" ];

subPackages = [ "clients/cmd/promtail" ];

preFixup = lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
wrapProgram $out/bin/promtail \
--prefix LD_LIBRARY_PATH : "${lib.getLib pkgs.systemd}/lib"
'';

meta = with lib; {
description = "Client for sending logs to Loki";
mainProgram = "promtail";
license = with licenses; [ asl20 ];
} // meta;
});
}
16 changes: 0 additions & 16 deletions nix/packages/faillint.nix

This file was deleted.

Loading

0 comments on commit 03a0587

Please sign in to comment.