liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

overlay.nix (12753B)


      1 final: prev:
      2 let
      3   isCross = final.stdenv.buildPlatform != final.stdenv.hostPlatform;
      4   crossOnly = pkg: amendFn: if isCross then (amendFn pkg) else pkg;
      5   extraPkgs = import ./pkgs/default.nix {
      6     inherit (final) lib callPackage;
      7   };
      8   inherit (final) fetchpatch lib;
      9   luaHost =
     10     let
     11       l = prev.lua5_3.overrideAttrs (o: {
     12         name = "lua-tty";
     13         preBuild = ''
     14           makeFlagsArray+=(PLAT="posix" SYSLIBS="-Wl,-E -ldl"  CFLAGS="-O2 -fPIC -DLUA_USE_POSIX -DLUA_USE_DLOPEN")
     15         '';
     16         # lua in nixpkgs has a postInstall stanza that assumes only
     17         # one output, we need to override that if we're going to
     18         # convert to multi-output
     19         # outputs = ["bin" "man" "out"];
     20         makeFlags = builtins.filter (x: (builtins.match "(PLAT|MYLIBS).*" x) == null) o.makeFlags;
     21       });
     22     in
     23     l.override { self = l; };
     24 
     25   s6 = prev.s6.overrideAttrs (
     26     o:
     27     let
     28       patch = fetchpatch {
     29         # add "p" directive in s6-log
     30         url = "https://github.com/skarnet/s6/commit/ddc76841398dfd5e18b22943727ad74b880236d3.patch";
     31         hash = "sha256-fBtUinBdp5GqoxgF6fcR44Tu8hakxs/rOShhuZOgokc=";
     32       };
     33       patch_needed = builtins.compareVersions o.version "2.11.1.2" <= 0;
     34     in
     35     {
     36       configureFlags =
     37         (builtins.filter (x: (builtins.match ".*shared.*" x) == null) o.configureFlags)
     38         ++ [
     39           "--disable-allstatic"
     40           "--disable-static"
     41           "--enable-shared"
     42         ];
     43       hardeningDisable = [ "all" ];
     44       stripAllList = [
     45         "sbin"
     46         "bin"
     47       ];
     48       patches = (if o ? patches then o.patches else [ ]) ++ (if patch_needed then [ patch ] else [ ]);
     49     }
     50   );
     51 in
     52 extraPkgs
     53 // {
     54   # liminix library functions
     55   lim = {
     56     parseInt = s: (builtins.fromTOML "r=${s}").r;
     57     orEmpty = x: if x != null then x else [ ];
     58   };
     59 
     60   # keep these alphabetical
     61 
     62   btrfs-progs = crossOnly prev.btrfs-progs (
     63     d:
     64     d.override {
     65       udevSupport = false;
     66       udev = null;
     67     }
     68   );
     69 
     70   chrony =
     71     let
     72       chrony' = prev.chrony.overrideAttrs (o: {
     73         configureFlags = [
     74           "--chronyvardir=$(out)/var/lib/chrony"
     75           "--sbindir=$(out)/bin"
     76           "--chronyrundir=/run/chrony"
     77           "--disable-readline"
     78           "--disable-editline"
     79         ];
     80       });
     81     in
     82     chrony'.override {
     83       gnutls = null;
     84       libedit = null;
     85       libseccomp = null;
     86       libcap = null;
     87       # should texinfo be in nativeBuildInputs instead of
     88       # buildInputs?
     89       texinfo = null;
     90     }
     91     // lib.optionalAttrs (lib.versionOlder lib.version "24.10") {
     92       nss = null;
     93       nspr = null;
     94       readline = null;
     95     };
     96 
     97   # clevis without luks/tpm
     98   clevis = crossOnly prev.clevis (
     99     d:
    100     let
    101       c = d.overrideAttrs (o: {
    102         outputs = [ "out" ];
    103         preConfigure = ''
    104           rm -rf src/luks
    105           sed -i -e '/luks/d' src/meson.build
    106         '';
    107       });
    108     in
    109     c.override {
    110       asciidoc = null;
    111       cryptsetup = null;
    112       luksmeta = null;
    113       tpm2-tools = null;
    114     }
    115   );
    116 
    117   # luarocks wants a cross-compiled cmake (which seems like a bug,
    118   # we're never going to run luarocks on the device, but ...)
    119   # but https://github.com/NixOS/nixpkgs/issues/284734
    120   # so we do surgery on the cmake derivation until that's fixed
    121 
    122   cmake = crossOnly prev.cmake (
    123     d:
    124     d.overrideAttrs (o: {
    125       preConfigure =
    126         builtins.replaceStrings [ "$configureFlags" ] [ "$configureFlags $cmakeFlags" ]
    127           o.preConfigure;
    128     })
    129   );
    130 
    131   dnsmasq =
    132     let
    133       d = prev.dnsmasq.overrideAttrs (o: {
    134         preBuild = ''
    135           makeFlagsArray=("COPTS=")
    136         '';
    137       });
    138     in
    139     d.override {
    140       dbusSupport = false;
    141       nettle = null;
    142     };
    143 
    144   dropbear = crossOnly prev.dropbear (
    145     d:
    146     d.overrideAttrs (o: rec {
    147       # nixpkgs 25.05 contains newer dropbear (2025.87) than this,
    148       # we can drop this override when that's ready
    149       version = "2024.85";
    150       src = final.fetchurl {
    151         url = "https://matt.ucc.asn.au/dropbear/releases/dropbear-${version}.tar.bz2";
    152         sha256 = "sha256-hrA2xDOmnYnOUeuuM11lxHc4zPkNE+XrD+qDLlVtpQI=";
    153       };
    154       patches =
    155         # in 24.11 we need to update nixpkgs patch for new version of dropbear
    156         let
    157           passPath = final.runCommand "pass-path" { } ''
    158             sed < ${builtins.head o.patches} -e 's,svr-chansession.c,src/svr-chansession.c,g' > $out
    159           '';
    160         in
    161         [
    162           (if (lib.versionOlder o.version "2024") then passPath else (builtins.head o.patches))
    163           ./pkgs/dropbear/add-authkeyfile-option.patch
    164         ];
    165       postPatch = ''
    166         (echo '#define DSS_PRIV_FILENAME "/run/dropbear/dropbear_dss_host_key"'
    167          echo '#define RSA_PRIV_FILENAME "/run/dropbear/dropbear_rsa_host_key"'
    168          echo '#define ECDSA_PRIV_FILENAME "/run/dropbear/dropbear_ecdsa_host_key"'
    169          echo '#define ED25519_PRIV_FILENAME "/run/dropbear/dropbear_ed25519_host_key"') > localoptions.h
    170       '';
    171     })
    172   );
    173 
    174   elfutils = crossOnly prev.elfutils (
    175     d:
    176     let
    177       e = d.overrideAttrs (o: {
    178         configureFlags = o.configureFlags ++ [
    179           "ac_cv_has_stdatomic=no"
    180         ];
    181       });
    182     in
    183     e.override {
    184       enableDebuginfod = false;
    185     }
    186   );
    187 
    188   hostapd =
    189     let
    190       config = [
    191         "CONFIG_DRIVER_NL80211=y"
    192         "CONFIG_IAPP=y"
    193         "CONFIG_IEEE80211AC=y"
    194         "CONFIG_IEEE80211AX=y"
    195         "CONFIG_IEEE80211N=y"
    196         "CONFIG_IEEE80211W=y"
    197         "CONFIG_INTERNAL_LIBTOMMATH=y"
    198         "CONFIG_INTERNAL_LIBTOMMATH_FAST=y"
    199         "CONFIG_IPV6=y"
    200         "CONFIG_LIBNL32=y"
    201         "CONFIG_PKCS12=y"
    202         "CONFIG_RSN_PREAUTH=y"
    203         "CONFIG_TLS=internal"
    204       ];
    205       h = prev.hostapd.overrideAttrs (o: {
    206         extraConfig = "";
    207         configurePhase = ''
    208           cat > hostapd/defconfig <<EOF
    209           ${builtins.concatStringsSep "\n" config}
    210           EOF
    211           ${o.configurePhase}
    212         '';
    213       });
    214     in
    215     h.override {
    216       openssl = null;
    217       sqlite = null;
    218     };
    219 
    220   # berlekey db needs libatomic which we haven't figured out yet.
    221   # disabling it means we don't have arpd
    222   iproute2 = crossOnly prev.iproute2 (d: d.override { db = null; });
    223 
    224   kexec-tools-static = prev.kexec-tools.overrideAttrs (o: {
    225     # For kexecboot we copy kexec into a ramdisk on the system being
    226     # upgraded from. This is more likely to work if kexec is
    227     # statically linked so doesn't have dependencies on store paths that
    228     # may not exist on that machine. (We can't nix-copy-closure as
    229     # the store may not be on a writable filesystem)
    230     LDFLAGS = "-static";
    231 
    232     patches = o.patches ++ [
    233       (fetchpatch {
    234         # merge user command line options into DTB chosen
    235         url = "https://patch-diff.githubusercontent.com/raw/horms/kexec-tools/pull/3.patch";
    236         hash = "sha256-MvlJhuex9dlawwNZJ1sJ33YPWn1/q4uKotqkC/4d2tk=";
    237       })
    238       pkgs/kexec-map-file.patch
    239     ];
    240   });
    241 
    242   libadwaita =  prev.libadwaita.overrideAttrs(o: {
    243     # tests fail with a message
    244     # Gdk-DEBUG: error: XDG_RUNTIME_DIR is invalid or not set in the environment.
    245     doCheck = false;
    246   });
    247 
    248   lua = crossOnly prev.lua5_3 (_: luaHost);
    249 
    250   luaossl' = luaHost.pkgs.luaossl.overrideAttrs (o: {
    251     patches = [
    252       (fetchpatch {
    253         url = "https://patch-diff.githubusercontent.com/raw/wahern/luaossl/pull/218.patch";
    254         hash = "sha256-2GOliY4/RUzOgx3rqee3X3szCdUVxYDut7d+XFcUTJw=";
    255       })
    256     ] ++ final.lib.optionals (o ? patches) o.patches;
    257   });
    258 
    259   mtdutils =
    260     (prev.mtdutils.overrideAttrs (o: {
    261 
    262       src =  final.fetchgit {
    263         url = "git://git.infradead.org/mtd-utils.git";
    264         rev  = "77981a2888c711268b0e7f32af6af159c2288e23";
    265         hash = "sha256-pHunlPOuvCRyyk9qAiR3Kn3cqS/nZHIxsv6m4nsAcbk=";
    266       };
    267 
    268       patches = (if o ? patches then o.patches else [ ]) ++ [
    269         ./pkgs/mtdutils/0001-mkfs.jffs2-add-graft-option.patch
    270       ];
    271     })).override
    272       { util-linux = final.util-linux-small; };
    273 
    274   nftables = prev.nftables.overrideAttrs (o: {
    275     configureFlags = [
    276       "--disable-debug"
    277       "--disable-python"
    278       "--with-mini-gmp"
    279       "--without-cli"
    280     ];
    281   });
    282 
    283   openssl = crossOnly prev.openssl (
    284     d:
    285     d.overrideAttrs (
    286       o: with final; {
    287         # we want to apply
    288         # https://patch-diff.githubusercontent.com/raw/openssl/openssl/pull/20273.patch";
    289         # which disables overriding the -march cflags to the wrong values,
    290         # but openssl is used for bootstrapping so that's easier said than
    291         # done. Do it the ugly way..
    292         postPatch =
    293           o.postPatch
    294           + ''
    295             sed -i.bak 's/linux.*-mips/linux-mops/' Configure
    296           '';
    297         # openssl with threads requires stdatomic which drags in libgcc
    298         # as a dependency
    299         configureFlags = [ "no-threads" ] ++ o.configureFlags;
    300 
    301         # don't need or want this bash script
    302         postInstall = o.postInstall + "rm $bin/bin/c_rehash\n";
    303       }
    304     )
    305   );
    306 
    307   pppBuild = prev.ppp;
    308 
    309   qemuLim =
    310     let
    311       inherit (final) lib;
    312       q = prev.qemu.overrideAttrs (o: {
    313         patches = o.patches ++ [
    314           ./pkgs/qemu/arm-image-friendly-load-addr.patch
    315           (final.fetchpatch {
    316             url = "https://lore.kernel.org/qemu-devel/20220322154658.1687620-1-raj.khem@gmail.com/raw";
    317             hash = "sha256-jOsGka7xLkJznb9M90v5TsJraXXTAj84lcphcSxjYLU=";
    318           })
    319         ];
    320         buildInputs = o.buildInputs ++ [ final.libslirp ];
    321       });
    322       overrides =
    323         {
    324           hostCpuTargets = map (f: "${f}-softmmu") [
    325             "arm"
    326             "aarch64"
    327             "mips"
    328             "mipsel"
    329           ];
    330           sdlSupport = false;
    331           numaSupport = false;
    332           seccompSupport = false;
    333           usbredirSupport = false;
    334           libiscsiSupport = false;
    335           tpmSupport = false;
    336           uringSupport = false;
    337           capstoneSupport = false;
    338         }
    339         // lib.optionalAttrs (lib.versionOlder lib.version "24.10") {
    340           texinfo = null;
    341           nixosTestRunner = true;
    342         }
    343         // lib.optionalAttrs (lib.versionAtLeast lib.version "25.04") {
    344           minimal = true;
    345         };
    346     in
    347     q.override overrides;
    348   rsyncSmall =
    349     let
    350       r = prev.rsync.overrideAttrs (o: {
    351         configureFlags = o.configureFlags ++ [ "--disable-openssl" ];
    352       });
    353     in
    354     r.override { openssl = null; };
    355 
    356   inherit s6;
    357   s6-linux-init = prev.s6-linux-init.override {
    358     skawarePackages = prev.skawarePackages // {
    359       inherit s6;
    360     };
    361   };
    362   s6-rc = prev.s6-rc.override {
    363     skawarePackages = prev.skawarePackages // {
    364       inherit s6;
    365     };
    366   };
    367 
    368   strace = prev.strace.override { libunwind = null; };
    369 
    370   ubootQemuAarch64 = final.buildUBoot {
    371     defconfig = "qemu_arm64_defconfig";
    372     extraMeta.platforms = [ "aarch64-linux" ];
    373     filesToInstall = [ "u-boot.bin" ];
    374   };
    375 
    376   ubootQemuArm = final.buildUBoot {
    377     defconfig = "qemu_arm_defconfig";
    378     extraMeta.platforms = [ "armv7l-linux" ];
    379     filesToInstall = [ "u-boot.bin" ];
    380     extraConfig = ''
    381       CONFIG_CMD_UBI=y
    382       CONFIG_CMD_UBIFS=y
    383       CONFIG_BOOTSTD=y
    384       CONFIG_BOOTMETH_DISTRO=y
    385       CONFIG_LZMA=y
    386       CONFIG_CMD_LZMADEC=y
    387       CONFIG_SYS_BOOTM_LEN=0x1000000
    388     '';
    389   };
    390 
    391   ubootQemuMips = final.buildUBoot {
    392     defconfig = "malta_defconfig";
    393     extraMeta.platforms = [ "mips-linux" ];
    394     filesToInstall = [ "u-boot.bin" ];
    395     # define the prompt to be the same as arm{32,64} so
    396     # we can use the same expect script for both
    397     extraPatches = [ ./pkgs/u-boot/0002-virtio-init-for-malta.patch ];
    398     extraConfig = ''
    399       CONFIG_SYS_PROMPT="=> "
    400       CONFIG_VIRTIO=y
    401       CONFIG_AUTOBOOT=y
    402       CONFIG_DM_PCI=y
    403       CONFIG_VIRTIO_PCI=y
    404       CONFIG_VIRTIO_NET=y
    405       CONFIG_VIRTIO_BLK=y
    406       CONFIG_VIRTIO_MMIO=y
    407       CONFIG_QFW_MMIO=y
    408       CONFIG_FIT=y
    409       CONFIG_LZMA=y
    410       CONFIG_CMD_LZMADEC=y
    411       CONFIG_SYS_BOOTM_LEN=0x1000000
    412       CONFIG_SYS_MALLOC_LEN=0x400000
    413       CONFIG_MIPS_BOOT_FDT=y
    414       CONFIG_OF_LIBFDT=y
    415       CONFIG_OF_STDOUT_VIA_ALIAS=y
    416     '';
    417   };
    418 
    419   libusb1 = crossOnly prev.libusb1 (
    420     d:
    421     let
    422       u = d.overrideAttrs (o: {
    423         # don't use gcc libatomic because it vastly increases the
    424         # closure size
    425         preConfigure = "sed -i.bak /__atomic_fetch_add_4/c\: configure.ac";
    426       });
    427     in
    428     u.override {
    429       enableUdev = false;
    430       withDocs = false;
    431     }
    432   );
    433 
    434   util-linux-small = prev.util-linux.override {
    435     ncursesSupport = false;
    436     pamSupport = false;
    437     systemdSupport = false;
    438     nlsSupport = false;
    439     translateManpages = false;
    440     capabilitiesSupport = false;
    441   };
    442 
    443   xl2tpd = prev.xl2tpd.overrideAttrs (o: {
    444     patches = [ ./pkgs/xl2tpd-exit-on-close.patch ];
    445   });
    446 }