Files
untypequicodeandClaude Sonnet 5.5 947b513163 Add a Nix flake (NixOS, GNOME and Hyprland)
Builds the desktop app and the CLI from source with `nix build`, and offers
packages, an overlay, `nix run`, a dev shell and a formatting check.

- Cargo.lock drives the dependencies (git sources via allowBuiltinFetchGit).
- Installs the desktop file, hicolor icons, MIME types and AppStream metadata
  from packaging/linux/, validated at build time.
- Wraps the binaries so the dlopen'd libraries (libwayland-client,
  libxkbcommon(-x11), X11, Vulkan loader, libEGL, libdbus for the portal file
  chooser) are found on NixOS: native Wayland on GNOME and Hyprland, X11 as
  fallback.
- Fonts from storytold/craft-fonts are pinned to the release workflow's revision
  where the app embeds them.
- doCheck is off (the suite needs corpora and a GPU); `nix build` was verified.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-12 19:17:18 +02:00

123 lines
3.8 KiB
Nix

{
description = "DesignCraft — page layout and publishing, a free alternative to InDesign, in pure Rust";
inputs = {
# DesignCraft needs edition 2024 and rustc ≥ 1.95, so the flake tracks unstable. Consumers on a
# release channel can retarget it: `inputs.designcraft.inputs.nixpkgs.follows = "nixpkgs";`
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# Optional build input of the repository: the fonts that the build embeds when `CRAFT_FONTS_DIR`
# is set. Official releases always build with them; without them everything works but some
# scripts have no glyphs. Pinned to the revision the release workflow uses — bump deliberately
# (`nix flake update craft-fonts`).
craft-fonts = {
url = "github:storytold/craft-fonts/abb83316d96aa59c1cf64784289e378fe9fa5695";
flake = false;
};
};
outputs =
{
self,
nixpkgs,
craft-fonts,
}:
let
inherit (nixpkgs) lib;
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];
# The AppStream metadata carries a release date. The flake source's own commit date is
# reproducible, unlike "now"; a tarball or dirty tree without one falls back to the epoch.
buildDate =
let
d = self.lastModifiedDate or "";
in
if builtins.stringLength d >= 8 then
"${builtins.substring 0 4 d}-${builtins.substring 4 2 d}-${builtins.substring 6 2 d}"
else
"1970-01-01";
packageArgs = {
inherit craft-fonts buildDate;
};
forAllSystems = f: lib.genAttrs systems (system: f (import nixpkgs { inherit system; }) system);
in
{
packages = forAllSystems (
pkgs: _:
let
designcraft = pkgs.callPackage ./nix/package.nix packageArgs;
in
{
inherit designcraft;
default = designcraft;
}
);
# `nixpkgs.overlays = [ inputs.designcraft.overlays.default ]` → `pkgs.designcraft` everywhere.
overlays.default = final: _prev: {
designcraft = final.callPackage ./nix/package.nix packageArgs;
};
apps = forAllSystems (
_: system: {
default = {
type = "app";
program = lib.getExe self.packages.${system}.designcraft;
};
}
);
devShells = forAllSystems (
pkgs: system:
let
designcraft = self.packages.${system}.designcraft;
in
{
default = pkgs.mkShell (
{
# The package's own native inputs, so `cargo build` in the shell needs no extra setup.
inputsFrom = [ designcraft ];
packages = with pkgs; [
cargo
rustc
clippy
rustfmt
rust-analyzer
];
# `cargo run` dlopens the Vulkan loader, libwayland and libxkbcommon like the packaged binary.
LD_LIBRARY_PATH = lib.makeLibraryPath designcraft.passthru.runtimeLibs;
RUST_BACKTRACE = "1";
}
// lib.optionalAttrs (craft-fonts != null) {
# Embedded fonts in `cargo run` too; build.rs reads this as CRAFT_FONTS_DIR.
CRAFT_FONTS_DIR = toString craft-fonts;
}
);
}
);
checks = forAllSystems (
pkgs: system: {
designcraft = self.packages.${system}.designcraft;
# `nix fmt` formats the flake; this keeps it formatted.
formatting =
pkgs.runCommand "designcraft-nix-formatting" { nativeBuildInputs = [ pkgs.nixfmt ]; }
''
nixfmt --check ${./flake.nix} ${./nix}
touch $out
'';
}
);
formatter = forAllSystems (pkgs: _: pkgs.nixfmt);
};
}