From 80405f4584292cf656450e49f2dd3c52210fbd73 Mon Sep 17 00:00:00 2001 From: Sebastian Moser Date: Wed, 3 Apr 2024 10:20:29 +0200 Subject: [PATCH] static talloc overlay --- flake.lock | 68 ++++++++-- flake.nix | 42 ++++-- .../my-overlay.nix | 0 overlays/patches/talloc-satic.patch | 20 +++ overlays/static-overlay.nix | 120 ++++++++++++++++++ 5 files changed, 231 insertions(+), 19 deletions(-) rename mods/my-nixpkgs-overlay.nix => overlays/my-overlay.nix (100%) create mode 100644 overlays/patches/talloc-satic.patch create mode 100644 overlays/static-overlay.nix diff --git a/flake.lock b/flake.lock index 030125d..768c775 100644 --- a/flake.lock +++ b/flake.lock @@ -3,7 +3,7 @@ "androidPkgs": { "inputs": { "devshell": "devshell", - "flake-utils": "flake-utils_6", + "flake-utils": "flake-utils_7", "nixpkgs": "nixpkgs_7" }, "locked": { @@ -327,6 +327,24 @@ "inputs": { "systems": "systems_2" }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_4": { + "inputs": { + "systems": "systems_3" + }, "locked": { "lastModified": 1694529238, "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", @@ -341,9 +359,9 @@ "type": "github" } }, - "flake-utils_4": { + "flake-utils_5": { "inputs": { - "systems": "systems_3" + "systems": "systems_4" }, "locked": { "lastModified": 1701680307, @@ -359,7 +377,7 @@ "type": "github" } }, - "flake-utils_5": { + "flake-utils_6": { "locked": { "lastModified": 1610051610, "narHash": "sha256-U9rPz/usA1/Aohhk7Cmc2gBrEEKRzcW4nwPWMPwja4Y=", @@ -374,7 +392,7 @@ "type": "github" } }, - "flake-utils_6": { + "flake-utils_7": { "locked": { "lastModified": 1638122382, "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", @@ -504,7 +522,7 @@ "evil-quick-diff": "evil-quick-diff", "explain-pause-mode": "explain-pause-mode", "flake-compat": "flake-compat_2", - "flake-utils": "flake-utils_3", + "flake-utils": "flake-utils_4", "format-all": "format-all", "nix-straight": "nix-straight", "nixpkgs": "nixpkgs_3", @@ -623,7 +641,7 @@ "nix-wsl": { "inputs": { "flake-compat": "flake-compat_3", - "flake-utils": "flake-utils_4", + "flake-utils": "flake-utils_5", "nixpkgs": "nixpkgs_4" }, "locked": { @@ -1041,7 +1059,7 @@ }, "podman": { "inputs": { - "flake-utils": "flake-utils_5", + "flake-utils": "flake-utils_6", "nixpkgs": "nixpkgs_6" }, "locked": { @@ -1098,6 +1116,7 @@ "inputs": { "firefox": "firefox", "firefox-addons": "firefox-addons", + "flake-utils": "flake-utils_3", "home-manager": "home-manager", "my-log": "my-log", "networkmanager": "networkmanager", @@ -1111,7 +1130,8 @@ "nixpkgs-for-bootstrap": "nixpkgs-for-bootstrap_2", "nixpkgs-unstable": "nixpkgs-unstable", "podman": "podman", - "robotnix": "robotnix" + "robotnix": "robotnix", + "systems": "systems_5" } }, "rotate-text": { @@ -1191,6 +1211,36 @@ "type": "github" } }, + "systems_4": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_5": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "ts-fold": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index d3df931..f5a238c 100644 --- a/flake.nix +++ b/flake.nix @@ -64,15 +64,33 @@ podman.url = "github:ES-Nix/podman-rootless"; + flake-utils.url = "github:numtide/flake-utils"; + systems.url = "github:nix-systems/default"; + }; - outputs = { self, nixpkgs, nixos-generators, ... }@inputs: + outputs = { self, nixpkgs, nixos-generators, flake-utils, systems, ... }@inputs: let confDir = "/home/me/work/config"; workDir = "/home/me/work"; secretsDir = "/home/me/work/here/secrets"; persistentDir = "/home/me/work/app-data"; + tunepkgs = import nixpkgs { + + localSystem = { + gcc.arch = "kabylake"; + gcc.tune = "kabylake"; + system = "x86_64-linux"; + }; + + #system = "x86_64-linux"; + #overlays = [ + #(self: super: { + #stdenv = super.impureUseNativeOptimizations super.stdenv; + #}) + #]; + }; mypkgs = import nixpkgs { system = "x86_64-linux"; config = { @@ -89,7 +107,7 @@ }; specialArgs = { - inherit inputs confDir workDir secretsDir persistentDir self; + inherit inputs confDir workDir secretsDir persistentDir self tunepkgs; system = "x86_64-linux"; pkgs = mypkgs; }; @@ -340,6 +358,16 @@ }; packages.x86_64-linux = { + tunefox = mypkgs.firefox-unwrapped.overrideAttrs (final: prev: { + NIX_CFLAGS_COMPILE = [ (prev.NIX_CFLAGS_COMPILE or "") ] ++ [ "-O3" "-march=native" "-fPIC" ]; + requireSigning = false; + }); + + pkgsWithOverlays = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ./overlays/static-overlay.nix ./overlays/my-overlay.nix ]; + }; + hi = self.nixosConfigurations.the-most-default.config.system.build.toplevel; #testing = nixpkgs.legacyPackages.x86_64-linux; testing = (nixpkgs.legacyPackages.x86_64-linux.writeShellApplication { @@ -348,14 +376,6 @@ #text = "cd /home/me/work/log/new; nix develop -c 'python ${workDir}/log/new/client.py'"; text = ''${inputs.my-log.packages.x86_64-linux.pythonForLog}/bin/python ${workDir}/log/new/client.py "$@"''; }); - - test = nixpkgs.legacyPackages.x86_64-linux.firefox-devedition-unwrapped.overrideAttrs (old: { - NIX_CFLAGS_COMPILE = [ (old.NIX_CFLAGS_COMPILE or "") ] ++ [ "-O3" "-march=native" "-fPIC" ]; - #hi = builtins.trace ("hello world: " + old.passthru.unwrapped.name) 4; - #passthru.unwrapped = old.passthru.unwrapped.overrideAttrs (innerOld: { - #NIX_CFLAGS_COMPILE = [ (innerOld.NIX_CFLAGS_COMPILE or "") ] ++ [ "-O3" "-march=native" "-fPIC" ]; - #}); - }); #test = inputs.firefox.packages.${nixpkgs.legacyPackages.x86_64-linux.pkgs.system}; #.firefox-nightly-bin.overrideAttrs (old: { #NIX_CFLAGS_COMPILE = [ (old.NIX_CFLAGS_COMPILE or "") ] ++ [ "-O3" "-march=native" "-fPIC" ]; @@ -408,8 +428,10 @@ }; }; + tunepkgs = tunepkgs; pkgs = mypkgs; home.me = import ./users/me/gui-home.nix; top = builtins.mapAttrs (name: value: value.config.system.build.toplevel) (self.nixOnDroidConfigurations // self.nixosConfigurations); + #nur = let nur-systems = [ "x86_64-linux" "aarch64-linux" ]; in flake-utils.eachDefaultSystem (system: inputs.nixpkgs-unstable.legacyPackages.${system}.callPackage ./nur.nix {}); }; } diff --git a/mods/my-nixpkgs-overlay.nix b/overlays/my-overlay.nix similarity index 100% rename from mods/my-nixpkgs-overlay.nix rename to overlays/my-overlay.nix diff --git a/overlays/patches/talloc-satic.patch b/overlays/patches/talloc-satic.patch new file mode 100644 index 0000000..5b73b0e --- /dev/null +++ b/overlays/patches/talloc-satic.patch @@ -0,0 +1,20 @@ +diff --git a/buildtools/wafsamba/wscript b/buildtools/wafsamba/wscript +index dcc8a65..3e42d43 100644 +--- a/buildtools/wafsamba/wscript ++++ b/buildtools/wafsamba/wscript +@@ -305,7 +305,15 @@ def configure(conf): + conf.CHECK_CC_ENV() + + conf.load('compiler_c') ++ ++ # This seems to be the only way to not include the -Wl,-Bdynamic in the linker gcc cmdline ++ # because it is assumed as a common gcc flag in $src/third_party/waf/waflib/Tools/gcc.py ++ # and disabled only for certain platforms with no way to disable it from eg an ENV Variable ++ # export SHLIB_MARKER = "" is picked up by waf (just before conf.load conf.env.SHLIB_MARKER is "") ++ # but the conf.load("compiler_c") overwrites that ++ # on the alpine static build it is no problem to have both -Wl,-Bdynamic and -Wl,-Bstatic ++ # but on nix it is a problem ++ conf.env.SHLB_MARKER = "" + + conf.CHECK_STANDARD_LIBPATH() + diff --git a/overlays/static-overlay.nix b/overlays/static-overlay.nix new file mode 100644 index 0000000..0a647d5 --- /dev/null +++ b/overlays/static-overlay.nix @@ -0,0 +1,120 @@ + +{ nixpkgs, ... }: final: prev: { + + # talloc for proot + talloc = prev.talloc.overrideAttrs (innerFinal: innerPrev: { + wafConfigureFlags = innerPrev.wafConfigureFlags ++ [ "--disable-python" ]; + patches = innerPrev.patches ++ [ ./patches/talloc-satic.patch ]; + }); + + # for static builds + duktape = prev.duktape.overrideAttrs (innerFinal: innerPrev: { + patches = innerPrev.patches or [] ++ [ + ./static/duktape.patch + ]; + #unpackPhase = "echo hiiiiiiiiiiiiiiiiiiiiiiiiiii"; + #buildPhase = "echo hiiiiiiiiiiiiiiiiiiiiiiiiii"; + + buildPhase = '' + make -f dist-files/Makefile.staticlibrary + make -f Makefile.cmdline + ''; + installPhase = '' + install -d $out/bin + install -m755 duk $out/bin/ + install -d $out/lib/pkgconfig + install -d $out/include + make -f dist-files/Makefile.staticlibrary install INSTALL_PREFIX=$out + substituteAll ${nixpkgs}/pkgs/development/interpreters/duktape/duktape.pc.in $out/lib/pkgconfig/duktape.pc + ''; + }); + + dconf = prev.dconf.overrideAttrs (innerFinal: innerPrev: { + patches = innerPrev.patches or [] ++ [ + ./static/dconf.patch + ]; + }); + + at-spi2-core = prev.at-spi2-core.overrideAttrs (innerFinal: innerPrev: { + mesonFlags = innerPrev.mesonFlags or [] ++ [ + "-Dintrospection=disabled" + "-Ddbus_broker=default" + "-Dgtk2_atk_adaptor=false" + ]; + }); + + cdparanoia = prev.cdparanoia.overrideAttrs (innerFinal: innerPrev: { + patches = innerPrev.patches or [] ++ [ + ./static/cdparanoia.patch + ]; + }); + + + # this is a mess.... + #pkgsStatic = prev.pkgsStatic // {gobject-introspection = prev.callPackage ./static/gobject-introspection.nix { inherit nixpkgs; };}; + #gobject-introspection = prev.callPackage ./static/gobject-introspection.nix { inherit nixpkgs; }; + #buildPackges = prev.buildPackges // {gobject-introspection = prev.callPackage ./static/gobject-introspection.nix { inherit nixpkgs; };}; + # .... gobject-introspection is just not made for dyn linking + + python311Packages = prev.python311Packages // { lxml = prev.python311Packages.lxml.overrideAttrs (innerFinal: innerPrev: + let + libxmlSrc = prev.fetchurl { + url = "mirror://gnome/sources/libxml2/${prev.lib.versions.majorMinor "2.12.4"}/libxml2-2.12.4.tar.xz"; + sha256 = "sha256-SXNg5CPPC9merNt8YhXeqS5tbonulAOTwrrg53y5t9A="; + }; + zlibSrc = let version = "1.3.1"; in prev.fetchurl { + urls = [ + # This URL works for 1.2.13 only; hopefully also for future releases. + "https://github.com/madler/zlib/releases/download/v${version}/zlib-${version}.tar.gz" + # Stable archive path, but captcha can be encountered, causing hash mismatch. + "https://www.zlib.net/fossils/zlib-${version}.tar.gz" + ]; + hash = "sha256-mpOyt9/ax3zrpaVYpYDnRmfdb+3kWFuR7vtg8Dty3yM="; + }; + libiconvSrc = prev.fetchurl { + url = "https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.17.tar.gz"; + hash = "sha256-j3QhO1YjjIWlClMp934GGYdx5w3Zpzl3n0wC9l2XExM="; + }; + libxsltSrc = let version = "1.1.37"; pname = "libxslt"; in prev.fetchurl { + url = "mirror://gnome/sources/${pname}/${prev.lib.versions.majorMinor version}/${pname}-${version}.tar.xz"; + sha256 = "Oksn3IAnzNYUZyWVAzbx7FIJKPMg8UTrX6eZCuYSOrQ="; + }; + in + { + setupPyBuildFlags = [ + "--libxml2-version=2.12.4" + "--libxslt-version=1.1.37" + "--zlib-version=1.3.1" + "--libiconv-version=1.17" + "--without-cython" + ]; + patches = [ + ./static/python311Packages-lxml.patch + # built without any extensions ... hardcoded with a patch + ]; + + STATICBUILD = true; + preConfigure = '' + mkdir -p ./libs + cp ${zlibSrc} ./libs/${zlibSrc.name} + cp ${libiconvSrc} ./libs/${libiconvSrc.name} + cp ${libxmlSrc} ./libs/${libxmlSrc.name} + cp ${libxsltSrc} ./libs/${libxsltSrc.name} + + ls ./libs + ''; + #cat ${libxsltSrc} | xz -d | gzip > ./libs/${libxsltSrc.name} + #cat ${libxmlSrc} | xz -d | gzip > ./libs/${libxmlSrc.name} + #mv ./libs/libxslt-1.1.37.tar.xz ./libs/libxslt-1.1.37.tar.gz + #mv ./libs/libxml2-2.10.4.tar.xz ./libs/libxml2-2.10.4.tar.gz + }); + }; + + pkgsStatic = prev.pkgsStatic // { + libglvnd = prev.libglvnd; + gonme2.libIDL = prev.gnome2.libIDL; + libjpeg-turbe = prev.libjpeg-turbo; + }; +} + +