Skip to content

Commit

Permalink
Use gomodnix to build pistol
Browse files Browse the repository at this point in the history
  • Loading branch information
doronbehar committed Oct 20, 2021
1 parent 0c27023 commit 944a9af
Show file tree
Hide file tree
Showing 3 changed files with 396 additions and 10 deletions.
45 changes: 45 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 64 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,82 @@
url = "github:edolstra/flake-compat";
flake = false;
};
inputs.gomod2nix = {
url = "github:tweag/gomod2nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.utils.follows = "flake-utils";
};
inputs.gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};

outputs = { self
, nixpkgs
, flake-utils
, flake-compat
, gitignore
, gomod2nix
}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
pistol = pkgs.pistol.overrideAttrs(oldAttrs: rec {
version = "${builtins.readFile ./VERSION}-flake";
src = builtins.filterSource
(path: type: type != "directory" || baseNameOf path != ".git")
./.;
buildFlagsArray = [
"-ldflags=-s -w -X main.Version=${version}"
pkgs = import nixpkgs {
inherit system;
overlays = [
gomod2nix.overlay
];
});
};
inherit (gitignore.lib) gitignoreSource;
# https://discourse.nixos.org/t/passing-git-commit-hash-and-tag-to-build-with-flakes/11355/2
version_rev = if (self ? rev) then (builtins.substring 0 8 self.rev) else "dirty";
version = "${pkgs.lib.fileContents ./VERSION}-${version_rev}-flake";
pistol = pkgs.buildGoApplication {
pname = "pistol";
inherit version;
src = pkgs.lib.cleanSourceWith {
# Ignore many files that gitignoreSource doesn't ignore, see:
# https://github.com/hercules-ci/gitignore.nix/issues/9#issuecomment-635458762
filter = path: type:
! (builtins.any (r: (builtins.match r (builtins.baseNameOf path)) != null) [
# Nix files
"flake.nix"
"flake.lock"
"default.nix"
"shell.nix"
".envrc"
# Evaluated but not used for the build itself
"gomod2nix.toml"
"VERSION"
# CI files
"renovate.json5"
# Git files
".gitignore"
".git"
])
;
src = gitignoreSource ./.;
};
buildFlagsArray = ''
-ldflags=
-X main.Version=${version}
'';
modules = ./gomod2nix.toml;
inherit (pkgs.pistol)
nativeBuildInputs
buildInputs
subPackages
postBuild
meta
;
CGO_ENABLED = 1;
};
in rec {
devShell = pkgs.mkShell {
buildInputs = pistol.buildInputs ++ [
inherit (pistol) buildInputs;
nativeBuildInputs = pistol.nativeBuildInputs ++ [
# For make check
pkgs.elinks
pkgs.gomod2nix
];
};
packages.pistol = pistol;
Expand Down
Loading

0 comments on commit 944a9af

Please sign in to comment.