Add flake.nix, make default.nix callPackageable

This commit is contained in:
Jari Vetoniemi 2024-02-02 13:38:20 +09:00
parent b1439df42c
commit 55e5aec8d5
4 changed files with 108 additions and 17 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
*
result/

View File

@ -1,27 +1,41 @@
{ pkgs ? import <nixpkgs> {}, lib ? pkgs.lib, stdenv ? pkgs.stdenv }:
{
lib
, stdenv
, pkg-config
, scdoc
, ncurses
, cairo
, fribidi
, harfbuzz
, libxkbcommon
, pango
, wayland
, wayland-scanner
, wayland-protocols
, xorg
}:
with builtins;
with lib;
let
src = pkgs.copyPathToStore ./.;
semver = builtins.readFile "${src}/VERSION";
revision = builtins.readFile (pkgs.runCommand "get-rev" {
nativeBuildInputs = with pkgs; [ git ];
} "GIT_DIR=${src}/.git git rev-parse --short HEAD | tr -d '\n' > $out");
src = ./.;
version = readFile "${src}/VERSION";
in stdenv.mkDerivation {
inherit src;
inherit src version;
pname = "bemenu";
version = "${semver}${revision}";
strictDeps = true;
nativeBuildInputs = with pkgs; [
nativeBuildInputs = [
pkg-config
scdoc
] ++ lib.optionals (stdenv.isLinux) [
] ++ optionals (stdenv.isLinux) [
wayland-scanner
];
buildInputs = with pkgs; [
buildInputs = [
ncurses
] ++ lib.optionals (stdenv.isLinux) [
] ++ optionals (stdenv.isLinux) [
cairo
fribidi
harfbuzz
@ -34,26 +48,27 @@ in stdenv.mkDerivation {
xorg.libXdmcp xorg.libpthreadstubs xorg.libxcb
];
postPatch = "" + lib.optionalString (stdenv.isDarwin) ''
postPatch = "" + optionalString (stdenv.isDarwin) ''
substituteInPlace GNUmakefile --replace '-soname' '-install_name'
'';
makeFlags = [ "PREFIX=$(out)" ];
buildFlags = [ "PREFIX=$(out)" "clients" "curses" ] ++ lib.optionals (stdenv.isLinux) [ "wayland" "x11" ];
buildFlags = [ "PREFIX=$(out)" "clients" "curses" ] ++ optionals (stdenv.isLinux) [ "wayland" "x11" ];
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh
# ^ does not handle .so files
postInstall = "" + lib.optionalString (stdenv.isDarwin) ''
postInstall = "" + optionalString (stdenv.isDarwin) ''
so="$(find "$out/lib" -name "libbemenu.so.[0-9]" -print -quit)"
for f in "$out/bin/"*; do
install_name_tool -change "$(basename $so)" "$so" $f
done
'';
meta = with pkgs.lib; {
meta = {
homepage = "https://github.com/Cloudef/bemenu";
description = "Dynamic menu library and client program inspired by dmenu";
license = licenses.gpl3Plus;
platforms = with platforms; darwin ++ linux;
mainProgram = "bemenu-run";
};
}

60
flake.lock generated Normal file
View File

@ -0,0 +1,60 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1706847834,
"narHash": "sha256-h5oI1EYXFl9y6a9UplqposfGPL0hNGKH7bgT0mnLmQg=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "90f6c2d2b6132686cb6aa0f63fc0ce027d4e2c18",
"type": "github"
},
"original": {
"owner": "nixos",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

16
flake.nix Normal file
View File

@ -0,0 +1,16 @@
{
description = "bemenu";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }: let
outputs = (flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.outputs.legacyPackages.${system};
in {
packages.default = pkgs.callPackage ./default.nix {};
}));
in outputs;
}