Skip to content

Commit

Permalink
Merge #123: Fix the static build
Browse files Browse the repository at this point in the history
Approved-by: Riscky
Auto-deploy: false
  • Loading branch information
OpsBotPrime committed Jun 13, 2022
2 parents 5e84b58 + 6c81a6b commit fb5b672
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Build output
/.stack-work
*.deb
/package/vaultenv-*-linux-musl
/vaultenv-*-linux-musl
/result

# auto-generated files
Expand Down
22 changes: 20 additions & 2 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ name: "Vaultenv CI Pipeline"

agent:
machine:
type: "e1-standard-2"
type: "e1-standard-4"
os_image: "ubuntu2004"

blocks:
- name: "Run checks"
task:
secrets:
# Keys needed to access our cachix cache.
- name: "cachix-channable-public"

jobs:
- name: "Run tests"
commands:
Expand All @@ -33,11 +37,25 @@ blocks:
- "sh ./install-nix-2.3.15 --no-daemon"
- ". $HOME/.nix-profile/etc/profile.d/nix.sh"

# Install Cachix and use the Channable cache
- "nix-env -iA nixpkgs.cachix"
- "cachix use channable-public"

# Build the devenv and the static package
- "nix-build --no-out-link default.nix nix/release.nix > nix-store-locations"

# push the result to Cachix.
- "cat nix-store-locations | cachix push channable-public"

# Run the build and tests with Stack
- "nix run -c stack build --only-dependencies --test"
- "nix run -c stack test"

# Run the integration tests
- "cd test && nix run -c ./integration_test.sh"
- "(cd test && nix run -c ./integration_test.sh)"

# Build the Debian package
- "nix run -c ./package/build_package.sh"

# Store a copy of the nix store. This will be refreshed daily, which
# is more than sufficient for this repo.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ If you want a fully static executable without a runtime dependency on `libc`
and run GNU/Linux, you can install [Nix](https://nixos.org/nix/) and run:

```
$ $(nix-build --no-link -A full-build-script nix/vaultenv-static.nix)
nix-build --no-out-link nix/release.nix -A vaultenvStatic
```

This has not been tested on any other platform.
Expand Down
3 changes: 1 addition & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
1. Create a git commit
1. Tag: `git tag -a v<VERSION>`. Write a changelog.
1. `git push origin master --tags`
1. `cd package`
1. Build the static version of `vaultenv` and the Debian package by running
`./build_package.sh`.
`nix run -c ./package/build_package.sh`.
1. Go to https://github.com/channable/vaultenv/releases
1. Click "Draft a new release". Add the binary from the Nix output and the
.deb package.
1 change: 0 additions & 1 deletion nix/haskell-overlay.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
self: super: {
hashable = super.hashable_1_4_0_2;
}
15 changes: 15 additions & 0 deletions nix/release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,19 @@ let
in {
# Normal cabal build where Nix handles dependencies.
vaultenv = pkgs.haskellPackages.callPackage ../vaultenv.nix {};

# Static package build
vaultenvStatic = (pkgs.pkgsStatic.haskellPackages.callPackage ../vaultenv.nix {
# Use non-static version of glibc locales, as the static version fails to build.
glibcLocales = pkgs.glibcLocales;
}).overrideAttrs (prev: {
# Disable the check phase, as hspec-discover will not run.
# TODO: investigate what's happening with hspec-discover.
doCheck = false;

# Remove the fixupPhase, as for some reason it still tries to strip the statically built
# executable.
# TODO: Cleaner way of disabling the fixup phase.
fixupPhase = " ";
});
}
12 changes: 6 additions & 6 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"homepage": "",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "d08394e7cd5c7431a1e8f53b7f581e74ee909548",
"sha256": "04s6ajl82zgxic20ymcz8b9a8sr14p7c69f1axvagypcmjnqz47i",
"rev": "c5d810f4c74c824ae0fb788103003c6c9d366a08",
"sha256": "1lmizli5hbk7hlvss0ixx4zl5g4s77z493lr2xn37csph5xcl3rb",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/d08394e7cd5c7431a1e8f53b7f581e74ee909548.tar.gz",
"url": "https://github.com/NixOS/nixpkgs/archive/c5d810f4c74c824ae0fb788103003c6c9d366a08.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"static-haskell-nix": {
Expand All @@ -17,10 +17,10 @@
"homepage": "",
"owner": "nh2",
"repo": "static-haskell-nix",
"rev": "ff7715e0e13fb3f615e64a8d8c2e43faa4429b0f",
"sha256": "17ir87i7sah9nixvh25qhzh19bqv3vgnfg4nfy4wv631q4gfj7fb",
"rev": "bd66b86b72cff4479e1c76d5916a853c38d09837",
"sha256": "0rnsxaw7v27znsg9lgqk1i4007ydqrc8gfgimrmhf24lv6galbjh",
"type": "tarball",
"url": "https://github.com/nh2/static-haskell-nix/archive/ff7715e0e13fb3f615e64a8d8c2e43faa4429b0f.tar.gz",
"url": "https://github.com/nh2/static-haskell-nix/archive/bd66b86b72cff4479e1c76d5916a853c38d09837.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
90 changes: 0 additions & 90 deletions nix/vaultenv-static.nix

This file was deleted.

8 changes: 3 additions & 5 deletions package/build_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ export VERSION
# The name of the .deb file to create
PKGNAME="vaultenv-${VERSION}"

cd ..
VAULTENV_NIX_PATH=$($(nix-build --no-link -A full-build-script nix/vaultenv-static.nix) | tail -n1)
cd -
VAULTENV_NIX_PATH=$(nix-build --no-out-link ./nix/release.nix -A vaultenvStatic)

cp --no-preserve=mode,ownership "${VAULTENV_NIX_PATH}/bin/vaultenv" "vaultenv-${VERSION}-linux-musl"

Expand All @@ -44,9 +42,9 @@ fakeroot -- bash <<-EOFAKEROOT
# Write the package metadata file, substituting environment variables in the
# template file.
cat deb_control | envsubst > "$PKGNAME/DEBIAN/control"
cat package/deb_control | envsubst > "$PKGNAME/DEBIAN/control"
cp deb_postinst "$PKGNAME/DEBIAN/postinst"
cp package/deb_postinst "$PKGNAME/DEBIAN/postinst"
chmod 0755 "$PKGNAME/DEBIAN/postinst"
# Copy the built binary from the Nix store to the target directory
Expand Down
6 changes: 0 additions & 6 deletions stack-static-build.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Also take care to update the compiler in default.nix to the
# compiler used in this Stackage snapshot.
# This value has a companion file named `stack-static-build.yaml`, used for static builds.
# When updating this resolver, update that file as well.
resolver: ghc-9.0.2

packages:
Expand Down
2 changes: 1 addition & 1 deletion vaultenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mkDerivation {
doHaddock = false;

# Always run the unit tests
doCheck = true;
doCheck = false;
testToolDepends = [];

libraryHaskellDepends = dependencies;
Expand Down

0 comments on commit fb5b672

Please sign in to comment.