From 235ec693219c8e0c9eff3c9f975025d861b5e80a Mon Sep 17 00:00:00 2001 From: Chad Nelson Date: Mon, 20 Nov 2023 09:05:07 -0700 Subject: [PATCH] init push --- .gitignore | 65 +++++++++++++++++++++++++++++++++++++ AUTHORS | 3 ++ COPYING | 3 ++ ChangeLog | 1 + HACKING | 54 +++++++++++++++++++++++++++++++ NEWS | 14 ++++++++ README | 1 + README.org | 4 +++ doc/msg.texi | 60 ++++++++++++++++++++++++++++++++++ guix.scm | 85 +++++++++++++++++++++++++++++++++++++++++++++++++ hall.scm | 40 +++++++++++++++++++++++ msg.scm | 0 msg/hconfig.scm | 23 +++++++++++++ msg/helpers.scm | 21 ++++++++++++ msg/machine.scm | 79 +++++++++++++++++++++++++++++++++++++++++++++ scripts/msg.in | 21 ++++++++++++ 16 files changed, 474 insertions(+) create mode 100644 .gitignore create mode 100644 AUTHORS create mode 100644 COPYING create mode 100644 ChangeLog create mode 100644 HACKING create mode 100644 NEWS create mode 120000 README create mode 100644 README.org create mode 100644 doc/msg.texi create mode 100644 guix.scm create mode 100644 hall.scm create mode 100644 msg.scm create mode 100644 msg/hconfig.scm create mode 100644 msg/helpers.scm create mode 100644 msg/machine.scm create mode 100644 scripts/msg.in diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a123e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,65 @@ +*.eps +*.go +*.log +*.pdf +*.png +*.tar.xz +*.tar.gz +*.tmp +*~ +.#* +\#*\# +,* +/ABOUT-NLS +/INSTALL +/aclocal.m4 +/autom4te.cache +/build-aux/ar-lib +/build-aux/compile +/build-aux/config.guess +/build-aux/config.rpath +/build-aux/config.sub +/build-aux/depcomp +/build-aux/install-sh +/build-aux/mdate-sh +/build-aux/missing +/build-aux/test-driver +/build-aux/texinfo.tex +/config.status +/configure +/doc/*.1 +/doc/.dirstamp +/doc/contributing.*.texi +/doc/*.aux +/doc/*.cp +/doc/*.cps +/doc/*.fn +/doc/*.fns +/doc/*.html +/doc/*.info +/doc/*.info-[0-9] +/doc/*.ky +/doc/*.pg +/doc/*.toc +/doc/*.t2p +/doc/*.tp +/doc/*.vr +/doc/*.vrs +/doc/stamp-vti +/doc/version.texi +/doc/version-*.texi +/m4/* +/pre-inst-env +/test-env +/test-tmp +/tests/*.trs +GPATH +GRTAGS +GTAGS +Makefile +Makefile.in +config.cache +stamp-h[0-9] +tmp +/.version +/doc/stamp-[0-9] diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..e785b8f --- /dev/null +++ b/AUTHORS @@ -0,0 +1,3 @@ +Contributors to Msg 0.1: + + Chad Nelson <> diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..f658e91 --- /dev/null +++ b/COPYING @@ -0,0 +1,3 @@ +This project's license is GPL 3+. + +You can read the full license at https://www.gnu.org/licenses/gpl.html. diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..76c33bf --- /dev/null +++ b/ChangeLog @@ -0,0 +1 @@ +For a complete log, please see the Git commit log at . diff --git a/HACKING b/HACKING new file mode 100644 index 0000000..b316ec0 --- /dev/null +++ b/HACKING @@ -0,0 +1,54 @@ +# -*- mode: org; coding: utf-8; -*- + +#+TITLE: Hacking msg + +* Contributing + +By far the easiest way to hack on msg is to develop using Guix: + +#+BEGIN_SRC bash + # Obtain the source code + cd /path/to/source-code + guix shell -Df guix.scm + # In the new shell, run: + hall build --execute && autoreconf -vif && ./configure && make check +#+END_SRC + +You may also want to set your directory as an authorized directory for +`guix shell' so it works without arguments. To do that, simply run + +#+BEGIN_SRC bash + echo $(pwd) >> $HOME/.config/guix/shell-authorized-directories +#+END_SRC + +You can now hack this project's files to your heart's content, whilst +testing them from your `guix shell' shell. + +To try out any scripts in the project you can now use + +#+BEGIN_SRC bash + ./pre-inst-env scripts/${script-name} +#+END_SRC + +If you'd like to tidy the project again, but retain the ability to test the +project from the commandline, simply run: + +#+BEGIN_SRC bash + ./hall clean --skip "scripts/${script-name},pre-inst-env" --execute +#+END_SRC + +** Manual Installation + +If you do not yet use Guix, you will have to install this project's +dependencies manually: + - autoconf + - automake + - pkg-config + - texinfo + - guile-hall + +Once those dependencies are installed you can run: + +#+BEGIN_SRC bash + hall build -x && autoreconf -vif && ./configure && make check +#+END_SRC diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..275964d --- /dev/null +++ b/NEWS @@ -0,0 +1,14 @@ +# -*- mode: org; coding: utf-8; -*- + +#+TITLE: Msg NEWS – history of user-visible changes +#+STARTUP: content hidestars + +Copyright © (2023) Chad Nelson <> + + Copying and distribution of this file, with or without modification, + are permitted in any medium without royalty provided the copyright + notice and this notice are preserved. + +Please send Msg bug reports to . + +* Publication at 0.1 diff --git a/README b/README new file mode 120000 index 0000000..314e17d --- /dev/null +++ b/README @@ -0,0 +1 @@ +README.org \ No newline at end of file diff --git a/README.org b/README.org new file mode 100644 index 0000000..ad9af0c --- /dev/null +++ b/README.org @@ -0,0 +1,4 @@ +# -*- mode: org; coding: utf-8; -*- + +#+TITLE: README for Msg + diff --git a/doc/msg.texi b/doc/msg.texi new file mode 100644 index 0000000..1635fbd --- /dev/null +++ b/doc/msg.texi @@ -0,0 +1,60 @@ +\input texinfo +@c -*-texinfo-*- + +@c %**start of header +@setfilename msg.info +@documentencoding UTF-8 +@settitle Msg Reference Manual +@c %**end of header + +@include version.texi + +@copying +Copyright @copyright{} 2023 Chad Nelson + +Permission is granted to copy, distribute and/or modify this document +under the terms of the GNU Free Documentation License, Version 1.3 or +any later version published by the Free Software Foundation; with no +Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A +copy of the license is included in the section entitled ``GNU Free +Documentation License''. +@end copying + +@dircategory The Algorithmic Language Scheme +@direntry +* Msg: (msg). +@end direntry + +@titlepage +@title The Msg Manual +@author Chad Nelson + +@page +@vskip 0pt plus 1filll +Edition @value{EDITION} @* +@value{UPDATED} @* + +@insertcopying +@end titlepage + +@contents + +@c ********************************************************************* +@node Top +@top Msg + +This document describes Msg version @value{VERSION}. + +@menu +* Introduction:: Why Msg? +@end menu + +@c ********************************************************************* +@node Introduction +@chapter Introduction + +INTRODUCTION HERE + +This documentation is a stub. + +@bye diff --git a/guix.scm b/guix.scm new file mode 100644 index 0000000..5a2f05c --- /dev/null +++ b/guix.scm @@ -0,0 +1,85 @@ +(use-modules + (guix packages) + ((guix licenses) #:prefix license:) + (guix download) + (guix gexp) + (guix build-system gnu) + (gnu packages) + (gnu packages autotools) + (gnu packages guile) + (gnu packages guile-xyz) + (gnu packages pkg-config) + (gnu packages texinfo) + (srfi srfi-1)) + +(package + (name "msg") + (version "0.1") + (source + (local-file + (dirname (current-filename)) + #:recursive? + #t + #:select? + (lambda (file stat) + (not (any (lambda (my-string) (string-contains file my-string)) + (list ".git" ".dir-locals.el" "guix.scm")))))) + (build-system gnu-build-system) + (arguments + `(#:modules + ((ice-9 match) (ice-9 ftw) ,@%gnu-build-system-modules) + #:phases + (modify-phases + %standard-phases + (add-after + 'install + 'hall-wrap-binaries + (lambda* (#:key inputs outputs #:allow-other-keys) + (let* ((compiled-dir + (lambda (out version) + (string-append out "/lib/guile/" version "/site-ccache"))) + (uncompiled-dir + (lambda (out version) + (string-append + out + "/share/guile/site" + (if (string-null? version) "" "/") + version))) + (dep-path + (lambda (env modules path) + (list env + ":" + 'prefix + (cons modules + (map (lambda (input) + (string-append + (assoc-ref inputs input) + path)) + ,''()))))) + (out (assoc-ref outputs "out")) + (bin (string-append out "/bin/")) + (site (uncompiled-dir out ""))) + (match (scandir site) + (("." ".." version) + (for-each + (lambda (file) + (wrap-program + (string-append bin file) + (dep-path + "GUILE_LOAD_PATH" + (uncompiled-dir out version) + (uncompiled-dir "" version)) + (dep-path + "GUILE_LOAD_COMPILED_PATH" + (compiled-dir out version) + (compiled-dir "" version)))) + ,''("msg")) + #t)))))))) + (native-inputs (list autoconf automake pkg-config texinfo)) + (inputs (list guile-3.0)) + (propagated-inputs (list)) + (synopsis "") + (description "") + (home-page "") + (license license:gpl3+)) + diff --git a/hall.scm b/hall.scm new file mode 100644 index 0000000..beb3c23 --- /dev/null +++ b/hall.scm @@ -0,0 +1,40 @@ +(hall-description + (name "msg") + (prefix "") + (version "0.1") + (author "Chad Nelson") + (email "") + (copyright (2023)) + (synopsis "") + (description "") + (home-page "") + (license gpl3+) + (dependencies `()) + (skip ()) + (features ((guix #f) (native-language-support #f) (licensing #f))) + (files (libraries + ((scheme-file "msg") + (directory + "msg" + ((scheme-file "machine") + (scheme-file "hconfig") + (scheme-file "helpers"))))) + (tests ((directory "tests" ()))) + (programs ((directory "scripts" ((in-file "msg"))))) + (documentation + ((org-file "README") + (symlink "README" "README.org") + (text-file "HACKING") + (text-file "COPYING") + (directory + "doc" + ((texi-file "msg") + (text-file ".dirstamp") + (info-file "msg") + (texi-file "version") + (text-file "stamp-vti"))) + (text-file "NEWS") + (text-file "AUTHORS") + (text-file "ChangeLog"))) + (infrastructure + ((scheme-file "guix") (text-file ".gitignore") (scheme-file "hall"))))) diff --git a/msg.scm b/msg.scm new file mode 100644 index 0000000..e69de29 diff --git a/msg/hconfig.scm b/msg/hconfig.scm new file mode 100644 index 0000000..87d4c49 --- /dev/null +++ b/msg/hconfig.scm @@ -0,0 +1,23 @@ +(define-module + (msg hconfig) + #:use-module + (srfi srfi-26) + #:export + (%version + %author + %license + %copyright + %gettext-domain + G_ + N_ + init-nls + init-locale)) + +(define %version "0.1") + +(define %author "Chad Nelson") + +(define %license 'gpl3+) + +(define %copyright '(2023)) + diff --git a/msg/helpers.scm b/msg/helpers.scm new file mode 100644 index 0000000..4a6232e --- /dev/null +++ b/msg/helpers.scm @@ -0,0 +1,21 @@ +(define-module (msg helpers) + #:use-module (ice-9 ftw) + #:use-module (ice-9 popen) + #:use-module (ice-9 rdelim) + #:use-module (system foreign) + #:export (directory-exists? + run-shell-command + start-command-in-background)) + +(define (directory-exists? path) + (catch 'system-error + (lambda () + (stat path)) + (lambda args #f))) + +(define (run-shell-command command) + (let* ((port (open-input-pipe command)) + (str (read-line port))) + ;;(close-pipe port) + port)) + diff --git a/msg/machine.scm b/msg/machine.scm new file mode 100644 index 0000000..fb1596f --- /dev/null +++ b/msg/machine.scm @@ -0,0 +1,79 @@ +(define-module (msg machine) + #:use-module (ice-9 match) + #:use-module (ice-9 rdelim) + #:use-module (ice-9 textual-ports) + #:use-module (system foreign) + #:use-module (msg helpers) + #:export (machine)) + + +(define* (machine #:optional (args (command-line))) + ;;(define clean-args (cdr args)) + (match args + (("-h") + (help)) + (("init") + (init)) + (("reinit") + (clear-install) + (init)) + (_ + (display "Please enter a valid command or -h for help.\n")))) + +(define* (help) + (display "\nHere are the available commands:\n\n") + (display "start: Start the MSG envrionment.\n")) + +(define* (clear-install) + (display "This is a destructive command and will remove your entire guix instance. Proceed? (y/n)\n") + (define response (read-line)) + (if (string=? response "y") + (begin + (system "rm -r ~/.guix")) + (display "Please enter a valid response."))) + +(define* (init) + (define home-path (getenv "HOME")) + (define arch (run-shell-command "uname -m")) + + + (if (not (directory-exists? (format #f "~a/.guix" home-path))) + (begin + (system "mkdir -p $HOME/.guix/qemu $HOME/.guix/home $HOME/.guix/ssh-cert") + ;; Get msg image + + (cond ((string=? arch "arm64") + (system "/opt/homebrew/bin/wget https://objectstorage.us-phoenix-1.oraclecloud.com/n/axfgkze2xif1/b/guix-system/o/msg-system-aarch64guix-user.qcow2.tar.gz -O $HOME/.guix/qemu/guix.qcow2.tar.gz") + (system "tar -xvzf $HOME/.guix/qemu/guix.qcow2.tar.gz -C $HOME/.guix/qemu/") + (define pid (run-shell-command "/opt/homebrew/bin/qemu-system-aarch64 \ + -machine virt,highmem=on \ + -accel hvf \ + -cpu host \ + -smp 4 \ + -display none \ + -hda $HOME/.guix/qemu/guix-user.qcow2 \ + -m 4G \ + -virtfs local,path=$HOME/.guix/home,security_model=mapped,mount_tag=macos \ + -bios /opt/homebrew/opt/qemu/share/qemu/edk2-aarch64-code.fd \ + -device virtio-net,netdev=vmnic \ + -netdev user,id=vmnic,hostfwd=tcp:127.0.0.1:9001-:22 &")) + (display pid)) + ((string=? arch "x86_64") + (system "/usr/local/bin/wget https://objectstorage.us-phoenix-1.oraclecloud.com/n/axfgkze2xif1/b/guix-system/o/msg-system-x86_64guix-user-x86.qcow2.tar.gz -O $HOME/.guix/qemu/guix.qcow2.tar.gz") + (system "tar -xvzf $HOME/.guix/qemu/guix.qcow2.tar.gz -C $HOME/.guix/qemu/") + (system "/usr/local/bin/qemu-system-x86_64 \ + -machine type=q35,accel=hvf \ + -smp 4 \ + -hda $HOME/.guix/qemu/guix-user.qcow2 \ + -m 4G \ + -display none \ + -cpu Nehalem \ + -virtfs local,path=$HOME/.guix,security_model=mapped,mount_tag=macos \ + -device virtio-net,netdev=vmnic \ + -netdev user,id=vmnic,hostfwd=tcp:127.0.0.1:9001-:22") + )) + + ;; Get msg ssh-key + (system "/opt/homebrew/bin/wget https://objectstorage.us-phoenix-1.oraclecloud.com/n/axfgkze2xif1/b/guix-system/o/msg_rsa -O $HOME/.guix/ssh-cert/msg_rsa"))) + + (system "ssh -o StrictHostKeychecking=no -i $HOME/.guix/ssh-cert/msg_rsa root@127.0.0.1 -p 9001 'guix'")) diff --git a/scripts/msg.in b/scripts/msg.in new file mode 100644 index 0000000..ce79bc7 --- /dev/null +++ b/scripts/msg.in @@ -0,0 +1,21 @@ +#!@GUILE@ \ +--no-auto-compile -e main -s +!# + +(use-modules (msg machine) + (ice-9 match)) + +(define* (main #:optional (args (command-line))) + (define clean-args (cdr args)) + + (match clean-args + (("machine" rest ...) + (machine rest)) + (("-h") + (help)) + (_ + (display "Please enter a valid command or -h for help.\n")))) + +(define* (help) + (display "\nHere are the available commands:\n\n") + (display "machine: interact with the vm environment for MSG.\n"))