Skip to content
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 flake for easier build support #694

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ build/mgmt-*
mgmt.iml
rpmbuild/
releases/
result
# vim swap files
.*.sw[op]
# prevent `echo foo 2>1` typo errors by making this file read-only
Expand Down
43 changes: 43 additions & 0 deletions flake.lock

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

58 changes: 58 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
description = "Next generation distributed, event-driven, parallel config management!";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:urandom2/nixpkgs/mgmt";
};
outputs = {
flake-utils,
nixpkgs,
self,
}:
flake-utils.lib.eachDefaultSystem (system: let
buildInputs = with pkgs; [
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are dependencies that are linked against, think shared libraries

augeas
libvirt
libxml2
];
nativeBuildInputs = with pkgs; [
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are dependencies that are called during the build process explicitly

gotools
nex
pkg-config
ragel
];
pkgs = nixpkgs.legacyPackages.${system};
in {
devShells.default = pkgs.mkShell {
inherit buildInputs nativeBuildInputs;
packages = [pkgs.go];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is anything I missed that is useful for testing/debugging/development, we should add it here

};
packages.default = let
pname = "mgmt";
version = "0.0.22";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately, flakes cannot consume version strings from vcs, so you will be required to manually update the string before releases, or just leave the flake as something like unstable-20221107155054 like so:

Suggested change
version = "0.0.22";
version = "unstable-${self.lastModifiedDate}";

in
pkgs.buildGoModule {
inherit pname version buildInputs nativeBuildInputs;
ldflags = [
"-X main.program=${pname}"
"-X main.version=${version}"
];
meta = {
description = "Next generation distributed, event-driven, parallel config management!";
homepage = "https://mgmtconfig.com";
license = pkgs.lib.licenses.gpl3;
};
preBuild = ''
substituteInPlace Makefile --replace "/usr/bin/env " ""
substituteInPlace lang/Makefile --replace "/usr/bin/env " ""
substituteInPlace lang/types/Makefile --replace "/usr/bin/env " ""
Comment on lines +46 to +48
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these execute the same change I would suggest: use SHELL = bash and allow make to do PATH based resolution, as this will be more portable than assuming everybody has a /usr/bin/env

substituteInPlace lang/types/Makefile --replace "unset GOCACHE &&" ""
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the linked upstream bug, golang/go#31843, and it is both stale/closed, and I could not trigger it during testing; can we consider it resolved and remove the override?

patchShebangs .
make lang funcgen
'';
src = ./.;
subPackages = ["."];
vendorHash = "sha256-Dtqy4TILN+7JXiHKHDdjzRTsT8jZYG5sPudxhd8znXY=";
};
});
}