From 8b08408e9794f94e932b9cfd844c1d14dabdf2b8 Mon Sep 17 00:00:00 2001 From: Audrey Dutcher Date: Sat, 30 Nov 2024 00:44:02 -0700 Subject: [PATCH] openbsd.makedev: init MAKEDEV is a shell script that can generate OpenBSD device nodes. It is useful on an OpenBSD system for disaster recovery and also on a non-OpenBSD system for cross-compilation. --- .../bsd/openbsd/pkgs/makedev/bash.patch | 18 +++++++++ .../bsd/openbsd/pkgs/makedev/package.nix | 37 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 pkgs/os-specific/bsd/openbsd/pkgs/makedev/bash.patch create mode 100644 pkgs/os-specific/bsd/openbsd/pkgs/makedev/package.nix diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/makedev/bash.patch b/pkgs/os-specific/bsd/openbsd/pkgs/makedev/bash.patch new file mode 100644 index 000000000000..06993c0066d7 --- /dev/null +++ b/pkgs/os-specific/bsd/openbsd/pkgs/makedev/bash.patch @@ -0,0 +1,18 @@ +diff --git a/etc/MAKEDEV.common b/etc/MAKEDEV.common +index 1e7bb3d235a..1cc64a38985 100644 +--- a/etc/MAKEDEV.common ++++ b/etc/MAKEDEV.common +@@ -315,10 +315,10 @@ _mkdev(pty, pty*, {-if [ $U -gt 15 ]; then + echo bad unit for pty in: $i + continue + fi +- set -A letters p q r s t u v w x y z P Q R S T +- set -A suffixes 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q \ ++ letters=(p q r s t u v w x y z P Q R S T) ++ suffixes=(0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q \ + r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X \ +- Y Z ++ Y Z) + + name=${letters[$U]} + n=0 diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/makedev/package.nix b/pkgs/os-specific/bsd/openbsd/pkgs/makedev/package.nix new file mode 100644 index 000000000000..48f5b7176b20 --- /dev/null +++ b/pkgs/os-specific/bsd/openbsd/pkgs/makedev/package.nix @@ -0,0 +1,37 @@ +{ + mkDerivation, + runtimeShell, + m4, +}: + +mkDerivation { + pname = "MAKEDEV"; + path = "etc"; + + patches = [ ./bash.patch ]; + + extraNativeBuildInputs = [ + m4 + ]; + + preBuild = '' + mkdir -p $out/share/doc + ''; + buildTargets = [ "MAKEDEV" ]; + + # patch some build artifacts + # gnu m4 doesn't seem to recognize the expr() macro but it's only used for simple arithmetic so we convert it to bash + postBuild = '' + substituteInPlace etc.$TARGET_MACHINE_ARCH/MAKEDEV --replace-fail "/bin/sh -" "${runtimeShell}" + sed -E -i -e '/^PATH=.*/d' -e 's/expr\((.*)\)/$((\1))/g' etc.$TARGET_MACHINE_ARCH/MAKEDEV + ''; + + # The install procedure is also weird since this is supposed to live in /dev + postInstall = '' + mkdir -p $out/bin + cp etc.$TARGET_MACHINE_ARCH/MAKEDEV $out/bin + chmod +x $out/bin/MAKEDEV + ''; + + meta.mainProgram = "MAKEDEV"; +}