Skip to main content

Nix

Publish Nix derivations to a nixpkgs-style repository

The Nix publisher generates a Nix derivation expression for your release and commits it to a nixpkgs-style repository. It is configured under publish.nix within a crate's config.

Minimal config

crates:
  - name: myapp
    publish:
      nix:
        repository:
          owner: my-org
          name: nixpkgs
        description: "A fast CLI tool"
        license: mit

Config fields

FieldTypeDefaultDescription
namestringcrate nameOverride the derivation pname.
pathstringpkgs/<name>/default.nixOutput path for the .nix file in the repository.
repositoryobjectTarget repository config. See Repository config.
commit_authorobjectGit commit author for the derivation commit.
commit_msg_templatestringCustom commit message template.
idslistallFilter to artifacts with these IDs.
url_templatestringOverride download URL template (defaults to release asset URL).
skip_uploadstring"true" always skips; "auto" skips for prereleases.
installstringCustom install commands replacing auto-generated binary install.
extra_installstringAdditional install commands appended after the main install.
post_installstringCommands for the postInstall phase.
descriptionstringShort description for the derivation's meta.description.
homepagestringProject homepage URL for meta.homepage.
licensestringmitNix license identifier (e.g. mit, asl20, gpl3Only). Must be a valid lib.licenses attribute.
dependencieslistRuntime dependencies as Nix package names.
formatterstringNix formatter to run on the generated file: alejandra or nixfmt.

Repository config

repository:
  owner: my-org
  name: nixpkgs
  branch: main           # target branch
  token: "{{ .Env.GITHUB_TOKEN }}"
  pull_request:
    enabled: true        # open a PR instead of pushing directly
    base: master

Dependencies

Dependencies are added to the derivation's nativeBuildInputs. When any dependency is present, makeWrapper is automatically added and a wrapProgram call is generated to extend PATH.

FieldTypeDescription
namestringNix attribute path (e.g. openssl, pkgs.libgit2).
osstringRestrict to linux or darwin. Empty means all platforms.
dependencies:
  - name: openssl
  - name: libiconv
    os: darwin
  - name: pkg-config
    os: linux

Generated derivation format

The generated derivation uses stdenvNoCC.mkDerivation with fetchurl. The SHA256 hashes from release checksums are automatically converted from hex to Nix SRI format (sha256-<base64>).

{ lib
, stdenvNoCC
, fetchurl
, installShellFiles
}:

let
  selectSystem = attrs: attrs.${stdenvNoCC.hostPlatform.system} or (throw "Unsupported system: ${stdenvNoCC.hostPlatform.system}");
  urlMap = {
    x86_64-linux = "https://github.com/owner/repo/releases/download/v1.0.0/myapp_1.0.0_linux_amd64.tar.gz";
    aarch64-linux = "https://github.com/owner/repo/releases/download/v1.0.0/myapp_1.0.0_linux_arm64.tar.gz";
    x86_64-darwin = "https://github.com/owner/repo/releases/download/v1.0.0/myapp_1.0.0_darwin_amd64.tar.gz";
    aarch64-darwin = "https://github.com/owner/repo/releases/download/v1.0.0/myapp_1.0.0_darwin_arm64.tar.gz";
  };
  shaMap = {
    x86_64-linux = "sha256-abc123...";
    ...
  };
in
stdenvNoCC.mkDerivation {
  pname = "myapp";
  version = "1.0.0";

  src = fetchurl {
    url = selectSystem urlMap;
    sha256 = selectSystem shaMap;
  };

  sourceRoot = ".";

  nativeBuildInputs = [ installShellFiles ];

  installPhase = ''
    mkdir -p $out/bin
    cp -vr ./myapp $out/bin/myapp
  '';

  meta = {
    description = "A fast CLI tool";
    license = lib.licenses.mit;
    sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
    platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
  };
}

Platform mapping

Only Linux and macOS (Darwin) artifacts are included. Nix system strings are derived from the artifact's OS and architecture:

OS / ArchNix system
linux / amd64x86_64-linux
linux / arm64aarch64-linux
linux / 386i686-linux
darwin / amd64x86_64-darwin
darwin / arm64aarch64-darwin

License identifiers

The license field must be a valid lib.licenses attribute from nixpkgs. Common values include mit, asl20, gpl3Only, gpl3Plus, lgpl21Only, mpl20, isc, bsd2, bsd3, unlicense, asl20.

Run anodizer check to validate the license identifier before releasing.

Skipping prereleases

skip_upload: auto   # skip for prereleases; publish stable releases

Full example

crates:
  - name: myapp
    publish:
      nix:
        name: myapp
        path: pkgs/myapp/default.nix
        description: "A fast, cross-platform CLI tool"
        homepage: https://github.com/my-org/myapp
        license: mit
        repository:
          owner: my-org
          name: nixpkgs
          branch: main
          token: "{{ .Env.GITHUB_TOKEN }}"
        dependencies:
          - name: openssl
          - name: libiconv
            os: darwin
        skip_upload: auto