Skip to content

matthewbauer/make-package

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

make-package.nix

This is a Nix function for creating packages in Nix. It combines ‘stdenv.mkDerivation’ and ‘callPackage’ from Nixpkgs. By breaking compatibility with these functions, we can create packages with much more structure, and robustness than provided by stdenv.mkDerivation and callPackage.

Differences from stdenv.mkDerivation

  • arguments to makePackage are checked, so you get an error if you misspell one; additional variables to the derivation need to be passed via “environment” (should be used sparingly)
  • strictDeps is enabled by default; if you don’t know what that is, “buildInputs” should be sufficient for your use case
  • “native” build inputs are automatically put into “disallowedReferences” since they should not appear in the output.
  • custom phases like buildCommand, unpackPhase, buildPhase, etc. are disallowed; new phases should be defined in reusable “setup hooks”
  • check phase is enabled by default
  • parallel building and checking is enabeld by default
  • separate debug info is enabled by default
  • installCheck and dist phases are removed; these should be done in a separate derivation

Eventually, I would like to enable “__structuredAttrs” as well, but that requires changes to Nixpkgs (NixOS/nixpkgs#85042).

Differences from callPackage

  • splicing happens explicitly: the arguments passed in are always from pkgsHostTarget, while “deps” must be string identifiers
  • a copy of the package function is saved so that it can be reapplied later for things like override and overrideAttrs
  • package functions use the { … } syntax instead of guessing what to supply

Example

For example, a flake for Nix would look like:

{
  description = "The purely functional package manager";

  inputs.make-package.url = "github:matthewbauer/make-package.nix";

  outputs = { self, make-package }: make-package.makePackagesFlake {} {
    nix = { stdenv, ... }: rec {
      pname = "nix";
      version = "2.4pre20200622_334e26b";

      outputs = [ "out" "dev" "man" "doc" ];

      nativeBuildInputs = [
        "pkgconfig"
        "autoreconfHook"
        "autoconf-archive"
        "bison"
        "flex"
        "libxml2"
        "libxslt"
        "docbook5"
        "docbook_xsl_ns"
        "jq"
      ];
      buildInputs = [
        "curl"
        "openssl"
        "sqlite"
        "xz"
        "bzip2"
        "nlohmann_json"
        "brotli"
        "boost"
        "editline"
        "libsodium"
        "libarchive"
        "gtest"
      ] ++ stdenv.lib.optional stdenv.hostPlatform.isLinux "libseccomp";
      propagatedBuildInputs = [
        "boehmgc"
      ];

      src = self;

      configureFlags = [
        "--with-store-dir=/nix/store"
        "--localstatedir=/nix/"
        "--sysconfdir=/etc"
        "--disable-init-state"
        "--enable-gc"
        "--with-system=${stdenv.hostPlatform.system}"
      ];

      makeFlags = [ "profiledir=${placeholder "out"}/etc/profile.d" ];

      installFlags = [ "sysconfdir=${placeholder "out"}/etc" ];
    };
  };
}

Then, we can have another flake which depends on it directly:

{

  description = "a D-Bus abstraction layer that allows the session user to manage packages in a secure way using a cross-distro, cross-architecture API";

  inputs.make-package.url = "github:matthewbauer/make-package.nix";
  inputs.nix.url = "github:matthewbauer/nix?ref=make-package-flake";

  outputs = { self, make-package, nix }: make-package.makePackagesFlake {
    defaultPackageName = "PackageKit";
  } {
    inherit nix;

    PackageKit = { stdenv, ... }: rec {
      pname = "packagekit";
      version = "1.1.13";

      outputs = [ "out" "dev" ];

      depsBuildBuild = [
        "pkgconfig"
      ];
      nativeBuildInputs = [
        "vala"
        "intltool"
        "pkgconfig"
        "gtk-doc"
        "meson"
        "glib"
        "gobject-introspection"
        "libxslt"
        "ninja"
      ];
      buildInputs = [
        "glib"
        "polkit"
        "python3"
        "systemd"
        "gobject-introspection"
        "bash-completion"
        "gst_all_1.gstreamer"
        "gst_all_1.gst-plugins-base"
        "gtk3"
      ];
      propagatedBuildInputs = [
        "sqlite"
        "boost"
        "nix"
      ];

      src = self;

      mesonFlags = [
        "-Dpackaging_backend=nix"
        "-Ddbus_sys=${placeholder "out"}/share/dbus-1/system.d"
        "-Ddbus_services=${placeholder "out"}/share/dbus-1/system-services"
        "-Dsystemdsystemunitdir=${placeholder "out"}/lib/systemd/system"
      ];
    };
  };
}

More examples are available in “checks” of flake.nix.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages