diff --git a/flake.nix b/flake.nix index 4f905b756c6b8..37d472b238b83 100644 --- a/flake.nix +++ b/flake.nix @@ -9,65 +9,74 @@ # Nixpkgs / NixOS version to use. outputs = { self, nixpkgs, flake-utils }: + let + golangci-lint-overlay = final: prev: { + golangci-lint = prev.callPackage + "${prev.path}/pkgs/development/tools/golangci-lint" + { + buildGoModule = args: + prev.buildGoModule (args // rec { + version = "1.45.2"; + + src = prev.fetchFromGitHub rec { + owner = "golangci"; + repo = "golangci-lint"; + rev = "v${version}"; + sha256 = + "sha256-Mr45nJbpyzxo0ZPwx22JW2WrjyjI9FPpl+gZ7NIc6WQ="; + }; + + vendorSha256 = + "sha256-pcbKg1ePN8pObS9EzP3QYjtaty27L9sroKUs/qEPtJo="; + + ldflags = [ + "-s" + "-w" + "-X main.version=${version}" + "-X main.commit=v${version}" + "-X main.date=19700101-00:00:00" + ]; + }); + }; + }; + + helm-docs-overlay = final: prev: { + helm-docs = prev.callPackage + "${prev.path}/pkgs/applications/networking/cluster/helm-docs" + { + buildGoModule = args: + prev.buildGoModule (args // rec { + version = "1.8.1"; + + src = prev.fetchFromGitHub { + owner = "norwoodj"; + repo = "helm-docs"; + rev = "v${version}"; + sha256 = "sha256-OpS/CYBb2Ll6ktvEhqkw/bWMSrFa4duidK3Glu8EnPw="; + }; + + vendorSha256 = "sha256-FpmeOQ8nV+sEVu2+nY9o9aFbCpwSShQUFOmyzwEQ9Pw="; + + ldflags = [ + "-w" + "-s" + "-X main.version=v${version}" + ]; + }); + }; + }; + + nix = import ./nix { inherit self; }; + in + { + overlays = { + golangci-lint = golangci-lint-overlay; + helm-docs = helm-docs-overlay; + default = nix.overlay; + }; + } // flake-utils.lib.eachDefaultSystem (system: let - golangci-lint-overlay = final: prev: { - golangci-lint = prev.callPackage - "${prev.path}/pkgs/development/tools/golangci-lint" - { - buildGoModule = args: - prev.buildGoModule (args // rec { - version = "1.45.2"; - - src = prev.fetchFromGitHub rec { - owner = "golangci"; - repo = "golangci-lint"; - rev = "v${version}"; - sha256 = - "sha256-Mr45nJbpyzxo0ZPwx22JW2WrjyjI9FPpl+gZ7NIc6WQ="; - }; - - vendorSha256 = - "sha256-pcbKg1ePN8pObS9EzP3QYjtaty27L9sroKUs/qEPtJo="; - - ldflags = [ - "-s" - "-w" - "-X main.version=${version}" - "-X main.commit=v${version}" - "-X main.date=19700101-00:00:00" - ]; - }); - }; - }; - - helm-docs-overlay = final: prev: { - helm-docs = prev.callPackage - "${prev.path}/pkgs/applications/networking/cluster/helm-docs" - { - buildGoModule = args: - prev.buildGoModule (args // rec { - version = "1.8.1"; - - src = prev.fetchFromGitHub { - owner = "norwoodj"; - repo = "helm-docs"; - rev = "v${version}"; - sha256 = "sha256-OpS/CYBb2Ll6ktvEhqkw/bWMSrFa4duidK3Glu8EnPw="; - }; - - vendorSha256 = "sha256-FpmeOQ8nV+sEVu2+nY9o9aFbCpwSShQUFOmyzwEQ9Pw="; - - ldflags = [ - "-w" - "-s" - "-X main.version=v${version}" - ]; - }); - }; - }; - - nix = import ./nix { inherit self nixpkgs system; }; pkgs = import nixpkgs { inherit system; @@ -141,12 +150,6 @@ chart-testing chart-releaser ]; - - shellHook = '' - pushd $(git rev-parse --show-toplevel) > /dev/null || exit 1 - ./nix/generate-build-vars.sh - popd > /dev/null || exit 1 - ''; }; }); } diff --git a/nix/README.md b/nix/README.md index 1c5fefd6e4578..f8867899ad755 100644 --- a/nix/README.md +++ b/nix/README.md @@ -28,9 +28,3 @@ To build the repo (including running tests), from the root of the repo you can r Nix is supported on Linux, MacOS, and Windows (WSL2). Check [here](https://nixos.org/download.html#download-nix) for installation instructions for your specific platform. 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 - -When building a Nix Flake, the source is first copied into the Nix Store. For immutability (and maybe security) reasons, the `.git` folder is not included in the files copied to the Nix Store. As a result, a Flake cannot rely on `git` commands in it's build. This project does, however, rely on `git` commands during the build. The workaround is the `generate-build-vars.sh` script and `build-vars.nix` file in this folder. The former creates the latter, which should not be edited by hand. There is a shell hook that will run this script whenever you drop into a Nix shell using `nix develop`. While not ideal, by dealing with this through a Nix shell hook, there's no need to change the build process for anyone not using nix. - -The `gitRevision` in this file is only used when running `nix build` on a dirty git tree. Otherwise the flake's `self.rev` is used. Therefore, it is probably not necessary to commit changes to `build-vars.nix`. diff --git a/nix/build-vars.nix b/nix/build-vars.nix deleted file mode 100644 index 276616f039385..0000000000000 --- a/nix/build-vars.nix +++ /dev/null @@ -1,10 +0,0 @@ -# DO NOT EDIT, this file is auto-generated by -# generate-build-vars.sh for purposes of getting around -# the dependency our build has on the .git folder, which is -# not copied to the nix store when building. -# Branch should match the branch you're building on, so -# changes to this file should not be comitted to main. -# See the README for more details. -{ - gitBranch = "main"; -} diff --git a/nix/default.nix b/nix/default.nix index c80348c2b987d..5f07c26ee14dd 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,6 +1,4 @@ -{ self, nixpkgs, system }: -let buildVars = import ./build-vars.nix; -in +{ self }: { overlay = final: prev: let @@ -23,9 +21,9 @@ in imageTag = if (self ? rev) then - "${buildVars.gitBranch}-${imageTagVersion}" + "${imageTagVersion}" else - "${buildVars.gitBranch}-${imageTagVersion}-WIP"; + "${imageTagVersion}-WIP"; loki-helm-test = prev.callPackage ../production/helm/loki/src/helm-test { inherit (prev) pkgs lib buildGoModule dockerTools; @@ -37,7 +35,6 @@ in loki = prev.callPackage ./loki.nix { inherit imageTag; - inherit (buildVars) gitBranch; version = shortGitRevsion; pkgs = prev; }; diff --git a/nix/generate-build-vars.sh b/nix/generate-build-vars.sh deleted file mode 100755 index ee13e59127246..0000000000000 --- a/nix/generate-build-vars.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -current_dir=$(cd "$(dirname "$0")" && pwd) -root_dir=$(cd "${current_dir}/.." && pwd) - -pushd "${root_dir}" >/dev/null || exit 1 -cat <"${current_dir}/build-vars.nix" -# DO NOT EDIT, this file is auto-generated by -# generate-build-vars.sh for purposes of getting around -# the dependency our build has on the .git folder, which is -# not copied to the nix store when building. -# Branch should match the branch you're building on, so -# changes to this file should not be comitted to main. -# See the README for more details. -{ - gitBranch = "$(git rev-parse --abbrev-ref HEAD)"; -} -NIX -popd >/dev/null || exit 1 diff --git a/nix/loki.nix b/nix/loki.nix index b896f7ea81a0f..d238c673cdc88 100644 --- a/nix/loki.nix +++ b/nix/loki.nix @@ -1,4 +1,4 @@ -{ pkgs, version, imageTag, gitBranch }: +{ pkgs, version, imageTag }: pkgs.stdenv.mkDerivation { inherit version; @@ -29,7 +29,7 @@ pkgs.stdenv.mkDerivation { --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 := ${gitBranch}" \ + --replace "GIT_BRANCH := \$(shell git rev-parse --abbrev-ref HEAD)" "GIT_BRANCH := nix" \ ''; buildPhase = ''