refactor: fix flake checks, make package definitions easier

This commit is contained in:
h4rl 2025-06-09 22:52:50 +02:00
parent e465d05284
commit e1a4fb9810
No known key found for this signature in database
GPG key ID: B69EFF282C4538F4
3 changed files with 85 additions and 60 deletions

1
.gitignore vendored
View file

@ -8,3 +8,4 @@ node_modules/
.direnv/
.envrc
build/
result/

View file

@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1747327360,
"narHash": "sha256-LSmTbiq/nqZR9B2t4MRnWG7cb0KVNU70dB7RT4+wYK4=",
"lastModified": 1749285348,
"narHash": "sha256-frdhQvPbmDYaScPFiCnfdh3B/Vh81Uuoo0w5TkWmmjU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e06158e58f3adee28b139e9c2bcfcc41f8625b46",
"rev": "3e3afe5174c561dee0df6f2c2b2236990146329f",
"type": "github"
},
"original": {

134
flake.nix
View file

@ -10,9 +10,62 @@
nixpkgs,
}: let
inherit (nixpkgs) lib;
systems = lib.systems.flakeExposed;
forAllSystems = lib.genAttrs systems;
nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system});
date = let
# YYYYMMDD
date' = lib.substring 0 8 self.lastModifiedDate;
year = lib.substring 0 4 date';
month = lib.substring 4 2 date';
day = lib.substring 6 2 date';
in
if (self ? lastModifiedDate)
then lib.concatStringsSep "-" [year month day]
else "unknown";
mkClayPackage = {
system,
version,
src,
suffix,
}:
nixpkgsFor.${system}.stdenv.mkDerivation {
pname = "clay";
version = "${version}${suffix}";
inherit src;
dontBuild = true;
postInstall = ''
mkdir -p $out/include
mkdir -p $out/lib/pkgconfig
cp clay.h $out/include
cat <<EOF >$out/lib/pkgconfig/clay.pc
prefix=$out
includedir=$out/include
Name: Clay
Description: Clay (short for C Layout) is a high performance 2D UI layout library.
Version: ${version}
Cflags: -I$out/include
EOF
'';
passthru.tests.pkg-config = nixpkgs.lib.testing.testMetaPkgConfig self.packages.${system}.${version};
meta = with lib; {
description = "Clay (short for C Layout) is a high performance 2D UI layout library.";
homepage = "https://github.com/nicbarker/clay";
license = licenses.zlib;
maintainers = with maintainers; [nicbarker];
pkgConfigModules = ["clay"];
platforms = platforms.all;
};
};
in {
checks = forAllSystems (
system: let
@ -26,6 +79,8 @@
statix
];
} ''
cd ${self}
echo "Checking nix formatting"
alejandra --check .
@ -34,6 +89,8 @@
echo "Checking statix"
statix check .
touch $out
'';
}
);
@ -101,64 +158,31 @@
formatter = forAllSystems (system: nixpkgsFor.${system}.alejandra);
packages = forAllSystems (
system: let
packages = forAllSystems (system: let
pkgs = nixpkgsFor.${system};
git_tag
date = let
# YYYYMMDD
date' = lib.substring 0 8 self.lastModifiedDate;
year = lib.substring 0 4 date';
month = lib.substring 4 2 date';
date = lib.substring 6 2 date';
in
if (self ? "lastModifiedDate")
then
lib.concatStringsSep "-" [
year
month
date
]
else "unknown";
inherit (pkgs) fetchFromGitHub;
in {
default = pkgs.stdenv.mkDerivation (finalAttrs {
pname = "clay";
version = "v0.14-master-${date}";
src = ./.;
dontBuild = true;
installPhase = ''
mkdir -p $out/include
mkdir -p $out/lib/pkgconfig
cp clay.h $out/include
cat <<EOF >$out/lib/pkgconfig/clay.pc
prefix=$out
includedir=$out/include
Name: Clay
Description: Clay (short for C Layout) is a high performance 2D UI layout library.
Version: $version
Cflags: -I$out/include
EOF
'';
passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
meta = with lib; {
description = "Clay (short for C Layout) is a high performance 2D UI layout library.";
homepage = "https://github.com/nicbarker/clay";
license = licenses.zlib;
maintainers = with maintainers; [nicbarker];
pkgConfigModules = ["clay"];
# FIXME: I'm not sure what platforms this supports.
platforms = platforms.all;
stable = mkClayPackage {
inherit system;
version = "0.14";
# To update this use nurl https://github.com/nicbarker/clay {tag}
src = fetchFromGitHub {
owner = "nicbarker";
repo = "clay";
rev = "v0.14"; # This will need to be updated when a new version is released
hash = "sha256-6h1aQXqwzPc4oPuid3RfV7W0WzQFUiddjW7OtkKM0P8="; # This too likely
};
suffix = "";
};
});
defaultPackage = self.packages.${system}.default;
}
);
unstable = mkClayPackage {
inherit system;
version = "0.14";
src = ./.;
suffix = "-master-${date}";
};
default = self.packages.${system}.stable;
});
};
}