Unverified Commit 469e4097 authored by John Ericson's avatar John Ericson Committed by GitHub
Browse files

Merge pull request #308138 from rhelmot/freebsd-minimal2/multiple-package-sets

freebsd: Separate package set contents from construction
parents 791e0503 571f390d
Loading
Loading
Loading
Loading
+57 −65
Original line number Diff line number Diff line
{ stdenv, lib, stdenvNoCC
, makeScopeWithSplicing', generateSplicesForMkScope
, buildPackages
, fetchgit, fetchzip
{
  lib,
  makeScopeWithSplicing',
  generateSplicesForMkScope,
  callPackage,
  crossLibcStdenv,
  attributePathToSplice ? [ "freebsd" ],
  branch ? "release/13.1.0",
}:

let
  inherit (buildPackages.buildPackages) rsync;

  versions = builtins.fromJSON (builtins.readFile ./versions.json);

  version = "13.1.0";
  branch = "release/${version}";

in makeScopeWithSplicing' {
  otherSplices = generateSplicesForMkScope "freebsd";
  f = (self: lib.packagesFromDirectoryRecursive {
    callPackage = self.callPackage;
    directory = ./pkgs;
  } // {
    sourceData = versions.${branch};

    ports = fetchzip {
      url = "https://cgit.freebsd.org/ports/snapshot/ports-dde3b2b456c3a4bdd217d0bf3684231cc3724a0a.tar.gz";
      sha256 = "BpHqJfnGOeTE7tkFJBx0Wk8ryalmf4KNTit/Coh026E=";
    };

    compatIfNeeded = lib.optional (!stdenvNoCC.hostPlatform.isFreeBSD) self.compat;
    freebsd-lib = import ./lib { inherit version; };

    # The manual callPackages below should in principle be unnecessary, but are
    # necessary. See note in ../netbsd/default.nix

    compat = self.callPackage ./pkgs/compat/package.nix {
      inherit stdenv;
      inherit (buildPackages.freebsd) makeMinimal boot-install;
    };

    csu = self.callPackage ./pkgs/csu.nix {
      inherit (buildPackages.freebsd) makeMinimal install gencat;
      inherit (self) include;
    };

    include = self.callPackage ./pkgs/include/package.nix {
      inherit (buildPackages.freebsd) makeMinimal install rpcgen;
    };

    install = self.callPackage ./pkgs/install.nix {
      inherit (buildPackages.freebsd) makeMinimal;
      inherit (self) mtree libnetbsd;
    };

    libc = self.callPackage ./pkgs/libc/package.nix {
      inherit (buildPackages.freebsd) makeMinimal install gencat rpcgen;
      inherit (self) csu include;
    };

    libnetbsd = self.callPackage ./pkgs/libnetbsd/package.nix {
      inherit (buildPackages.freebsd) makeMinimal;
    };

    mkDerivation = self.callPackage ./pkgs/mkDerivation.nix {
      inherit stdenv;
      inherit (buildPackages.freebsd) makeMinimal install tsort;
    };

    makeMinimal = self.callPackage ./pkgs/makeMinimal.nix {
      inherit (self) make;
  badBranchError =
    branch:
    throw ''
      Unknown FreeBSD branch ${branch}!
      FreeBSD branches normally look like one of:
      * `release/<major>.<minor>.0` for tagged releases without security updates
      * `releng/<major>.<minor>` for release update branches with security updates
      * `stable/<major>` for stable versions working towards the next minor release
      * `main` for the latest development version

      Branches can be selected by overriding the `branch` attribute on the freebsd package set.
    '';

  # `./package-set.nix` should never know the name of the package set we
  # are constructing; just this function is allowed to know that. This
  # is why we:
  #
  #  - do the splicing for cross compilation here
  #
  #  - construct the *anonymized* `buildFreebsd` attribute to be passed
  #    to `./package-set.nix`.
  callFreeBSDWithAttrs =
    extraArgs:
    let
      # we do not include the branch in the splice here because the branch
      # parameter to this file will only ever take on one value - more values
      # are provided through overrides.
      otherSplices = generateSplicesForMkScope attributePathToSplice;
    in
    makeScopeWithSplicing' {
      inherit otherSplices;
      f =
        self:
        {
          inherit branch;
        }
        // callPackage ./package-set.nix (
          {
            sourceData = versions.${self.branch} or (throw (badBranchError self.branch));
            versionData = self.sourceData.version;
            buildFreebsd = otherSplices.selfBuildHost;
            patchesRoot = ./patches/${self.versionData.revision};
          }
          // extraArgs
        ) self;
    };

  });
in
{
  freebsd = callFreeBSDWithAttrs { };
  freebsdCross = callFreeBSDWithAttrs { stdenv = crossLibcStdenv; };
}
+71 −0
Original line number Diff line number Diff line
{ stdenv, lib, stdenvNoCC
, fetchzip
, sourceData, versionData, buildFreebsd, patchesRoot
}:

self:

lib.packagesFromDirectoryRecursive {
  callPackage = self.callPackage;
  directory = ./pkgs;
} // {
  inherit sourceData patchesRoot versionData;

  # Keep the crawled portion of Nixpkgs finite.
  buildFreebsd = lib.dontRecurseIntoAttrs buildFreebsd;

  ports = fetchzip {
    url = "https://cgit.freebsd.org/ports/snapshot/ports-dde3b2b456c3a4bdd217d0bf3684231cc3724a0a.tar.gz";
    sha256 = "BpHqJfnGOeTE7tkFJBx0Wk8ryalmf4KNTit/Coh026E=";
  };

  compatIfNeeded = lib.optional (!stdenvNoCC.hostPlatform.isFreeBSD) self.compat;
  freebsd-lib = import ./lib {
    version = lib.concatStringsSep "." (map toString (lib.filter (x: x != null) [
      self.versionData.major
      self.versionData.minor
      self.versionData.patch or null
    ]));
  };

  # The manual callPackages below should in principle be unnecessary, but are
  # necessary. See note in ../netbsd/default.nix

  compat = self.callPackage ./pkgs/compat/package.nix {
    inherit stdenv;
    inherit (buildFreebsd) makeMinimal boot-install;
  };

  csu = self.callPackage ./pkgs/csu.nix {
    inherit (buildFreebsd) makeMinimal install gencat;
    inherit (self) include;
  };

  include = self.callPackage ./pkgs/include/package.nix {
    inherit (buildFreebsd) makeMinimal install rpcgen;
  };

  install = self.callPackage ./pkgs/install.nix {
    inherit (buildFreebsd) makeMinimal;
    inherit (self) mtree libnetbsd;
  };

  libc = self.callPackage ./pkgs/libc/package.nix {
    inherit (buildFreebsd) makeMinimal install gencat rpcgen;
    inherit (self) csu include;
  };

  libnetbsd = self.callPackage ./pkgs/libnetbsd/package.nix {
    inherit (buildFreebsd) makeMinimal;
  };

  mkDerivation = self.callPackage ./pkgs/mkDerivation.nix {
    inherit stdenv;
    inherit (buildFreebsd) makeMinimal install tsort;
  };

  makeMinimal = self.callPackage ./pkgs/makeMinimal.nix {
    inherit (self) make;
  };

}
Loading