Skip to content

Commit 20469d9

Browse files
committed
ci(flake): improve builder
1 parent 9f3b92a commit 20469d9

3 files changed

Lines changed: 61 additions & 45 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ endif
9797
ifdef BINDIR
9898
@mkdir -p "$(BINDIR)";
9999
ifeq ($(filter /%,$(LUA)),)
100-
@printf '%s\npackage.cpath = '\''%q/?.so'\''\n-- ' "#!/usr/bin/env $(LUA)" "$(LIBDIR)" > "$(BINDIR)/tomlua";
100+
@printf '%s\npackage.cpath = [==============[%s/?.so]==============]\n-- ' "#!/usr/bin/env $(LUA)" "$(LIBDIR)" > "$(BINDIR)/tomlua";
101101
else
102-
@printf '%s\npackage.cpath = '\''%q/?.so'\''\n-- ' "#!$(LUA)" "$(LIBDIR)" > "$(BINDIR)/tomlua";
102+
@printf '%s\npackage.cpath = [==============[%s/?.so]==============]\n-- ' "#!$(LUA)" "$(LIBDIR)" > "$(BINDIR)/tomlua";
103103
endif
104104
@cat "$(SRC)/bin/tomlua" >> "$(BINDIR)/tomlua";
105105
@chmod +x "$(BINDIR)/tomlua";

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{ pkgs ? import <nixpkgs> {}, ... }: (import ./flake.nix).outputs {
22
self = builtins.path { path = ./.; };
33
inherit (pkgs.stdenv.hostPlatform) system;
4-
nixpkgs = pkgs;
4+
inherit pkgs;
55
}

flake.nix

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
{
22
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
3-
outputs = { self, nixpkgs, ... }@inputs: let
4-
genAttrs = names: f: builtins.listToAttrs (map (n: { name = n; value = f n; }) names);
5-
forAllSys = genAttrs inputs.systems or nixpkgs.lib.platforms.all or [ (inputs.system or throw "No systems list provided!") ];
6-
getpkgswithoverlay = system: if builtins.all (v: nixpkgs ? "${v}") [ "path" "stdenv" "appendOverlays" ]
7-
then nixpkgs.appendOverlays [ overlay ] else import nixpkgs { inherit system; overlays = [ overlay ]; };
8-
getpkgs = system: if builtins.all (v: nixpkgs ? "${v}") [ "path" "stdenv" "appendOverlays" ]
9-
then nixpkgs else import nixpkgs { inherit system; };
3+
outputs = { self, ... }@inputs: let
4+
lib = inputs.pkgs.lib or inputs.nixpkgs.lib or (import "${inputs.nixpkgs or <nixpkgs>}/lib");
5+
forAllSys = lib.genAttrs lib.platforms.all;
6+
getPkgs = system: overlays: if inputs.pkgs.stdenv.hostPlatform.system or null == system then
7+
if builtins.isList overlays && overlays != [] then
8+
inputs.pkgs.appendOverlays overlays
9+
else
10+
inputs.pkgs
11+
else
12+
import (inputs.pkgs.path or inputs.nixpkgs or <nixpkgs>) {
13+
inherit system;
14+
overlays = (if builtins.isList overlays then overlays else []) ++ inputs.pkgs.overlays or [];
15+
config = inputs.pkgs.config or {};
16+
};
1017
mapAttrsToList = f: attrs: builtins.attrValues (builtins.mapAttrs f attrs);
1118
l_pkg_enum = {
1219
lua5_1 = "lua51Packages";
@@ -19,55 +26,64 @@
1926
};
2027
APPNAME = "tomlua";
2128
overlay = final: prev: let
29+
luaCallPackageFn = { toLuaModule, lua, }:
30+
toLuaModule (lua.stdenv.mkDerivation (finalAttrs: {
31+
pname = APPNAME;
32+
version = "${(finalAttrs.passthru.luaModule or lua).luaversion}.dev";
33+
src = self;
34+
LUA = (finalAttrs.passthru.luaModule or lua).interpreter;
35+
LUA_INC = (finalAttrs.passthru.luaModule or lua) + "/include";
36+
propagatedBuildInputs = [ (finalAttrs.passthru.luaModule or lua) ];
37+
BINDIR = placeholder "out" + "/bin";
38+
LIBDIR = placeholder "out" + "/lib/lua/" + (finalAttrs.passthru.luaModule or lua).luaversion;
39+
LUADIR = placeholder "out" + "/share/lua/" + (finalAttrs.passthru.luaModule or lua).luaversion;
40+
doCheck = false;
41+
}));
2242
# lua5_1 = prev.lua5_1.override { packageOverrides };
23-
l_pkg_main = builtins.mapAttrs (n: _: (prev.lib.attrByPath [ n "override" ] null prev) {
24-
packageOverrides = luaself: luaprev: {
25-
${APPNAME} = luaself.callPackage ({buildLuarocksPackage}:
26-
buildLuarocksPackage {
27-
pname = APPNAME;
28-
version = "scm-1";
29-
knownRockspec = "${self}/${APPNAME}-scm-1.rockspec";
30-
src = self;
31-
checkPhase = "runHook preCheck; runHook preCheck";
32-
installCheckPhase = ''
33-
runHook preInstallCheck
34-
luarocks test
35-
runHook postInstallCheck
36-
'';
37-
}) {};
38-
};
39-
}) l_pkg_enum;
43+
l_pkg_main = builtins.mapAttrs (
44+
n: _: (prev.lib.attrByPath [ n "override" ] null prev) {
45+
packageOverrides = luaself: luaprev: {
46+
${APPNAME} = luaself.callPackage luaCallPackageFn {};
47+
};
48+
}
49+
) l_pkg_enum;
4050
# lua51Packages = final.lua5_1.pkgs;
41-
l_pkg_sets = builtins.listToAttrs (mapAttrsToList (n: v: {
42-
name = v;
43-
value = prev.lib.attrByPath [ n "pkgs" ] null final;
44-
}) l_pkg_enum);
51+
l_pkg_sets = builtins.listToAttrs (
52+
mapAttrsToList (
53+
n: v: {
54+
name = v;
55+
value = prev.lib.attrByPath [ n "pkgs" ] null final;
56+
}
57+
) l_pkg_enum
58+
);
4559
in l_pkg_main // l_pkg_sets // {
4660
vimPlugins = prev.vimPlugins // {
47-
${APPNAME} = (final.neovimUtils.buildNeovimPlugin { pname = APPNAME; }).overrideAttrs {
48-
luarocksConfig = {
49-
lua_modules_path = "lua";
50-
lib_modules_path = "lua";
51-
};
52-
};
61+
${APPNAME} = final.vimUtils.toVimPlugin ((final.neovim-unwrapped.lua.pkgs.callPackage luaCallPackageFn {}).overrideAttrs {
62+
LIBDIR = placeholder "out" + "/lua";
63+
LUADIR = placeholder "out" + "/lua";
64+
});
5365
};
5466
};
5567
packages = forAllSys (system: let
56-
pkgs = getpkgswithoverlay system;
57-
in (with builtins; listToAttrs (map (n: {
58-
name = "${n}-${APPNAME}";
59-
value = pkgs.lib.attrByPath [ n "pkgs" APPNAME ] null pkgs;
60-
}) (attrNames l_pkg_enum))) // {
68+
pkgs = getPkgs system [ overlay ];
69+
in (
70+
with builtins; listToAttrs (
71+
map (n: {
72+
name = "${n}-${APPNAME}";
73+
value = pkgs.lib.attrByPath [ n "pkgs" APPNAME ] null pkgs;
74+
}) (attrNames l_pkg_enum)
75+
)
76+
) // {
6177
default = pkgs.vimPlugins.${APPNAME};
6278
"vimPlugins-${APPNAME}" = pkgs.vimPlugins.${APPNAME};
6379
});
6480
in {
6581
overlays.default = overlay;
6682
inherit packages;
67-
checks = forAllSys (system: builtins.mapAttrs (_: p: p.overrideAttrs { doInstallCheck = true; }) packages.${system});
83+
checks = forAllSys (system: builtins.mapAttrs (_: p: p.overrideAttrs { doCheck = true; }) packages.${system});
6884
devShells = forAllSys (system: let
69-
pkgs = getpkgs system;
70-
lua = pkgs.luajit.withPackages (lp: [lp.inspect lp.cjson lp.toml-edit lp.luarocks]);
85+
pkgs = getPkgs system [];
86+
lua = pkgs.luajit.withPackages (lp: [ lp.inspect lp.cjson lp.toml-edit lp.luarocks ]);
7187
in {
7288
default = pkgs.mkShell {
7389
name = "${APPNAME}-dev";

0 commit comments

Comments
 (0)