goreleaser / nfpm

nFPM is Not FPM - a simple deb, rpm, apk, ipk, and arch linux packager written in Go
https://nfpm.goreleaser.com/
MIT License
2.16k stars 158 forks source link

License file is not being added to deb #847

Closed andrewlock closed 2 months ago

andrewlock commented 2 months ago

What happened?

I'm trying to migrate from fpm to nfpm, and AFAICT, the license field is being ignored.

How can we reproduce this?

configfile:

name: "my-package"
arch: "amd64"
platform: "linux"
version: "3.1.0"
maintainer: "Me <me@testing.com>"
description: "My testing package"
vendor: "Me <me@testing.com>"
homepage: "https://andrewlock.net"
license: "Apache License 2.0"
priority: extra
section: default
scripts:
    postinstall: /some/path/after-install.sh
    postremove: /some/path/after-remove.sh
contents:
- src: /home/testing/linux-x64/
  dst: /opt/me
  type: tree

Then if I run dpkg-deb --info on the output I get:

new Debian package, version 2.0.
 size 114776044 bytes: control archive=1432 bytes.
       1 bytes,     0 lines      conffiles
     274 bytes,     9 lines      control
    2851 bytes,    34 lines      md5sums
      92 bytes,     3 lines   *  postinst             #!/bin/sh
      32 bytes,     2 lines   *  postrm               #!/bin/sh
 Package: my-package
 Version: 3.1.0
 Section: default
 Priority: extra
 Architecture: amd64
 Maintainer: Me <me@testing.com>
 Installed-Size: 309626
 Homepage: https://andrewlock.net
 Description: My testing package

Note that there is no license field. And running dpkg-deb --field license similarly shows it's not set.

nfpm version

_____ ____  __  __
 _ __ |  ___|  _ \|  \/  |
| '_ \| |_  | |_) | |\/| |
| | | |  _| |  __/| |  | |
|_| |_|_|   |_|   |_|  |_|
nfpm: a simple and 0-dependencies apk, arch linux, deb, ipk, and rpm packager written in Go
https://nfpm.goreleaser.com

GitVersion:    2.38.0
GitCommit:     d33a9233bb7acf04621b78114114476196d79779
GitTreeState:  false
BuildDate:     2024-07-05T18:26:41Z
BuiltBy:       goreleaser
GoVersion:     go1.22.5
Compiler:      gc
ModuleSum:     h1:59iH9IPc6GUUk542YBMWw28R1OUEYp7yfOrBC7H+B2Q=
Platform:      linux/amd64

Search

Code of Conduct

Additional context

Thanks for this project, I would love to remove our ruby dependency! πŸ˜… I expect I'm just doing something wrong, but I've looked all through the code and can't figure it out. Thanks for your help!

caarlos0 commented 2 months ago

hey!

yeah, I think currently you have to copy the license file into the package, something like:

contents:
  - src: ./LICENSE.md
    dst: /usr/share/doc/my-package/copyright
    file_info:
      mode: 0644
andrewlock commented 2 months ago

Oh, I see, thanks for the info! With fpm we weren't doing that, just specifying the metadata a!d that was it. Thanks, I'll give it a try!

andrewlock commented 2 months ago

Hmmm, that still hasn't worked πŸ€”

If I run dpkg -c I can see the copyright file is there:

-rw-r--r-- root/root     11357 2024-03-07 11:30 ./usr/share/doc/my-package/copyright

but it's still not reported by dpkg --info or by dpkg -f my-package_3.1.0_amd64.deb license πŸ€”

Any more ideas? πŸ˜• Thanks for the help!

andrewlock commented 2 months ago

I was doing a bit more spelunking, and AFAICT, the

RPMMetaData has a license field in the metadata for example:

https://github.com/goreleaser/nfpm/blob/52e0c639c8d0675a895e47f27c35a0e1bb1242df/rpm/rpm.go#L252

The template for the debian control file has no such field:

https://github.com/goreleaser/nfpm/blob/52e0c639c8d0675a895e47f27c35a0e1bb1242df/deb/deb.go#L716

Compared to fpm which does include it:

https://github.com/jordansissel/fpm/blob/9d3d96a93d6fd667ac21fecf2f91004bfaa77142/templates/deb.erb#L3

Interestingly though, I don't see a specific mention of the License field in the debian control file spec, so I guess fpm is adding it as a "user-defined field"? πŸ€”

Based on the documentation about copyright information here, your suggestion of just adding the file seems correct, although it also says:

Packages distributed under the Apache license (version 2.0), the Artistic license, the Creative Commons CC0-1.0 license, the GNU GPL (versions 1, 2, or 3), the GNU LGPL (versions 2, 2.1, or 3), the GNU FDL (versions 1.2 or 1.3), and the Mozilla Public License (version 1.1 or 2.0) should refer to the corresponding files under /usr/share/common-licenses, 9 rather than quoting them in the copyright file.

So I think the license file should look something like this (based on examples I found):

Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Source: {{HomePage}}
Upstream-Name: {{PackageName}}

Files:
 *
Copyright: {{Year}} {{CopyrightOwner}}
License: Apache-2.0
 Licensed under the Apache License, Version 2.0 (the "License"); you may not
 use this file except in compliance with the License. You may obtain a copy of
 the License at
 .
    http://www.apache.org/licenses/LICENSE-2.0
 .
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 License for the specific language governing permissions and limitations under
 the License.
Comment:
 On Debian-based systems the full text of the Apache version 2.0 license can be
 found in `/usr/share/common-licenses/Apache-2.0'.

and there shouldn't be a license control field value?

In which case, I think there's probably nothing to do here, though I guess it would be really nice if nfpm could handle this automatically based on the License configuration field πŸ˜„ Might be a bit much to ask though! πŸ˜„

caarlos0 commented 2 months ago

ah, so, I think at least the License field in the control file we can set -> https://github.com/goreleaser/nfpm/pull/849

about formatting a license in the specific format needed, maybe that can be left to whoever is packaging it

andrewlock commented 2 months ago

Ah cool, thank you! 😊