Unify flag substitution functionality
This commit is contained in:
parent
e785953314
commit
4604e7974a
3 changed files with 40 additions and 34 deletions
|
@ -1,28 +0,0 @@
|
||||||
{ nixpkgs, ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
inherit (builtins)
|
|
||||||
filter isList
|
|
||||||
isString stringLength
|
|
||||||
unsafeDiscardStringContext;
|
|
||||||
|
|
||||||
inherit (nixpkgs.lib.lists) flatten subtractLists;
|
|
||||||
inherit (nixpkgs.lib.strings) addContextFrom;
|
|
||||||
|
|
||||||
split = strOrList:
|
|
||||||
if isList strOrList then flatten strOrList
|
|
||||||
else builtins.split "[[:space:]]+" strOrList
|
|
||||||
|> filter (flag: isString flag && stringLength flag > 0);
|
|
||||||
|
|
||||||
remerge = strOrList: list:
|
|
||||||
if isList strOrList then list
|
|
||||||
else toString list |> addContextFrom strOrList;
|
|
||||||
in {
|
|
||||||
remove = rem: strOrList: split strOrList
|
|
||||||
|> subtractLists rem
|
|
||||||
|> remerge strOrList;
|
|
||||||
|
|
||||||
subst = sub: strOrList: split strOrList
|
|
||||||
|> map (flag: sub.${unsafeDiscardStringContext flag} or flag)
|
|
||||||
|> remerge strOrList;
|
|
||||||
}
|
|
32
lib/substituteFlags.nix
Normal file
32
lib/substituteFlags.nix
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
{ nixpkgs, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
inherit (builtins)
|
||||||
|
isFunction
|
||||||
|
filter isList
|
||||||
|
match isString stringLength
|
||||||
|
unsafeDiscardStringContext;
|
||||||
|
|
||||||
|
inherit (nixpkgs.lib.attrsets) foldlAttrs;
|
||||||
|
inherit (nixpkgs.lib.lists) flatten subtractLists;
|
||||||
|
inherit (nixpkgs.lib.strings) addContextFrom;
|
||||||
|
|
||||||
|
split = strOrList:
|
||||||
|
if isList strOrList then flatten strOrList
|
||||||
|
else builtins.split "[[:space:]]+" strOrList
|
||||||
|
|> filter (flag: isString flag && stringLength flag > 0);
|
||||||
|
|
||||||
|
merge = strOrList: list:
|
||||||
|
if isList strOrList then list
|
||||||
|
else toString list |> addContextFrom strOrList;
|
||||||
|
in substAttrs: strOrList: split strOrList
|
||||||
|
|> map (flag: let subst = foldlAttrs (result: regex: subst:
|
||||||
|
if result != false then result
|
||||||
|
else let groups = match regex flag;
|
||||||
|
in if groups == null then false
|
||||||
|
else if isFunction subst then subst groups
|
||||||
|
else subst)
|
||||||
|
false substAttrs;
|
||||||
|
in if subst != false then subst else flag)
|
||||||
|
|> filter (flag: flag != null)
|
||||||
|
|> merge strOrList
|
|
@ -5,7 +5,7 @@ let
|
||||||
inherit (nixpkgs.lib.attrsets) genAttrs;
|
inherit (nixpkgs.lib.attrsets) genAttrs;
|
||||||
inherit (nixpkgs.lib.lists) remove toList;
|
inherit (nixpkgs.lib.lists) remove toList;
|
||||||
inherit (nixpkgs.lib.strings) mesonBool mesonEnable;
|
inherit (nixpkgs.lib.strings) mesonBool mesonEnable;
|
||||||
inherit (self.lib) flags packages;
|
inherit (self.lib) substituteFlags packages;
|
||||||
|
|
||||||
final' = final;
|
final' = final;
|
||||||
prev' = prev;
|
prev' = prev;
|
||||||
|
@ -89,7 +89,7 @@ in genAttrs [
|
||||||
buildInputs = prevAttrs.buildInputs or [ ]
|
buildInputs = prevAttrs.buildInputs or [ ]
|
||||||
++ [ final.libGL ];
|
++ [ final.libGL ];
|
||||||
mesonFlags = prevAttrs.mesonFlags or [ ]
|
mesonFlags = prevAttrs.mesonFlags or [ ]
|
||||||
|> flags.subst { "-Degl=no" = "-Degl=yes"; };
|
|> substituteFlags { "-Degl=.*" = "-Degl=yes"; };
|
||||||
})).override {
|
})).override {
|
||||||
x11Support = false;
|
x11Support = false;
|
||||||
};
|
};
|
||||||
|
@ -132,12 +132,14 @@ in genAttrs [
|
||||||
qtbase = (prev.qtbase.overrideAttrs (prevAttrs: {
|
qtbase = (prev.qtbase.overrideAttrs (prevAttrs: {
|
||||||
env = prevAttrs.env or { } // {
|
env = prevAttrs.env or { } // {
|
||||||
NIX_CFLAGS_COMPILE = prevAttrs.env.NIX_CFLAGS_COMPILE or ""
|
NIX_CFLAGS_COMPILE = prevAttrs.env.NIX_CFLAGS_COMPILE or ""
|
||||||
|> flags.remove [ "-DUSE_X11" ];
|
|> substituteFlags { "-DUSE_X11" = null; };
|
||||||
};
|
};
|
||||||
|
|
||||||
configureFlags = prevAttrs.configureFlags or [ ]
|
configureFlags = prevAttrs.configureFlags or [ ]
|
||||||
|> flags.remove [ "-qpa xcb" ]
|
|> substituteFlags {
|
||||||
|> flags.subst { "-xcb" = "-no-xcb"; };
|
"-qpa .*" = null;
|
||||||
|
"-xcb" = "-no-xcb";
|
||||||
|
};
|
||||||
})).override {
|
})).override {
|
||||||
withGtk3 = false;
|
withGtk3 = false;
|
||||||
withQttranslation = false;
|
withQttranslation = false;
|
||||||
|
@ -153,7 +155,7 @@ in genAttrs [
|
||||||
buildInputs = prevAttrs.buildInputs or [ ]
|
buildInputs = prevAttrs.buildInputs or [ ]
|
||||||
|> packages.remove [ "gtkmm" ];
|
|> packages.remove [ "gtkmm" ];
|
||||||
configureFlags = prevAttrs.configureFlags or [ ]
|
configureFlags = prevAttrs.configureFlags or [ ]
|
||||||
|> flags.remove [ "--with-gtkmm" ];
|
|> substituteFlags { "--with-gtkmm" = null; };
|
||||||
});
|
});
|
||||||
|
|
||||||
vim-full = prev.vim-full.override {
|
vim-full = prev.vim-full.override {
|
||||||
|
|
Loading…
Reference in a new issue