-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Add nix configuration #7020
Add nix configuration #7020
Conversation
{ | ||
imageTag = "main-5a6d09f"; | ||
gitRevision = "5a6d09f83"; | ||
gitBranch = "main"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in general there probably isn't much need to commit changes to this file, so I decided to have it track main
. The gitRevision
is only used on dirty git trees, and there's a shell hook that will automatically update these values for your local branch when you run nix develop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reasoning to have it in git?
I suspect to still be able to build the derivation when the flake is imported. I would prefer to have a unknown
revision instead. As otherwise it is just implying the wrong thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so are you suggesting we use either self.rev
or unknown
(when self.rev
is not set, which would mean the local git tree is dirty)?
./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell. + ingester 0%
+ distributor 0%
+ querier 0%
+ querier/queryrange 0%
+ iter 0%
+ storage 0%
+ chunkenc 0%
+ logql 0%
+ loki 0% |
1 similar comment
./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell. + ingester 0%
+ distributor 0%
+ querier 0%
+ querier/queryrange 0%
+ iter 0%
+ storage 0%
+ chunkenc 0%
+ logql 0%
+ loki 0% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I welcome this initiative. It is quite useful to have this as standardized environments and maybe in the future we could expand this to also form the basis of our CI/release (if helpful)
I think before we merge we should have some CI around that at least enforced the formatting of nix files and run a build.
For some reason in my local environment (on nixos) I have trouble building the loki derivation and I need that patch:
failed to initialize build cache at /homeless-shelter/.cache/go-build: mkdir /homeless-shelter: permission denied
[...]
failed to initialize build cache at /homeless-shelter/.cache/golangci-lint: mkdir /homeless-shelter: permission denied
--- a/nix/loki.nix
+++ b/nix/loki.nix
@@ -30,11 +30,13 @@ pkgs.stdenv.mkDerivation {
'';
buildPhase = ''
+ export GOCACHE=$TMPDIR/go-cache
make clean loki logcli loki-canary promtail
'';
doCheck = true;
checkPhase = ''
+ export GOCACHE=$TMPDIR/go-cache
make lint test
'';
{ | ||
imageTag = "main-5a6d09f"; | ||
gitRevision = "5a6d09f83"; | ||
gitBranch = "main"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reasoning to have it in git?
I suspect to still be able to build the derivation when the flake is imported. I would prefer to have a unknown
revision instead. As otherwise it is just implying the wrong thing.
|
||
You will also need to enable the Flakes feature to use Nix with this repo. See this [wiki](https://nixos.wiki/wiki/Flakes) for instructions on enabling Flakes. | ||
|
||
## Dealing with .git |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried the approach lined out in: https://stackoverflow.com/questions/67025103/how-inject-git-revision-into-nix-derivation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I am using the approach lined out in that link, which if I read correctly is to use self.rev
for flakes? Maybe I'm misunderstanding if there's another workaround in that article?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, I see, the suggestion is to use (builtins.fetchGit args).rev
. That will not work, as the url here would be ./..
or self
, which in either case points to the source in the nix store which has already been stripped of git info, so fetchGit
will complain that this is not a git repo.
./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell. + ingester 0%
+ distributor 0%
+ querier 0%
+ querier/queryrange 0%
+ iter 0%
+ storage 0%
+ chunkenc 0%
+ logql 0%
+ loki 0% |
So, if you import the flake it will not use the value of |
Build is currently broken, waiting on: #7029 |
./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell. + ingester 0%
+ distributor 0%
+ querier 0%
+ querier/queryrange 0%
+ iter 0%
+ storage 0%
+ chunkenc 0%
+ logql 0%
+ loki 0% |
3 similar comments
./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell. + ingester 0%
+ distributor 0%
+ querier 0%
+ querier/queryrange 0%
+ iter 0%
+ storage 0%
+ chunkenc 0%
+ logql 0%
+ loki 0% |
./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell. + ingester 0%
+ distributor 0%
+ querier 0%
+ querier/queryrange 0%
+ iter 0%
+ storage 0%
+ chunkenc 0%
+ logql 0%
+ loki 0% |
./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell. + ingester 0%
+ distributor 0%
+ querier 0%
+ querier/queryrange 0%
+ iter 0%
+ storage 0%
+ chunkenc 0%
+ logql 0%
+ loki 0% |
**What this PR does / why we need it**: The build is currently dependent upon you building in an environment with internet connectivity and GCP credentials. This PR fixes the few parts of our code and test that rely on these external dependencies so it can be built in an environment without internet or GCP credentials (such as when building a [nix flake](#7020)) **Which issue(s) this PR fixes**: Fixes #7028
Co-authored-by: Christian Simon <simon@swine.de>
fd16fbd
to
3e93d2f
Compare
./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell. + ingester 0%
+ distributor 0%
+ querier 0%
+ querier/queryrange 0%
+ iter 0%
+ storage 0%
+ chunkenc 0%
+ logql 0%
+ loki 0% |
./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell. + ingester 0%
+ distributor 0%
+ querier 0%
+ querier/queryrange 0%
+ iter 0%
+ storage 0%
+ chunkenc 0%
+ logql 0%
+ loki 0% |
**What this PR does / why we need it**: The build is currently dependent upon you building in an environment with internet connectivity and GCP credentials. This PR fixes the few parts of our code and test that rely on these external dependencies so it can be built in an environment without internet or GCP credentials (such as when building a [nix flake](grafana#7020)) **Which issue(s) this PR fixes**: Fixes grafana#7028
**What this PR does / why we need it**: This PR adds nix configuration to the Loki repo to make it easier for people who use nix to integrate building Loki into their existing workflows. For example, I have a `direnv` hook that uses nix shell to make sure I have the correct version of all dependent binaries (ie. `go`, `golangci-lint`, etc) on my `$PATH` whenever I change into the Loki directory. I find this especially useful for building with `CGO` enabled as it requires a C compiler with systemd headers to be available on the path. Furthermore, by having a `flake.nix` in the root of this repo, it will make it easier for users of the nix package manager to grab a specific version of Loki for their own systems / projects. This PR does _not_ attempt to replace any existing build processes, this is merely supplemental. All these nix configurations wrap existing `Makefile` targets, and the addition of these files will have no effect on anyone not using nix. Please see the README.md included in this PR for more information. **Checklist** - [X] Documentation added Co-authored-by: Christian Simon <simon@swine.de>
What this PR does / why we need it:
This PR adds nix configuration to the Loki repo to make it easier for people who use nix to integrate building Loki into their existing workflows. For example, I have a
direnv
hook that uses nix shell to make sure I have the correct version of all dependent binaries (ie.go
,golangci-lint
, etc) on my$PATH
whenever I change into the Loki directory. I find this especially useful for building withCGO
enabled as it requires a C compiler with systemd headers to be available on the path.Furthermore, by having a
flake.nix
in the root of this repo, it will make it easier for users of the nix package manager to grab a specific version of Loki for their own systems / projects.This PR does not attempt to replace any existing build processes, this is merely supplemental. All these nix configurations wrap existing
Makefile
targets, and the addition of these files will have no effect on anyone not using nix.Please see the README.md included in this PR for more information.
Checklist