-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-glibc-libre
More file actions
executable file
·195 lines (177 loc) · 6.43 KB
/
update-glibc-libre
File metadata and controls
executable file
·195 lines (177 loc) · 6.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env nix-shell
#! nix-shell -i zsh -p zsh gnutar xz git cacert coreutils nawk nixfmt-rfc-style --pure
#
# Copyright © 2025 Barry Schwartz
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License, as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received copies of the GNU General Public License
# along with this program. If not, see
# <https:#www.gnu.org/licenses/>.
#
set -e
program_name="${0}"
source glibc-libre-files/command-line.zsh
source glibc-libre-files/helpers.zsh
glibc_subdir="pkgs/development/libraries/glibc"
glibc_in_local_repo="${local_repo}/${glibc_subdir}"
glibc_dir="glibc-libre/glibc"
abs_glibc_dir=`realpath ${PWD}`/"${glibc_dir}"
function obtain_the_glibc_derivation
{
printf "Obtaining the glibc derivation.\n"
require_the_local_repo
mkdir -p "${abs_glibc_dir}"
cp -R "${glibc_in_local_repo}"/* "${abs_glibc_dir}"
}
function disable_nixonian_patch
{
awk_edit '/\.\/dont-use-system-ld-so-cache\.patch/ {
print (" # NOPE! Exert our freedom, instead.")
next
}
{
print
}
' "${abs_glibc_dir}"/common.nix
}
function install_ldconfig_for_sure
{
awk_edit '{
print
}
/moveToOutput bin\/getent \$getent/ {
print ("")
print (" # Be sure ldconfig is installed, and also install")
print (" # it as ldconfig-libre. Output both ldconfig and")
print (" # ldconfig-libre also as lone outputs. Some may")
print (" # find this arrangement helpful for working around")
print (" # problems.")
print (" cp elf/ldconfig elf/ldconfig-libre")
print (" install -d $bin/bin")
print (" rm -f $bin/bin/ldconfig")
print (" install elf/ldconfig $bin/bin")
print (" install elf/ldconfig-libre $bin/bin")
print (" install -d $ldconfig/bin")
print (" install elf/ldconfig $ldconfig/bin")
print (" install -d $ldconfig_libre/bin")
print (" install elf/ldconfig-libre $ldconfig_libre/bin")
}
/^[[:space:]]*"getent"/ { # FIXME: This edit could use more context.
print (" \"ldconfig\"")
print (" \"ldconfig_libre\"")
}
' "${abs_glibc_dir}"/common.nix
}
function edit_for_freedom
{
printf "Editing the derivation.\n"
disable_nixonian_patch
install_ldconfig_for_sure
nixfmt "${abs_glibc_dir}"/common.nix
}
function write_nix_configuration
{
local config="${1}"
local deriv_dir=`basename "${abs_glibc_dir}"`
if true; then
printf "{ pkgs, ... }:\n"
printf "\n"
printf "let\n"
printf " glibc-libre =\n"
printf " pkgs:\n"
printf " (pkgs.callPackage %s {\n" ./"${deriv_dir}"
printf " stdenv = pkgs.gccStdenv;\n"
printf " });\n"
printf "in\n"
printf "{\n"
printf " nixpkgs = {\n"
printf " overlays = [\n"
printf " ( final: prev: { libre = glibc-libre final.pkgs; } )"
printf " ];\n"
printf " };\n"
printf " system = {\n"
printf " replaceDependencies = {\n"
printf " replacements = [\n"
printf " {\n"
printf " oldDependency = pkgs.glibc;\n"
printf " newDependency = pkgs.libre;\n"
printf " }\n"
printf " ];\n"
printf " };"
printf " };\n"
printf "}\n"
fi > "${config}"
nixfmt "${config}"
}
function write_example_etc_config
{
local config="${1}"
if true; then
printf "{\n"
printf " pkgs,\n"
printf " ...\n"
printf "}:\n"
printf "\n"
printf "let\n"
printf " use-nix-ld = false;\n"
printf "in\n"
printf "{\n"
printf " #\n"
printf " # You can install either nix-ld or glibc-libre’s ELF\n"
printf " # interpreter itself as the ‘standard’ ELF interpreter.\n"
printf " # If you do not use nix-ld, then link or place libraries\n"
printf " # you wish to use into a directory listed in\n"
printf " # /etc/ld.so.conf and be sure to run ldconfig-libre.\n"
printf " # Using glibc-libre directly avoids setting LD_LIBRARY_PATH.\n"
printf " #\n"
printf " programs.nix-ld = {\n"
printf " enable = use-nix-ld;\n"
printf " libraries = [ ]; # Put a list of packages here.\n"
printf " };\n"
printf " environment.ldso =\n"
printf " if use-nix-ld then\n"
printf " null\n"
printf " else\n"
printf " \"\${pkgs.libre}/lib/ld-linux-x86-64.so.2\";\n"
printf "\n"
printf " system.activationScripts = {\n"
printf " \"update-ld.so.cache\" = ''\n"
printf " if ! [ -e /etc/ld.so.conf ]; then\n"
printf " if true; then\n"
printf " printf \"# Example /etc/ld.so.conf\\\\n\"\n"
printf " printf \"\\\\n\"\n"
printf " printf \"#/lib <-- uncomment to include\\\\n\"\n"
printf " printf \"#/usr/lib\\\\n\"\n"
printf " printf \"#/usr/local/lib\\\\n\"\n"
printf " fi > /etc/ld.so.conf\n"
printf " fi\n"
printf " \${pkgs.libre.bin}/bin/ldconfig-libre\n"
printf " '';\n"
printf " };\n"
printf "}\n"
fi > "${config}"
nixfmt "${config}"
}
printf "Updating glibc-libre...\n"
rm -R -f glibc-libre/glibc
obtain_the_glibc_derivation
edit_for_freedom
printf "Writing Nix configurations.\n"
write_nix_configuration "glibc-libre/libre-configuration.nix"
write_example_etc_config "glibc-libre/libre-etc-config.example.nix"
printf "Done.\n"
# local variables:
# mode: shell-script
# sh-shell: zsh
# coding: utf-8
# indent-tabs-mode: nil
# end: