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/ .direnv/
.envrc .envrc
build/ build/
result/

View file

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

132
flake.nix
View file

@ -10,9 +10,62 @@
nixpkgs, nixpkgs,
}: let }: let
inherit (nixpkgs) lib; inherit (nixpkgs) lib;
systems = lib.systems.flakeExposed; systems = lib.systems.flakeExposed;
forAllSystems = lib.genAttrs systems; forAllSystems = lib.genAttrs systems;
nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system}); 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 { in {
checks = forAllSystems ( checks = forAllSystems (
system: let system: let
@ -26,6 +79,8 @@
statix statix
]; ];
} '' } ''
cd ${self}
echo "Checking nix formatting" echo "Checking nix formatting"
alejandra --check . alejandra --check .
@ -34,6 +89,8 @@
echo "Checking statix" echo "Checking statix"
statix check . statix check .
touch $out
''; '';
} }
); );
@ -101,64 +158,31 @@
formatter = forAllSystems (system: nixpkgsFor.${system}.alejandra); formatter = forAllSystems (system: nixpkgsFor.${system}.alejandra);
packages = forAllSystems ( packages = forAllSystems (system: let
system: let
pkgs = nixpkgsFor.${system}; pkgs = nixpkgsFor.${system};
git_tag inherit (pkgs) fetchFromGitHub;
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";
in { in {
default = pkgs.stdenv.mkDerivation (finalAttrs { stable = mkClayPackage {
pname = "clay"; inherit system;
version = "v0.14-master-${date}"; 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 = "";
};
unstable = mkClayPackage {
inherit system;
version = "0.14";
src = ./.; src = ./.;
suffix = "-master-${date}";
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;
}; };
default = self.packages.${system}.stable;
}); });
defaultPackage = self.packages.${system}.default;
}
);
}; };
} }