Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

freebsd: various new packages to support a NixBSD system #320475

Merged
merged 65 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
77177e3
freebsd.sysctl: init
rhelmot Jun 7, 2024
c171489
freebsd.top: init
rhelmot Jun 7, 2024
b51604a
freebsd.mount: init
rhelmot Jun 7, 2024
27b9567
freebsd.nscd: init
rhelmot Jun 7, 2024
d942e3f
freebsd.pwd_mkdb: init
rhelmot Jun 7, 2024
c9b08ff
freebsd.getent: init
rhelmot Jun 7, 2024
a20e099
freebsd.getty: init
rhelmot Jun 7, 2024
7ada439
freebsd.cap_mkdb: init
rhelmot Jun 7, 2024
6e52c40
freebsd.libpam: init
rhelmot Jun 7, 2024
4fdc9f9
freebsd.libbsm: init
rhelmot Jun 7, 2024
d58f00e
freebsd.libradius: init
rhelmot Jun 7, 2024
b85f78b
freebsd.login: init
rhelmot Jun 7, 2024
95bed7c
freebsd.rc: init
rhelmot Jun 7, 2024
a25eb64
freebsd.rcorder: init
rhelmot Jun 7, 2024
22a4ba4
freebsd.protect: init
rhelmot Jun 7, 2024
f80a34d
freebsd.id: init
rhelmot Jun 7, 2024
c94a2a2
freebsd.limits: init
rhelmot Jun 7, 2024
54f1777
freebsd.mount_msdosfs: init
rhelmot Jun 7, 2024
8479282
freebsd.libkiconv: init
rhelmot Jun 7, 2024
80e3eca
freebsd.route: init
rhelmot Jun 7, 2024
9f84814
freebsd.ifconfig: init
rhelmot Jun 7, 2024
a03b493
freebsd.lib80211: init
rhelmot Jun 7, 2024
64e36d5
freebsd.libbsdxml: init
rhelmot Jun 7, 2024
cc86fcb
freebsd.libifconfig: init
rhelmot Jun 7, 2024
b9f1c7e
freebsd.newsyslog: init
rhelmot Jun 7, 2024
70236c2
freebsd.daemon: init
rhelmot Jun 7, 2024
f3c9e4a
freebsd.shutdown: init
rhelmot Jun 7, 2024
1185d75
freebsd.syslogd: init
rhelmot Jun 7, 2024
352259d
freebsd.services_mkdb: init
rhelmot Jun 7, 2024
7627bc4
freebsd.truss: init
rhelmot Jun 7, 2024
901f831
freebsd.libsysdecode: init
rhelmot Jun 7, 2024
06d2cdb
freebsd.bsdlabel: init
rhelmot Jun 7, 2024
afee073
freebsd.libgeom: init
rhelmot Jun 7, 2024
57cc0fb
freebsd.devfs: init
rhelmot Jun 7, 2024
16cad24
freebsd.dmesg: init
rhelmot Jun 7, 2024
cbc6f47
freebsd.fdisk: init
rhelmot Jun 7, 2024
39fe4cf
freebsd.geom: init
rhelmot Jun 7, 2024
20cf5fb
freebsd.libufs: init
rhelmot Jun 7, 2024
d7fc1a6
freebsd.kldconfig: init
rhelmot Jun 7, 2024
e310298
freebsd.kldload: init
rhelmot Jun 7, 2024
d542659
freebsd.kldstat: init
rhelmot Jun 7, 2024
15a263f
freebsd.kldunload: init
rhelmot Jun 7, 2024
2b7f6d3
freebsd.mdconfig: init
rhelmot Jun 7, 2024
256fe4a
freebsd.newfs: init
rhelmot Jun 7, 2024
55c787a
freebsd.newfs_msdos: init
rhelmot Jun 7, 2024
a46e74f
freebsd.ping: init
rhelmot Jun 7, 2024
4b76aee
freebsd.libipsec: init
rhelmot Jun 7, 2024
e87b4f2
freebsd.reboot: init
rhelmot Jun 7, 2024
2da43c3
freebsd.swapon: init
rhelmot Jun 7, 2024
8330c89
freebsd.zfs: init
rhelmot Jun 7, 2024
be96ca6
freebsd.zfs-data: init
rhelmot Jun 7, 2024
d651bd6
freebsd.libzfs: init
rhelmot Jun 7, 2024
bf35a20
freebsd.fsck: init
rhelmot Jun 7, 2024
9fa145f
freebsd.drm-kmod: init
rhelmot Jun 7, 2024
693bccf
freebsd.drm-kmod-firmware: init
rhelmot Jun 7, 2024
8fd9a80
freebsd.bintrans: init
rhelmot Jun 7, 2024
37f5de0
freebsd.init: init
rhelmot Jun 7, 2024
6acde4a
freebsd.stand-efi: init
rhelmot Jun 7, 2024
d8eef12
freebsd.vtfontcvt: init
rhelmot Jun 7, 2024
f413ee7
freebsd.makefs: init
rhelmot Jun 7, 2024
256f8ff
freebsd.mkimg: init
rhelmot Jun 7, 2024
94880ca
freebsd.stat: disable tests
rhelmot Jun 7, 2024
8cd6273
freebsd: move filterPatches into freebsd-lib
rhelmot Jun 7, 2024
f0097d1
freebsd.sys: make patched source visible, fix build
rhelmot Jun 7, 2024
e589fdb
chore: Remove `with lib` from various freebsd packages
rhelmot Jul 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 66 additions & 1 deletion pkgs/os-specific/bsd/freebsd/lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{ version }:
{
version,
lib,
writeText,
}:

{
inherit version;
Expand All @@ -15,4 +19,65 @@
.${stdenv'.hostPlatform.parsed.cpu.name} or stdenv'.hostPlatform.parsed.cpu.name;

install-wrapper = builtins.readFile ../../lib/install-wrapper.sh;

# this function takes a list of patches and a list of paths and returns a list of derivations,
# one per file that is patched, containing the actual patch contents. This allows us to have
# extract only the patches that are relevant for a given subset of the source tree.
# note: the "list of patches" input can be a directory containing patch files, a path or a list of valid inputs to this argument, recursively.
filterPatches =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too long. Can it be at least documented?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does need documentation, but do note it is just being moved. I would be OK with that happening in a later PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an overview.

patches: paths:
let
isDir =
file:
let
base = baseNameOf file;
type = (builtins.readDir (dirOf file)).${base} or null;
in
file == /. || type == "directory";
consolidatePatches =
patches:
if (lib.isDerivation patches) then
[ patches ]
else if (builtins.isPath patches) then
(if (isDir patches) then (lib.filesystem.listFilesRecursive patches) else [ patches ])
else if (builtins.isList patches) then
(lib.flatten (builtins.map consolidatePatches patches))
else
throw "Bad patches - must be path or derivation or list thereof";
consolidated = consolidatePatches patches;
splitPatch =
patchFile:
let
allLines' = lib.strings.splitString "\n" (builtins.readFile patchFile);
allLines = builtins.filter (
line: !((lib.strings.hasPrefix "diff --git" line) || (lib.strings.hasPrefix "index " line))
) allLines';
foldFunc =
a: b:
if ((lib.strings.hasPrefix "--- " b) || (lib.strings.hasPrefix "diff --git " b)) then
(a ++ [ [ b ] ])
else
((lib.lists.init a) ++ (lib.lists.singleton ((lib.lists.last a) ++ [ b ])));
partitionedPatches' = lib.lists.foldl foldFunc [ [ ] ] allLines;
partitionedPatches =
if (builtins.length partitionedPatches' > 1) then
(lib.lists.drop 1 partitionedPatches')
else
(throw "${patchFile} does not seem to be a unified patch (diff -u). this is required for FreeBSD.");
filterFunc =
patchLines:
let
prefixedPath = builtins.elemAt (builtins.split " |\t" (builtins.elemAt patchLines 1)) 2;
unfixedPath = lib.path.subpath.join (lib.lists.drop 1 (lib.path.subpath.components prefixedPath));
in
lib.lists.any (included: lib.path.hasPrefix (/. + ("/" + included)) (/. + ("/" + unfixedPath))) (
paths
);
filteredLines = builtins.filter filterFunc partitionedPatches;
derive = patchLines: writeText "freebsd-patch" (lib.concatLines patchLines);
derivedPatches = builtins.map derive filteredLines;
in
derivedPatches;
in
lib.lists.concatMap splitPatch consolidated;
}
2 changes: 2 additions & 0 deletions pkgs/os-specific/bsd/freebsd/package-set.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
versionData,
buildFreebsd,
patchesRoot,
writeText,
}:

self:
Expand Down Expand Up @@ -39,6 +40,7 @@ lib.packagesFromDirectoryRecursive {
]
)
);
inherit lib writeText;
};

# The manual callPackages below should in principle be unnecessary, but are
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/lib/libifconfig/Makefile b/lib/libifconfig/Makefile
index 6bdb202bec1d..ebc626901cfc 100644
--- a/lib/libifconfig/Makefile
+++ b/lib/libifconfig/Makefile
@@ -1,7 +1,6 @@

PACKAGE= lib${LIB}
LIB= ifconfig
-INTERNALLIB= true

LIBADD= m

@@ -36,8 +35,8 @@ SRCS+= ${GEN}
CLEANFILES+= ${GEN}

# If libifconfig become public uncomment those two lines
-#INCSDIR= ${INCLUDEDIR}
-#INCS= libifconfig.h libifconfig_sfp.h libifconfig_sfp_tables.h
+INCSDIR= ${INCLUDEDIR}
+INCS= libifconfig.h libifconfig_sfp.h libifconfig_sfp_tables.h

#MAN= libifconfig.3

diff --git a/lib/libifconfig/Symbol.map b/lib/libifconfig/Symbol.map
index 2d80fb31652a..8b08947112e5 100644
--- a/lib/libifconfig/Symbol.map
+++ b/lib/libifconfig/Symbol.map
@@ -2,6 +2,8 @@ FBSD_1.6 {
ifconfig_bridge_get_bridge_status;
ifconfig_bridge_free_bridge_status;
ifconfig_carp_get_info;
+ ifconfig_carp_get_vhid;
+ ifconfig_carp_set_info;
ifconfig_close;
ifconfig_create_interface;
ifconfig_create_interface_vlan;
18 changes: 18 additions & 0 deletions pkgs/os-specific/bsd/freebsd/patches/14.0/mount-use-path.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c
index 2fcc94e40818..7de6da1bb20e 100644
--- a/sbin/mount/mount.c
+++ b/sbin/mount/mount.c
@@ -155,12 +155,9 @@ exec_mountprog(const char *name, const char *execname, char *const argv[])
EXIT(1);
case 0: /* Child. */
/* Go find an executable. */
- execvP(execname, _PATH_SYSPATH, argv);
+ execvp(execname, argv);
if (errno == ENOENT) {
xo_warn("exec %s not found", execname);
- if (execname[0] != '/') {
- xo_warnx("in path: %s", _PATH_SYSPATH);
- }
}
EXIT(1);
default: /* Parent. */
17 changes: 17 additions & 0 deletions pkgs/os-specific/bsd/freebsd/patches/14.0/rc-user.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/libexec/rc/rc b/libexec/rc/rc
index 0ea61a4b2c0a..d9bfb228224c 100644
--- a/libexec/rc/rc
+++ b/libexec/rc/rc
@@ -87,6 +87,12 @@ if ! [ -e ${firstboot_sentinel} ]; then
skip_firstboot="-s firstboot"
fi

+if [ -z "$USER_LOGIN" ]; then
+ skip="$skip -s user"
+else
+ skip="$skip -k user"
+fi
+
# Do a first pass to get everything up to $early_late_divider so that
# we can do a second pass that includes $local_startup directories
#
5 changes: 5 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/bintrans.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{ mkDerivation }:
mkDerivation {
path = "usr.bin/bintrans";
MK_TESTS = "no";
}
6 changes: 6 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/bsdlabel.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ mkDerivation, libgeom }:
mkDerivation {
path = "sbin/bsdlabel";
extraPaths = [ "sys/geom" ];
buildInputs = [ libgeom ];
}
6 changes: 6 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/cap_mkdb.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ mkDerivation }:
mkDerivation {
path = "usr.bin/cap_mkdb";

MK_TESTS = "no";
}
5 changes: 5 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/daemon.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{ mkDerivation }:
mkDerivation {
path = "usr.sbin/daemon";
MK_TESTS = "no";
}
10 changes: 10 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/devfs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ mkDerivation }:
mkDerivation {
path = "sbin/devfs";

# These config files are mostly examples and not super useful
# in nixbsd
postPatch = ''
sed -i 's/^CONFS=.*$//' $BSDSRCDIR/sbin/devfs/Makefile
'';
}
6 changes: 6 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/dmesg.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ mkDerivation, lib }:
mkDerivation {
path = "sbin/dmesg";

meta.platforms = lib.platforms.freebsd;
}
54 changes: 54 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/drm-kmod-firmware.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
lib,
mkDerivation,
fetchFromGitHub,
buildFreebsd,
sys,
withAmd ? true,
withIntel ? true,
}:
mkDerivation rec {
pname =
"drm-kmod-firmware" + lib.optionalString withAmd "-amd" + lib.optionalString withIntel "-intel";

version = "20230625_8";

src = fetchFromGitHub {
owner = "freebsd";
repo = "drm-kmod-firmware";
rev = version;
hash = "sha256-Ly9B0zf+YODel/X1sZYVVUVWh38faNLhkcXcjEnQwII=";
};

extraNativeBuildInputs = [ buildFreebsd.xargs-j ];

hardeningDisable = [
"pic" # generates relocations the linker can't handle
"stackprotector" # generates stack protection for the function generating the stack canary
];

# hardeningDisable = stackprotector doesn't seem to be enough, put it in cflags too
NIX_CFLAGS_COMPILE = "-fno-stack-protector";

KMODS =
lib.optional withIntel "i915kmsfw"
++ lib.optionals withAmd [
"amdgpukmsfw"
"radeonkmsfw"
];

env = sys.passthru.env;
SYSDIR = "${sys.src}/sys";

KMODDIR = "${builtins.placeholder "out"}/kernel";

meta = {
description = "GPU firmware for FreeBSD drm-kmod";
platforms = lib.platforms.freebsd;
license =
lib.optional withAmd lib.licenses.unfreeRedistributableFirmware
# Intel license prohibits modification. this will wrap firmware files in an ELF
++ lib.optional withIntel lib.licenses.unfree;
sourceProvenance = [ lib.sourceTypes.binaryFirmware ];
};
}
53 changes: 53 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/drm-kmod/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
lib,
mkDerivation,
fetchFromGitHub,
xargs-j,
versionData,
sys,
}:
let
# Based off ports tree versions
reldate = lib.toIntBase10 versionData.reldate;
branch =
if reldate >= 1500008 then
"6.1-lts"
else if reldate >= 1400097 then
"5.15-lts"
else if reldate >= 1302000 then
"5.10-lts"
else
throw "drm-kmod not supported on FreeBSD version ${reldate}";

fetchOptions = (lib.importJSON ./versions.json).${branch};
in
mkDerivation {
pname = "drm-kmod";
version = branch;

src = fetchFromGitHub fetchOptions;

extraNativeBuildInputs = [ xargs-j ];

hardeningDisable = [
"pic" # generates relocations the linker can't handle
"stackprotector" # generates stack protection for the function generating the stack canary
];

# hardeningDisable = stackprotector doesn't seem to be enough, put it in cflags too
NIX_CFLAGS_COMPILE = "-fno-stack-protector";

env = sys.passthru.env;
SYSDIR = "${sys.src}/sys";

KMODDIR = "${builtins.placeholder "out"}/kernel";

meta = {
description = "Linux drm driver, ported to FreeBSD";
platforms = lib.platforms.freebsd;
license = with lib.licenses; [
bsd2
gpl2Only
];
};
}
rhelmot marked this conversation as resolved.
Show resolved Hide resolved
21 changes: 21 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/drm-kmod/update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env nix-shell
#!nix-shell -i python -p python3 nix-prefetch-github git

import subprocess
import json
import os.path

BRANCHES = ["5.10-lts", "5.15-lts", "6.1-lts"]
BASE_DIR = os.path.dirname(os.path.abspath(__file__))

versions = dict()

for branch in BRANCHES:
text = subprocess.check_output(
["nix-prefetch-github", "freebsd", "drm-kmod", "--rev", branch, "--json"]
).decode("utf-8")
versions[branch] = json.loads(text)

with open(os.path.join(BASE_DIR, "versions.json"), "w") as out:
json.dump(versions, out, sort_keys=True, indent=2)
out.write("\n")
20 changes: 20 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/drm-kmod/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"5.10-lts": {
"hash": "sha256-6v8FhaEch9fJfo0/1UXeo0bcZh5n4Y2TyAsyHmCBJgw=",
"owner": "freebsd",
"repo": "drm-kmod",
"rev": "e7950546196d44af502dd6abf162d1453f6f0dd0"
},
"5.15-lts": {
"hash": "sha256-i768QfnYo2hqxnoCEnfYqOurDSRwkAsC4qsP7TUalxc=",
"owner": "freebsd",
"repo": "drm-kmod",
"rev": "d7dc64fb8e63208afaca01e6d48284aa2305df35"
},
"6.1-lts": {
"hash": "sha256-+CsqQ0beJgoO3SSWzwLcAO8JP15oaDW9HR+bxwPaan4=",
"owner": "freebsd",
"repo": "drm-kmod",
"rev": "f2d6d4b58446fa45de575bae76d6435439b3ca8b"
}
}
6 changes: 6 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/fdisk.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ mkDerivation, libgeom }:
mkDerivation {
path = "sbin/fdisk";

buildInputs = [ libgeom ];
}
5 changes: 5 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/fsck.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{ mkDerivation }:
mkDerivation {
path = "sbin/fsck";
extraPaths = [ "sbin/mount" ];
}
Loading