From c887056d32aaae8d8c73bbeae647554bbe71b1dc Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Sun, 17 Jul 2022 07:41:42 +0800 Subject: [PATCH 1/7] chore: gitignore result/ --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2be92b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result From 2fa5cd8cca4b0863b5b436d12ce2c82833df7720 Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Sun, 17 Jul 2022 07:42:13 +0800 Subject: [PATCH 2/7] chore(build): use callCabal2nix* instead of deback.nix --- README.md | 11 ----------- deback.nix | 17 ----------------- default.nix | 3 +-- release.sh | 5 +---- shell.nix | 2 +- static.nix | 2 +- 6 files changed, 4 insertions(+), 36 deletions(-) delete mode 100644 deback.nix diff --git a/README.md b/README.md index 8cd6034..ebb229a 100644 --- a/README.md +++ b/README.md @@ -99,14 +99,3 @@ nix-env -f default.nix -i ```sh nix-env -f https://github.com/telostat/deback/archive/main.tar.gz -i ``` - -[./default.nix](./default.nix), [./shell.nix](./shell.nix) and -[./static.nix](./static.nix) depend on [./deback.nix](./deback.nix). - -If Haskell dependencies are updated or the application version has changed in -[./deback.cabal](./deback.cabal) file, you must update -[./deback.nix](./deback.nix) as well: - -```sh -cabal2nix --no-haddock . > deback.nix -``` diff --git a/deback.nix b/deback.nix deleted file mode 100644 index 753f4b9..0000000 --- a/deback.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ mkDerivation, aeson, ansi-terminal, base, bytestring, lib -, optparse-applicative, table-layout, text, typed-process -}: -mkDerivation { - pname = "deback"; - version = "0.0.2"; - src = ./.; - isLibrary = false; - isExecutable = true; - executableHaskellDepends = [ - aeson ansi-terminal base bytestring optparse-applicative - table-layout text typed-process - ]; - doHaddock = false; - license = "unknown"; - hydraPlatforms = lib.platforms.none; -} diff --git a/default.nix b/default.nix index 1d06560..b24e0ad 100644 --- a/default.nix +++ b/default.nix @@ -12,12 +12,11 @@ let ## Import rrclone: rrclone = import sources.rrclone; - ## Get the haskell set: haskell = pkgs.haskell.packages.${compiler}; ## Get deback: - deback = haskell.callPackage (import ./deback.nix) { }; + deback = haskell.callCabal2nixWithOptions "deback" ./. "--no-haddock" { }; ## Get installable deback: installableDeback = deback.overrideAttrs (oldAttrs: rec { diff --git a/release.sh b/release.sh index dfb76b5..c87862c 100644 --- a/release.sh +++ b/release.sh @@ -31,14 +31,11 @@ fi ## Update version: sed -i -E "s/^version:([ ]+).*/version:\\1${_VERSION_NEXT}/g" deback.cabal -## Regenerate deback.nix: -cabal2nix --no-haddock . > deback.nix - ## Update CHANGELOG.md: git-chglog -o CHANGELOG.md --next-tag "v${_VERSION_NEXT}" ## Add files: -git add deback.cabal deback.nix CHANGELOG.md +git add deback.cabal CHANGELOG.md ## Commit: git commit -m "chore(release): v${_VERSION_NEXT}" diff --git a/shell.nix b/shell.nix index 0255a58..95ffdec 100644 --- a/shell.nix +++ b/shell.nix @@ -16,7 +16,7 @@ let haskell = pkgs.haskell.packages.${compiler}; ## Get deback: - deback = haskell.callPackage (import ./deback.nix) { }; + deback = haskell.callCabal2nixWithOptions "deback" ./. "--no-haddock" { }; ## Get deback Haskell dependencies: debackDeps = pkgs.haskell.lib.compose.getHaskellBuildInputs deback; diff --git a/static.nix b/static.nix index 07c6c95..dc9400a 100644 --- a/static.nix +++ b/static.nix @@ -13,7 +13,7 @@ let haskell = pkgs.haskell.packages.${compiler}; ## Get deback: - deback = haskell.callPackage (import ./deback.nix) { }; + deback = haskell.callCabal2nixWithOptions "deback" ./. "--no-haddock" { }; ## Override stuff: staticDeback = pkgs.haskell.lib.compose.overrideCabal From 149a736b6201550c2e4598a1a810c6f8cf164870 Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Sun, 17 Jul 2022 08:06:59 +0800 Subject: [PATCH 3/7] chore(build): parameterize default.nix for static builds This way, we no longer need static.nix. --- README.md | 8 ++++---- default.nix | 27 ++++++++++++++++++++++----- release.sh | 2 +- static.nix | 34 ---------------------------------- 4 files changed, 27 insertions(+), 44 deletions(-) delete mode 100644 static.nix diff --git a/README.md b/README.md index ebb229a..328f6ee 100644 --- a/README.md +++ b/README.md @@ -74,10 +74,10 @@ Development takes place in a Nix shell ([./shell.nix](./shell.nix)): nix-shell ``` -Static builds can be obtained using [./static.nix](./static.nix): +Static builds can be obtained via: ```sh -nix-build static.nix +nix-build --arg doStatic true file result/bin/deback ``` @@ -87,8 +87,8 @@ In this case, all runtime dependencies ([rclone](https://rclone.org/), [smartmontools](https://www.smartmontools.org/) etc.) must be installed on the host and be on the `PATH` when running `deback`. -If you are on Nix, use [./default.nix](./default.nix) to install the application -(all its runtime dependencies will be automatically installed) via: +If you are on Nix, install the application (all its runtime dependencies will be +automatically installed) via: ```sh nix-env -f default.nix -i diff --git a/default.nix b/default.nix index b24e0ad..79d2cef 100644 --- a/default.nix +++ b/default.nix @@ -1,4 +1,5 @@ { compiler ? "ghc922" +, doStatic ? false , ... }: @@ -15,11 +16,24 @@ let ## Get the haskell set: haskell = pkgs.haskell.packages.${compiler}; - ## Get deback: - deback = haskell.callCabal2nixWithOptions "deback" ./. "--no-haddock" { }; + ## Define a function that makes deback statically compiled: + makeDebackStatic = drv: pkgs.haskell.lib.compose.overrideCabal + (_: { + enableSharedExecutables = false; + enableSharedLibraries = false; + configureFlags = [ + "--ghc-option=-optl=-static" + "--ghc-option=-optl=-pthread" + "--ghc-option=-optl=-L${pkgs.gmp6.override { withStatic = true; }}/lib" + "--ghc-option=-optl=-L${pkgs.zlib.static}/lib" + "--ghc-option=-optl=-L${pkgs.glibc.static}/lib" + "--extra-lib-dirs=${pkgs.libffi.overrideAttrs (old: { dontDisableStatic = true; })}/lib" + ]; + }) + drv; - ## Get installable deback: - installableDeback = deback.overrideAttrs (oldAttrs: rec { + ## Define a function that makes deback installable in Nix environment with all its dependencies: + makeDebackInstallable = drv: drv.overrideAttrs (oldAttrs: rec { nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.makeWrapper ]; @@ -28,5 +42,8 @@ let wrapProgram $out/bin/deback --prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.rclone pkgs.smartmontools ]} ''; }); + + ## Get raw deback: + deback = haskell.callCabal2nixWithOptions "deback" ./. "--no-haddock" { }; in -installableDeback +if doStatic then makeDebackStatic deback else makeDebackInstallable deback diff --git a/release.sh b/release.sh index c87862c..471f8ef 100644 --- a/release.sh +++ b/release.sh @@ -47,7 +47,7 @@ git tag -a -m "Release v${_VERSION_NEXT}" "v${_VERSION_NEXT}" git push --follow-tags origin main ## Build application: -nix-build static.nix +nix-build --arg doStatic true ## Release gh release create "v${_VERSION_NEXT}" --generate-notes diff --git a/static.nix b/static.nix deleted file mode 100644 index dc9400a..0000000 --- a/static.nix +++ /dev/null @@ -1,34 +0,0 @@ -{ compiler ? "ghc922" -, ... -}: - -let - ## Import sources: - sources = import ./nix/sources.nix; - - ## Import nixpkgs: - pkgs = import sources.nixpkgs { }; - - ## Get the haskell set: - haskell = pkgs.haskell.packages.${compiler}; - - ## Get deback: - deback = haskell.callCabal2nixWithOptions "deback" ./. "--no-haddock" { }; - - ## Override stuff: - staticDeback = pkgs.haskell.lib.compose.overrideCabal - (old: { - enableSharedExecutables = false; - enableSharedLibraries = false; - configureFlags = [ - "--ghc-option=-optl=-static" - "--ghc-option=-optl=-pthread" - "--ghc-option=-optl=-L${pkgs.gmp6.override { withStatic = true; }}/lib" - "--ghc-option=-optl=-L${pkgs.zlib.static}/lib" - "--ghc-option=-optl=-L${pkgs.glibc.static}/lib" - "--extra-lib-dirs=${pkgs.libffi.overrideAttrs (old: { dontDisableStatic = true; })}/lib" - ]; - }) - deback; -in -staticDeback From b398325482abdb73d4161469091ba6137c80f707 Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Mon, 18 Jul 2022 10:25:47 +0800 Subject: [PATCH 4/7] fix: add rrclone to PATH on Nix installation --- default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default.nix b/default.nix index 79d2cef..42cc26c 100644 --- a/default.nix +++ b/default.nix @@ -39,7 +39,7 @@ let ]; postFixup = (oldAttrs.postFixup or "") + '' - wrapProgram $out/bin/deback --prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.rclone pkgs.smartmontools ]} + wrapProgram $out/bin/deback --prefix PATH : ${pkgs.lib.makeBinPath [ rrclone pkgs.rclone pkgs.smartmontools ]} ''; }); From 17c202d3f8d3d7ba28ac05978583444b83c72ad5 Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Mon, 18 Jul 2022 11:05:01 +0800 Subject: [PATCH 5/7] chore: update package metadata, add LICENSE --- LICENSE | 22 ++++++++++++++++++++++ deback.cabal | 24 +++++++++--------------- 2 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..50f8547 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2022 Telostat Pte Ltd + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/deback.cabal b/deback.cabal index d02c18c..b0d61cf 100644 --- a/deback.cabal +++ b/deback.cabal @@ -1,24 +1,18 @@ cabal-version: 2.4 name: deback version: 0.0.2 - --- A short (one-line) description of the package. --- synopsis: - --- A longer description of the package. --- description: - --- A URL where users can report bugs. --- bug-reports: - --- The license under which the package is released. --- license: +synopsis: An opinionated backup and archive tool +description: Please see the README on GitHub at +homepage: https://github.com/telostat/deback#readme +bug-reports: https://github.com/telostat/deback/issues author: Vehbi Sinan Tunalioglu maintainer: vst@vsthost.com +copyright: 2022 Teloscube Pte Ltd +license: MIT +license-file: LICENSE +category: System, Backup +build-type: Simple --- A copyright notice. --- copyright: --- category: extra-source-files: CHANGELOG.md README.md From b9f3cd6231015d7bdfe3c82468fe5a00e16ad5e4 Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Mon, 18 Jul 2022 11:08:28 +0800 Subject: [PATCH 6/7] chore(docs): update README --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 328f6ee..45f9bfc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,14 @@ # deback +![GitHub release (latest by date)](https://img.shields.io/github/v/release/telostat/deback) +![GitHub contributors](https://img.shields.io/github/contributors/telostat/deback) +![GitHub](https://img.shields.io/github/license/telostat/deback) + +> **Note:** This software is under development and of prototype quality at the +> moment. Expect significant breaking changes without notification until we +> reach the first minor version. Until then, we will keep bumping the patch +> version. + Backups are hard, but we need to do it right for business continuity and sanity. @@ -99,3 +108,19 @@ nix-env -f default.nix -i ```sh nix-env -f https://github.com/telostat/deback/archive/main.tar.gz -i ``` + +## Releasing + +Here is the release process: + +```sh +git checkout develop +git pull +git checkout main +git pull +git merge --no-ff develop +bash release.sh -n +git checkout develop +git rebase main +git push +``` From 9ed68dccb57a17804daebe4a325f52c7afa57b02 Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Mon, 18 Jul 2022 11:21:32 +0800 Subject: [PATCH 7/7] chore(build): improve release artifact 1. Rename properly 2. Compress binary --- release.sh | 14 +++++++++++++- shell.nix | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/release.sh b/release.sh index 471f8ef..f19b897 100644 --- a/release.sh +++ b/release.sh @@ -49,6 +49,18 @@ git push --follow-tags origin main ## Build application: nix-build --arg doStatic true +## Get compiled output file path: +_infile="result/bin/deback" + +## Get compressed, renamed output file path: +_outfile="deback-v${_VERSION_NEXT}-$(uname -s)-$(uname -m)-static" + +## Compress file: +upx -o "${_outfile}" "${_infile}" + ## Release gh release create "v${_VERSION_NEXT}" --generate-notes -gh release upload "v${_VERSION_NEXT}" result/bin/deback +gh release upload "v${_VERSION_NEXT}" "${_outfile}" + +## Remove outfile: +rm "${_outfile}" diff --git a/shell.nix b/shell.nix index 95ffdec..875c3c3 100644 --- a/shell.nix +++ b/shell.nix @@ -31,9 +31,11 @@ pkgs.mkShell { pkgs.lolcat ## Release stuff: + pkgs.busybox pkgs.gh pkgs.git pkgs.git-chglog + pkgs.upx ## Haskell stuff: ghc