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

explore snap for gnu/linux packaging #595

Closed
simonmichael opened this issue Jul 27, 2017 · 12 comments
Closed

explore snap for gnu/linux packaging #595

simonmichael opened this issue Jul 27, 2017 · 12 comments
Labels
A-WISH Some kind of improvement request, hare-brained proposal, or plea. packaging Dependencies, version constraints, packaging.. platform:linux

Comments

@simonmichael
Copy link
Owner

simonmichael commented Jul 27, 2017

https://snapcraft.io
https://snapcraft.io/docs/build-snaps/your-first-snap
https://snapcraft.io/docs/reference/plugins/


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@simonmichael simonmichael added A-WISH Some kind of improvement request, hare-brained proposal, or plea. packaging Dependencies, version constraints, packaging.. platform:linux labels Jul 27, 2017
@simonmichael
Copy link
Owner Author

simonmichael commented Oct 16, 2017

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                                                                                                                                                                                                                              

@simonmichael simonmichael added good-first-issue If you're a new contributor, this might be a good one for you. help wanted labels Oct 16, 2017
@ghost
Copy link

ghost commented Dec 7, 2017

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.

@simonmichael
Copy link
Owner Author

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/*

@mparker17
Copy link
Contributor

mparker17 commented Dec 29, 2018

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/*

@mparker17
Copy link
Contributor

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/*'

@simonmichael
Copy link
Owner Author

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.

@simonmichael
Copy link
Owner Author

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

@simonmichael
Copy link
Owner Author

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

@julian-klode
Copy link

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

julian-klode added a commit to julian-klode/hledger that referenced this issue Feb 5, 2020
@simonmichael simonmichael removed the good-first-issue If you're a new contributor, this might be a good one for you. label Apr 27, 2023
@simonmichael
Copy link
Owner Author

We explored it. If anyone wants to package hledger as snaps, that is welcome.

@julian-klode
Copy link

julian-klode commented Apr 27, 2023

I forgot to follow up, sorry, I wrote the initial snap in 2021 @ julian-klode@ebea47a but never finished it, it's published in the snap store as hledger-jak for testing, but also I never updated it.

I guess it works fine enough ,it just manages your journal in

$HOME/snap/hledger//.hledger.journal

and doesn't have write access to $HOME directly, or the permission to create sockets for hledger web yet.

@simonmichael
Copy link
Owner Author

Thanks @julian-klode. I guess we won't add it to the Install page unless it's maintained, tested, people asking for it etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-WISH Some kind of improvement request, hare-brained proposal, or plea. packaging Dependencies, version constraints, packaging.. platform:linux
Projects
None yet
Development

No branches or pull requests

3 participants