Hledger: explore snap for gnu/linux packaging

Created on 27 Jul 2017  路  9Comments  路  Source: simonmichael/hledger

All 9 comments

I dropped this, help welcome. I was using this config in .../hledger/snap/snapcraft.yaml:

#https://snapcraft.io/docs/build-snaps/your-first-snap                                                                                                                                                                                        
name: hledger # you probably want to 'snapcraft register <name>'                                                                                                                                                                              
version: '1.3+git' # just for humans, typically '1.2+git' or '1.3.2'                                                                                                                                                                          
summary: cross-platform tools for easily tracking money & time with plain text                                                                                                                                                                
description: |                                                                                                                                                                                                                                
  hledger is a cross-platform program for tracking money, time, or                                                                                                                                                                            
  any other commodity, using double-entry accounting and a simple,                                                                                                                                                                            
  editable file format                                                                                                                                                                                                                        

grade: stable # must be 'stable' to release into candidate/stable channels                                                                                                                                                                    
confinement: devmode # use 'strict' once you have the right plugs and slots                                                                                                                                                                   

apps:                                                                                                                                                                                                                                         
  hledger:                                                                                                                                                                                                                                    
    command: hledger                                                                                                                                                                                                                          

parts:                                                                                                                                                                                                                                        
  hledger:                                                                                                                                                                                                                                    
    plugin: make                                                                                                                                                                                                                              

As an aside, I would also recommend considering using nix for packaging. It has decent support on macOS and good support on Linuxy systems: https://nixos.org/nix/.
For applications with lots of compile time dependencies, I've found it really quick to get up and running with a simple nix-env --install mypackage.
...
And I just read #613. So perhaps it would require more tinkering.

Related:
https://groups.google.com/d/topic/hledger/M30a4OHy8mw/discussion
https://forum.snapcraft.io/t/help-with-snap-for-hledger/9120
How to Snap your Awesome Haskell App
The paste:

root@hledger:~# cat snaps/hledger/snap/snapcraft.yaml
name: hledger
version: '1.11.1'
summary: An command-line based accounting program.
type: app
description: |
    hledger is an accounting program, for tracking money, time, or other commodities. 
    With simple yet powerful functionality accessed from command line, terminal or web browser, hledger is a fast, secure, dependable alternative to spreadsheets, Quickbooks, GnuCash, Xero etc.


grade: stable
confinement: strict

apps:
   hledger:
    command: env LC_ALL=C.UTF-8 ${SNAP}/bin/hledger
    plugs: [home]


parts:
  hledger:
    source: .
    plugin: nil
    build-packages: []
    stage-packages: []
    build-attributes: 
      - no-system-libraries
    prepare: |
    build: |
    install: |
      export _HLEDGER_VERSION=$SNAPCRAFT_PROJECT_NAME-$SNAPCRAFT_PROJECT_VERSION
      wget https://github.com/simonmichael/hledger/releases/tag/$_HLEDGER_VERSION.tar.gz
      tar -zxvf $_HLEDGER_VERSION.tar.gz
      mkdir -p $SNAPCRAFT_PART_INSTALL/usr/
      cd $_HLEDGER_VERSION/
      cp -RP . $SNAPCRAFT_PART_INSTALL/usr/
    prime:
      - -home/*

I would like it if hledger had snap packaging: my distro's regular packaging system is a few versions behind (1.2 at time of writing).

Apologies in advance for my ignorance: I'm still learning Haskell and don't know a whole lot about how to build / run anything except small example files from the Haskell documentation, so I don't know where I'd put a snapcraft.yaml file in the hledger repo, so I'm not sure how to turn this into a pull request.

This is also my first time working with a packaging system like Snap; but my understanding is that the maintainer (i.e.: @simonmichael ) should be the one to register the snap for hledger.

Nonetheless, I tested generating a local Snap package using the snapcraft.yaml from @simonmichael's comment on 2018-12-23 and the aforementioned article on creating snaps for Haskell projects.

@simonmichael's file from 2018-12-23 failed because Github has changed where you download the tarball and the name of the folder it produces; but both items were easily corrected (I will include my changed snapcraft.yaml file below).

Once I fixed the download location and where the cd command tries to go in the install script, it successfully built a .snap file, which I could successfully install; and I got an hledger command at /snap/bin; but it linked to ${SNAP}/bin/hledger, which doesn't exist.

Given the lack of stack and cabal commands in the snapcraft.yaml I think that means that the binary hasn't been built; this just packages up the source code. I'll see if I can figure out a way to fix this.

In the meantime, here's how I set up my environment...

  1. Install Virtualbox
  2. Install Ubuntu Server 18.10 "Cosmic Cuttlefish" in a virtual machine with the default options. On install, I created the user mparker17 which appears in the usermod line below.
  3. Run the following commands to generate a snap:

    sudo apt update
    sudo apt upgrade
    mkdir -p $HOME/my-snap-builds/hledger/snap
    sudo apt install snapcraft lxd lxd-client # chose 3.0 option
    sudo usermod -a -G lxd mparker17
    sudo lxd init
    cd $HOME/my-snap-builds/hledger
    snapcraft init
    # Wrote $HOME/my-snap-builds/hledger/snap/snapcraft.yml - see below
    snapcraft cleanbuild
    snapcraft clean hledger -s pull
    snapcraft --debug
    sudo snap install --devmode hledger_1.12.1_amd64.snap
    

... and here's my snapcraft.yaml:

name: 'hledger'
version: '1.12.1'
summary: 'A command-line based accounting program.'
type: 'app'
description: |
    hledger is an accounting program, for tracking money, time, or other
    commodities. With simple yet powerful functionality accessed from command 
    line, terminal or web browser, hledger is a fast, secure, dependable 
    alternative to spreadsheets, Quickbooks, GnuCash, Xero etc.

grade: 'stable'
confinement: 'strict'

apps:
   hledger:
    command: 'env LC_ALL=C.UTF-8 ${SNAP}/bin/hledger'
    plugs: ['home']

parts:
  hledger:
    source: .
    plugin: nil
    build-packages: []
    stage-packages: []
    build-attributes:
      - no-system-libraries
    prepare: |
    build: |
    install: |
      export _HLEDGER_VERSION=$SNAPCRAFT_PROJECT_NAME-$SNAPCRAFT_PROJECT_VERSION
      wget https://github.com/simonmichael/hledger/archive/$_HLEDGER_VERSION.tar.gz
      tar -zxvf $_HLEDGER_VERSION.tar.gz
      mkdir -p $SNAPCRAFT_PART_INSTALL/usr/
      cd hledger-$_HLEDGER_VERSION/
      cp -RP . $SNAPCRAFT_PART_INSTALL/usr/
    prime:
      - -home/*

A couple of follow-up notes:

  1. I got the process wrong: cleanbuild will generate the .snap file. So all you have to do after setting up the snapcraft.yaml file is:
snapcraft cleanbuild --debug
sudo snap install --devmode hledger_1.12.1_amd64.snap
  1. The prepare, build, and install scriptlets all appear to be deprecated (deprecation notices dn7, dn8, and dn9 respectively) in favor of a override-build scriptlet.
  2. An updated snapcraft.yaml that seems to start compiling hledger (although I got bored and cancelled after a few hours) is:
name: 'hledger'
version: '1.12.1'
summary: 'A command-line based accounting program.'
type: 'app'
description: |
    hledger is an accounting program, for tracking money, time, or other
    commodities. With simple yet powerful functionality accessed from command 
    line, terminal or web browser, hledger is a fast, secure, dependable 
    alternative to spreadsheets, Quickbooks, GnuCash, Xero etc.

grade: 'stable'
confinement: 'strict'

apps:
   hledger:
    command: 'env LC_ALL=C.UTF-8 ${SNAP}/bin/hledger'
    plugs: ['home']
parts:
  hledger:
    source: '.'
    plugin: 'nil'
    build-packages: []
    stage-packages: []
    build-attributes:
      - 'no-system-libraries'
    override-build:
      export _HLEDGER_VERSION=$SNAPCRAFT_PROJECT_NAME-$SNAPCRAFT_PROJECT_VERSION
      wget https://github.com/simonmichael/hledger/archive/$_HLEDGER_VERSION.tar.gz
      tar -zxvf $_HLEDGER_VERSION.tar.gz
      mkdir -p $SNAPCRAFT_PART_INSTALL/usr/
      cd hledger-$_HLEDGER_VERSION/
      wget -qO- https://get.haskellstack.org/ | sh
      stack build
      cp -RP . $SNAPCRAFT_PART_INSTALL/usr/
    prime:
      - '-home/*'

Thanks for working on this @mparker17. It's probably a good idea to find another haskell project that has been snap-packaged. I think pandoc, xmonad, postgrest, elm, purescript, stack, cabal, ghc are possibilities.

At least, there are a few projects at https://snapcraft.io/search?category=&q=haskell

snapcraft.yaml, snapcraft.yaml - these ones download a binary released on github I think.

I'm going to be looking into this! I asked for advise on #snapcraft if they have any example.

Was this page helpful?
0 / 5 - 0 ratings