[PATCH] guix-install.sh: Add support for openrc

  • Done
  • quality assurance status badge
Details
3 participants
  • Morgan.J.Smith
  • Ludovic Courtès
  • Tobias Geerinckx-Rice
Owner
unassigned
Submitted by
Morgan.J.Smith
Severity
normal

Debbugs page

M
M
Morgan.J.Smith wrote on 11 Aug 2020 13:36
(address . guix-patches@gnu.org)(name . Morgan Smith)(address . Morgan.J.Smith@outlook.com)
DM5PR1001MB2105C215AA5E05D4DAA5F64CC5450@DM5PR1001MB2105.namprd10.prod.outlook.com
From: Morgan Smith <Morgan.J.Smith@outlook.com>

* etc/guix-install.sh: Add support for openrc

I also removed the --warning=no-timestamp tar flag and changed grep to use
extended regex instead of perl regex since these flags where not supported on
the alpine linux image I was using to test (3.12.0-x86_64).
---
etc/guix-install.sh | 18 +++++++++++++++---
etc/openrc/guix-daemon | 11 +++++++++++
2 files changed, 26 insertions(+), 3 deletions(-)
create mode 100644 etc/openrc/guix-daemon

Toggle diff (69 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 72dc3839e8..9e9f8470d8 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -150,6 +150,9 @@ chk_init_sys()
_msg "${INF}init system is: sysv-init"
INIT_SYS="sysv-init"
return 0
+ elif [[ $(openrc --version 2>/dev/null) =~ \(OpenRC\) ]]; then
+ _msg "${INF}init system is: OpenRC"
+ INIT_SYS="openrc"
else
INIT_SYS="NA"
_err "${ERR}Init system could not be detected."
@@ -212,7 +215,7 @@ guix_get_bin_list()
| sort -Vu)")
latest_ver="$(echo "$bin_ver_ls" \
- | grep -oP "([0-9]{1,2}\.){2}[0-9]{1,2}" \
+ | grep -oE "([[:digit:]]{1,2}\.){2}[[:digit:]]{1,2}" \
| tail -n1)"
default_ver="guix-binary-${latest_ver}.${ARCH_OS}"
@@ -268,8 +271,7 @@ sys_create_store()
_debug "--- [ $FUNCNAME ] ---"
cd "$tmp_path"
- tar --warning=no-timestamp \
- --extract \
+ tar --extract \
--file "$pkg" &&
_msg "${PAS}unpacked archive"
@@ -384,6 +386,16 @@ sys_enable_guix_daemon()
service guix-daemon start; } &&
_msg "${PAS}enabled Guix daemon via sysv"
;;
+ openrc)
+ { mkdir -p /etc/init.d;
+ cp "${ROOT_HOME}/.config/guix/current/etc/openrc/guix-daemon" \
+ /etc/init.d/guix-daemon;
+ chmod 775 /etc/init.d/guix-daemon;
+
+ rc-update add guix-daemon default &&
+ rc-service guix-daemon start;} &&
+ _msg "${PAS}enabled Guix daemon via OpenRC"
+ ;;
NA|*)
_msg "${ERR}unsupported init system; run the daemon manually:"
echo " ${ROOT_HOME}/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild"
diff --git a/etc/openrc/guix-daemon b/etc/openrc/guix-daemon
new file mode 100644
index 0000000000..436673f169
--- /dev/null
+++ b/etc/openrc/guix-daemon
@@ -0,0 +1,11 @@
+#!/sbin/openrc-run
+
+export GUIX_LOCPATH=/var/guix/profiles/per-user/root/guix-profile/lib/locale
+export LC_ALL=en_US.utf8
+command="/var/guix/profiles/per-user/root/current-guix/bin/guix-daemon"
+command_args="--build-users-group=guixbuild"
+command_background="yes"
+pidfile="/var/run/guix-daemon.pid"
+
+output_log="/var/log/guix-daemon-stdout.log"
+error_log="/var/log/guix-daemon-stderr.log"
--
2.27.0
T
T
Tobias Geerinckx-Rice wrote on 11 Aug 2020 14:26
(address . Morgan.J.Smith@outlook.com)(address . 42816@debbugs.gnu.org)
87r1sc98m8.fsf@nckx
Morgan,

Morgan.J.Smith@outlook.com 写道:
Toggle quote (2 lines)
> * etc/guix-install.sh: Add support for openrc

\o/ thanks!

Toggle quote (2 lines)
> I also removed the --warning=no-timestamp tar flag

My understanding was that this silenced a scary but harmless
warning from older (GNU?) tar versions. I'm happy to see it go if
it actually breaks others.

Toggle quote (5 lines)
> and changed grep to use
> extended regex instead of perl regex since these flags where not
> supported on
> the alpine linux image I was using to test (3.12.0-x86_64).

Both Alpine compatibility changes are very welcome but should be
in a separate commit. Keep commits confined to one logical change
whenever possible.

Toggle quote (9 lines)
> --- a/etc/guix-install.sh
> +++ b/etc/guix-install.sh
> @@ -150,6 +150,9 @@ chk_init_sys()
> _msg "${INF}init system is: sysv-init"
> INIT_SYS="sysv-init"
> return 0
> + elif [[ $(openrc --version 2>/dev/null) =~ \(OpenRC\) ]];
> then

OK. I didn't realise the script still had severe bashism.

Toggle quote (3 lines)
> + _msg "${INF}init system is: OpenRC"
> + INIT_SYS="openrc"

Add a ‘return 0’ line here for consistency with the rest of the
code.

Toggle quote (6 lines)
> latest_ver="$(echo "$bin_ver_ls" \
> - | grep -oP "([0-9]{1,2}\.){2}[0-9]{1,2}"
> \
> + | grep -oE
> "([[:digit:]]{1,2}\.){2}[[:digit:]]{1,2}" \

[[:digit:]] wasn't strictly required here, right? I understand
that it's more ‘correct’ but can't imagine any locale actually
breaking either one.

Is there a practical chance that some ancient-but-supported grep
out there supports [0-9] but *not* [[:digit:]]?

If not: OK!

Toggle quote (16 lines)
> @@ -384,6 +386,16 @@ sys_enable_guix_daemon()
> service guix-daemon start; } &&
> _msg "${PAS}enabled Guix daemon via sysv"
> ;;
> + openrc)
> + { mkdir -p /etc/init.d;
> + cp
> "${ROOT_HOME}/.config/guix/current/etc/openrc/guix-daemon" \
> + /etc/init.d/guix-daemon;
> + chmod 775 /etc/init.d/guix-daemon;
> +
> + rc-update add guix-daemon default &&
> + rc-service guix-daemon start;} &&
> + _msg "${PAS}enabled Guix daemon via OpenRC"
> + ;;

I'll defer to your expertise on the OpenRC incantations :-)

Minor nitpick: ‘; }’.

Toggle quote (2 lines)
> diff --git a/etc/openrc/guix-daemon b/etc/openrc/guix-daemon

I like the subdirectory.

Toggle quote (18 lines)
> new file mode 100644
> index 0000000000..436673f169
> --- /dev/null
> +++ b/etc/openrc/guix-daemon
> @@ -0,0 +1,11 @@
> +#!/sbin/openrc-run
> +
> +export
> GUIX_LOCPATH=/var/guix/profiles/per-user/root/guix-profile/lib/locale
> +export LC_ALL=en_US.utf8
> +command="/var/guix/profiles/per-user/root/current-guix/bin/guix-daemon"
> +command_args="--build-users-group=guixbuild"
> +command_background="yes"
> +pidfile="/var/run/guix-daemon.pid"
> +
> +output_log="/var/log/guix-daemon-stdout.log"
> +error_log="/var/log/guix-daemon-stderr.log"

Please rename this to guix-daemon.in & add it to nix/local.mk so
we can use @localstatedir@ here.

If you could send a revised patch series it would be much
appreciated; otherwise I'll make the above changes when I get
around to it (...).

Thanks!

T G-R
-----BEGIN PGP SIGNATURE-----

iHUEARYKAB0WIQT12iAyS4c9C3o4dnINsP+IT1VteQUCXzMNIAAKCRANsP+IT1Vt
eeTFAQDVbJp6mrFok0pbCCYy92hGtv08T0zY8pq4ikBHmHdOtwEApZWejNdqO1Xi
QyJfPpZHIkonY4uuzExMDdKaT0ma/Qw=
=fojb
-----END PGP SIGNATURE-----

M
M
Morgan.J.Smith wrote on 11 Aug 2020 20:38
[PATCH 1/2] guix-install.sh: Increase compatibility
(address . me@tobias.gr)
DM5PR1001MB2105731ADDB371A895D7FCDDC5420@DM5PR1001MB2105.namprd10.prod.outlook.com
From: Morgan Smith <Morgan.J.Smith@outlook.com>

These fixes allow the script to be run using the binaries found on Alpine
Linux 3.12.0-x86_64.

* etc/guix-install.sh (guix_get_bin_list): Change grep to use extended regex
instead of perl regex. Grep using extended regex is POSIX while grep using
perl regex is not.

* etc/guix-install.sh (sys_create_store): Remove --warning flag as it is
unavailable on Alpine Linux
---

So for this change I had to learn perl regex. Then, once I understood
exactly what it did I recreated it from scratch not realizing that it
was almost the same as what was there before. I'm pretty sure there
are no differences between [[:digit:]] and [0-9], I just tend to use
[[:digit:]] because it's flashy

etc/guix-install.sh | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

Toggle diff (25 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 72dc3839e8..06edbaaffd 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -212,7 +212,7 @@ guix_get_bin_list()
| sort -Vu)")
latest_ver="$(echo "$bin_ver_ls" \
- | grep -oP "([0-9]{1,2}\.){2}[0-9]{1,2}" \
+ | grep -oE "([0-9]{1,2}\.){2}[0-9]{1,2}" \
| tail -n1)"
default_ver="guix-binary-${latest_ver}.${ARCH_OS}"
@@ -268,8 +268,7 @@ sys_create_store()
_debug "--- [ $FUNCNAME ] ---"
cd "$tmp_path"
- tar --warning=no-timestamp \
- --extract \
+ tar --extract \
--file "$pkg" &&
_msg "${PAS}unpacked archive"
--
2.28.0
M
M
Morgan.J.Smith wrote on 11 Aug 2020 20:38
[PATCH 2/2] guix-install.sh: Add openrc support
(address . me@tobias.gr)
DM5PR1001MB2105E73EB9EF88EF6BFAF513C5420@DM5PR1001MB2105.namprd10.prod.outlook.com
From: Morgan Smith <Morgan.J.Smith@outlook.com>

Tested and working on Alpine Linux 3.12.0-x86_64

* etc/guix-install.sh: Add openrc support
* etc/openrc/guix-daemon.in: New file - openrc service file
* nix/local.mk (etc/openrc/guix-daemon): New rule.
(nodist_openrcservice_DATA): Add etc/openrc/guix-daemon.in .
(CLEANFILES): Add etc/openrc/guix-daemon .
* .gitignore: Add etc/openrc/guix-daemon .
---

I'm pretty far out of comfort zone on these changes so please let me
know how this works. I basically guessed what needed to be changed in
local.mk.

---
.gitignore | 1 +
etc/guix-install.sh | 15 +++++++++++++++
nix/local.mk | 17 +++++++++++++++--
3 files changed, 31 insertions(+), 2 deletions(-)

Toggle diff (96 lines)
diff --git a/.gitignore b/.gitignore
index f630444a0f..e2f745b42a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -74,6 +74,7 @@
/etc/guix-publish.conf
/etc/guix-publish.service
/etc/init.d/guix-daemon
+/etc/openrc/guix-daemon
/guix-daemon
/guix/config.scm
/libformat.a
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 06edbaaffd..ff4b95f124 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -4,6 +4,7 @@
# Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
# Copyright © 2018 Efraim Flashner <efraim@flashner.co.il>
# Copyright © 2019, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
+# Copyright © 2020 Morgan Smith <Morgan.J.Smith@outlook.com>
#
# This file is part of GNU Guix.
#
@@ -150,6 +151,10 @@ chk_init_sys()
_msg "${INF}init system is: sysv-init"
INIT_SYS="sysv-init"
return 0
+ elif [[ $(openrc --version 2>/dev/null) =~ \(OpenRC\) ]]; then
+ _msg "${INF}init system is: OpenRC"
+ INIT_SYS="openrc"
+ return 0
else
INIT_SYS="NA"
_err "${ERR}Init system could not be detected."
@@ -383,6 +388,16 @@ sys_enable_guix_daemon()
service guix-daemon start; } &&
_msg "${PAS}enabled Guix daemon via sysv"
;;
+ openrc)
+ { mkdir -p /etc/init.d;
+ cp "${ROOT_HOME}/.config/guix/current/etc/openrc/guix-daemon" \
+ /etc/init.d/guix-daemon;
+ chmod 775 /etc/init.d/guix-daemon;
+
+ rc-update add guix-daemon default &&
+ rc-service guix-daemon start; } &&
+ _msg "${PAS}enabled Guix daemon via OpenRC"
+ ;;
NA|*)
_msg "${ERR}unsupported init system; run the daemon manually:"
echo " ${ROOT_HOME}/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild"
diff --git a/nix/local.mk b/nix/local.mk
index 005cde5563..2bb01041b9 100644
--- a/nix/local.mk
+++ b/nix/local.mk
@@ -180,6 +180,17 @@ etc/init.d/guix-daemon: etc/init.d/guix-daemon.in \
"$<" > "$@.tmp"; \
mv "$@.tmp" "$@"
+# The service script for openrc.
+openrcservicedir = $(sysconfdir)/init.d
+nodist_openrcservice_DATA = etc/openrc/guix-daemon
+
+etc/openrc/guix-daemon: etc/openrc/guix-daemon.in \
+ $(top_builddir)/config.status
+ $(AM_V_GEN)$(MKDIR_P) "`dirname $@`"; \
+ $(SED) -e 's|@''localstatedir''@|$(localstatedir)|' < \
+ "$<" > "$@.tmp"; \
+ mv "$@.tmp" "$@"
+
# The '.conf' jobs for Upstart.
upstartjobdir = $(libdir)/upstart/system
nodist_upstartjob_DATA = etc/guix-daemon.conf etc/guix-publish.conf
@@ -194,7 +205,8 @@ etc/guix-%.conf: etc/guix-%.conf.in \
CLEANFILES += \
$(nodist_systemdservice_DATA) \
$(nodist_upstartjob_DATA) \
- $(nodist_sysvinitservice_DATA)
+ $(nodist_sysvinitservice_DATA) \
+ $(nodist_openrcservice_DATA)
EXTRA_DIST += \
%D%/AUTHORS \
@@ -203,7 +215,8 @@ EXTRA_DIST += \
etc/guix-daemon.conf.in \
etc/guix-publish.service.in \
etc/guix-publish.conf.in \
- etc/init.d/guix-daemon.in
+ etc/init.d/guix-daemon.in \
+ etc/openrc/guix-daemon.in
if CAN_RUN_TESTS
--
2.28.0
M
M
Morgan.J.Smith wrote on 11 Aug 2020 20:58
[PATCH 3/2] Oops, please merge this patch with the last one. My bad
(address . me@tobias.gr)
DM5PR1001MB2105EBEFD116D4E65C55C7FAC5420@DM5PR1001MB2105.namprd10.prod.outlook.com
From: Morgan Smith <Morgan.J.Smith@outlook.com>

---
Oops, please merge this patch with the last one. My bad

etc/openrc/guix-daemon.in | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
create mode 100644 etc/openrc/guix-daemon.in

Toggle diff (36 lines)
diff --git a/etc/openrc/guix-daemon.in b/etc/openrc/guix-daemon.in
new file mode 100644
index 0000000000..110a58b88d
--- /dev/null
+++ b/etc/openrc/guix-daemon.in
@@ -0,0 +1,28 @@
+#!/sbin/openrc-run
+# GNU Guix --- Functional package management for GNU
+# Copyright © 2020 Morgan Smith <Morgan.J.Smith@outlook.com>
+#
+# This file is part of GNU Guix.
+#
+# GNU Guix 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.
+#
+# GNU Guix 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 a copy of the GNU General Public License
+# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+export GUIX_LOCPATH=@localstatedir@/guix/profiles/per-user/root/guix-profile/lib/locale
+export LC_ALL=en_US.utf8
+command="@localstatedir@/guix/profiles/per-user/root/current-guix/bin/guix-daemon"
+command_args="--build-users-group=guixbuild"
+command_background="yes"
+pidfile="/var/run/guix-daemon.pid"
+
+output_log="/var/log/guix-daemon-stdout.log"
+error_log="/var/log/guix-daemon-stderr.log"
--
2.28.0
T
T
Tobias Geerinckx-Rice wrote on 18 Aug 2020 13:52
This is just a test
(address . 42816@debbugs.gnu.org)(name . GNU bug tracker automated control server)(address . control@debbugs.gnu.org)
87y2mbwuaw.fsf@nckx
User: guix
Usertag: notdeadjusttestin
L
L
Ludovic Courtès wrote on 4 Sep 2020 01:57
Re: [bug#42816] [PATCH 1/2] guix-install.sh: Increase compatibility
(address . Morgan.J.Smith@outlook.com)
87363xx6k1.fsf@gnu.org
Hi!

Morgan.J.Smith@outlook.com skribis:

Toggle quote (12 lines)
> From: Morgan Smith <Morgan.J.Smith@outlook.com>
>
> These fixes allow the script to be run using the binaries found on Alpine
> Linux 3.12.0-x86_64.
>
> * etc/guix-install.sh (guix_get_bin_list): Change grep to use extended regex
> instead of perl regex. Grep using extended regex is POSIX while grep using
> perl regex is not.
>
> * etc/guix-install.sh (sys_create_store): Remove --warning flag as it is
> unavailable on Alpine Linux

[...]

Toggle quote (7 lines)
> From: Morgan Smith <Morgan.J.Smith@outlook.com>
>
> ---
> Oops, please merge this patch with the last one. My bad
>
> etc/openrc/guix-daemon.in | 28 ++++++++++++++++++++++++++++

Tobias, I think these patches fell through the cracks. Could you apply
them if everything looks good to you? :-)

Thanks,
Ludo’.
T
T
Tobias Geerinckx-Rice wrote on 17 Sep 2020 05:13
[PATCH] guix-install.sh: Add support for openrc
(address . 42816@debbugs.gnu.org)
87k0wszjmm.fsf@nckx
Morgan, civodul,

Toggle quote (2 lines)
> Tobias, I think these patches fell through the cracks.

I think so too. Thanks for your patience, Morgan, and enjoy
commits cabac732 et al.

Closing,

T G-R
-----BEGIN PGP SIGNATURE-----

iIMEARYKACsWIQT12iAyS4c9C3o4dnINsP+IT1VteQUCX2NS4Q0cbWVAdG9iaWFz
LmdyAAoJEA2w/4hPVW15r88BAPT10rB1lF8oBHC10NB8oTaijt/ezb19tEBDPUps
xdLFAQDIp4p1tf1vl2vkfZvLIZKyON4xPJU3Nioun4KLjmm3Aw==
=Ya3R
-----END PGP SIGNATURE-----

L
L
Ludovic Courtès wrote on 19 Sep 2020 13:41
control message for bug #42816
(address . control@debbugs.gnu.org)
87d02hpkij.fsf@gnu.org
tags 42816 fixed
close 42816
quit
?
Your comment

This issue is archived.

To comment on this conversation send an email to 42816@patchwise.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 42816
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch