diff --git a/Makefile b/Makefile index 773832e8..b95bacfc 100644 --- a/Makefile +++ b/Makefile @@ -88,6 +88,7 @@ help: @echo @echo " * 'install' - Install binaries and documents to system locations" @echo " * 'binary' - Build skopeo with a container" + @echo " * 'static' - Build statically linked binary" @echo " * 'bin/skopeo' - Build skopeo locally" @echo " * 'test-unit' - Execute unit tests" @echo " * 'test-integration' - Execute integration tests" @@ -103,12 +104,19 @@ binary: cmd/skopeo ${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd):/src/github.com/containers/skopeo \ skopeobuildimage make bin/skopeo $(if $(DEBUG),DEBUG=$(DEBUG)) BUILDTAGS='$(BUILDTAGS)' -# Update nix/nixpkgs.json its latest master commit +# Update nix/nixpkgs.json its latest stable commit .PHONY: nixpkgs nixpkgs: @nix run -f channel:nixos-20.03 nix-prefetch-git -c nix-prefetch-git \ --no-deepClone https://github.com/nixos/nixpkgs > nix/nixpkgs.json +# Build statically linked binary +.PHONY: static +static: + @nix build -f nix/ + mkdir -p ./bin + cp -rfp ./result/bin/* ./bin/ + # Build w/o using containers .PHONY: bin/skopeo bin/skopeo: diff --git a/nix/default.nix b/nix/default.nix index 0f2674f8..56933170 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -6,6 +6,16 @@ let gpgme = (static pkg.gpgme); libassuan = (static pkg.libassuan); libgpgerror = (static pkg.libgpgerror); + libseccomp = (static pkg.libseccomp); + glib = (static pkg.glib).overrideAttrs(x: { + outputs = [ "bin" "out" "dev" ]; + mesonFlags = [ + "-Ddefault_library=static" + "-Ddevbindir=${placeholder ''dev''}/bin" + "-Dgtk_doc=false" + "-Dnls=disabled" + ]; + }); }; }; }); @@ -21,14 +31,15 @@ let enableStatic = true; }); - self = with pkgs; buildGoPackage rec { + self = with pkgs; buildGoModule rec { name = "skopeo"; src = ./..; - goPackagePath = "github.com/containers/skopeo"; + vendorSha256 = null; doCheck = false; enableParallelBuilding = true; - nativeBuildInputs = [ git go-md2man installShellFiles makeWrapper pkg-config ]; - buildInputs = [ glibc glibc.static gpgme libassuan libgpgerror ]; + outputs = [ "out" ]; + nativeBuildInputs = [ bash git go-md2man installShellFiles makeWrapper pkg-config which ]; + buildInputs = [ glibc glibc.static gpgme libassuan libgpgerror libseccomp ]; prePatch = '' export CFLAGS='-static' export LDFLAGS='-s -w -static-libgcc -static' @@ -36,7 +47,6 @@ let export BUILDTAGS='static netgo exclude_graphdriver_btrfs exclude_graphdriver_devicemapper' ''; buildPhase = '' - pushd go/src/${goPackagePath} patchShebangs . make bin/skopeo ''; diff --git a/nix/nixpkgs.json b/nix/nixpkgs.json index 8684073c..976284ed 100644 --- a/nix/nixpkgs.json +++ b/nix/nixpkgs.json @@ -1,7 +1,7 @@ { "url": "https://github.com/nixos/nixpkgs", - "rev": "87c5724af9f61be5e77034229078960690c1abe2", - "date": "2020-06-28T22:14:24+01:00", - "sha256": "1vg6iajb945b33nx674nnask6wai8zkjd4m0i9fcpdkwhwr0s46s", + "rev": "d6a445fe821052861b379d9b6c02d21623c25464", + "date": "2020-08-11T04:28:16+01:00", + "sha256": "064scwaxg8qg4xbmq07hag57saa4bhsb4pgg5h5vfs4nhhwvchg9", "fetchSubmodules": false }