Skip to content

Instantly share code, notes, and snippets.

@christopherlam
Created December 13, 2021 14:33
Show Gist options
  • Save christopherlam/8f5f16b91e3d7c7cfacd5e0b4008732c to your computer and use it in GitHub Desktop.
Save christopherlam/8f5f16b91e3d7c7cfacd5e0b4008732c to your computer and use it in GitHub Desktop.
Guix in WSL2 (with busybox from 0xbadfca11/miniwsl) guix-infect
# wget https://github.com/0xbadfca11/miniwsl/releases/download/release3041562/rootfs.tgz
# wsl --import guix /guix rootfs.tgz --version 2
# wsl -d guix /bin/busybox sh -c "/mnt/c/sys/misc/guix-infect.sh"
mkdir -p /root /etc /tmp /var/run /run /home
chmod 1777 /tmp
rm /etc/passwd
cat <<EOM >> /etc/passwd
root:x:0:0:root:/root:/bin/bash
guixbuilder01:x:999:999:Guix build user 01:/var/empty:/usr/sbin/nologin
guixbuilder02:x:998:999:Guix build user 02:/var/empty:/usr/sbin/nologin
guixbuilder03:x:997:999:Guix build user 03:/var/empty:/usr/sbin/nologin
guixbuilder04:x:996:999:Guix build user 04:/var/empty:/usr/sbin/nologin
guixbuilder05:x:995:999:Guix build user 05:/var/empty:/usr/sbin/nologin
guixbuilder06:x:994:999:Guix build user 06:/var/empty:/usr/sbin/nologin
guixbuilder07:x:993:999:Guix build user 07:/var/empty:/usr/sbin/nologin
guixbuilder08:x:992:999:Guix build user 08:/var/empty:/usr/sbin/nologin
guixbuilder09:x:991:999:Guix build user 09:/var/empty:/usr/sbin/nologin
guixbuilder10:x:990:999:Guix build user 10:/var/empty:/usr/sbin/nologin
EOM
rm /etc/group
cat <<EOM >> /etc/group
root:x:0:
guixbuild:x:999:guixbuilder01,guixbuilder02,guixbuilder03,guixbuilder04,guixbuilder05,guixbuilder06,guixbuilder07,guixbuilder08,guixbuilder09,guixbuilder10
EOM
cat <<EOM >> /etc/services
ftp-data 20/tcp
ftp 21/tcp
ssh 22/tcp # SSH Remote Login Protocol
domain 53/tcp # Domain Name Server
domain 53/udp
http 80/tcp www # WorldWideWeb HTTP
https 443/tcp # http protocol over TLS/SSL
ftps-data 989/tcp # FTP over SSL (data)
ftps 990/tcp
http-alt 8080/tcp webcache # WWW caching service
http-alt 8080/udp
EOM
cd /tmp
wget http://ftp.gnu.org/gnu/guix/guix-binary-1.3.0.x86_64-linux.tar.xz
tar -C / -xvJf /tmp/guix-binary-1.3.0.x86_64-linux.tar.xz
mkdir -p ~root/.config/guix
ln -sf /var/guix/profiles/per-user/root/current-guix ~root/.config/guix/current
GUIX_PROFILE="`echo ~root`/.config/guix/current"
source $GUIX_PROFILE/etc/profile
guix-daemon --build-users-group=guixbuild &
guix archive --authorize < /var/guix/profiles/per-user/root/current-guix/share/guix/ci.guix.gnu.org.pub
# Edit Path to WSL config!
guix system reconfigure --no-bootloader /mnt/c/sys/scm/wsl.scm --no-grafts
# Restart System Services like shepherd - paste in script and run in cmd via:
# wsl.exe -d guix /bin/busybox sh -c "/mnt/c/sys/misc/guix-init.sh"
DIR="/run/current-system"
if [ ! -d "$DIR" ]; then
ln -s none /run/current-system &>/dev/null
export GUIX_NEW_SYSTEM=$(readlink -f /var/guix/profiles/system)
setsid /var/guix/profiles/system/profile/bin/guile --no-auto-compile $GUIX_NEW_SYSTEM/boot &>/dev/null &
sleep 1
fi
export GUIX_PROFILE=/run/current-system
source "$GUIX_PROFILE/etc/profile"
(use-modules
(gnu)
(guix profiles)
(guix packages)
(srfi srfi-1))
(use-service-modules networking ssh)
(define-public os
(operating-system
(host-name "guix")
(timezone "Europe/London")
(locale "en_US.utf8")
(kernel hello)
(initrd (lambda* (. rest) (plain-file "dummyinitrd" "dummyinitrd")))
(initrd-modules '())
(firmware '())
(bootloader
(bootloader-configuration
(bootloader
(bootloader
(name 'dummybootloader)
(package hello)
(configuration-file "/dev/null")
(configuration-file-generator (lambda* (. rest) (computed-file "dummybootloader" #~(mkdir #$output))))
(installer #~(const #t))))))
(file-systems (list (file-system
(device "/dev/sdb")
(mount-point "/")
(type "ext4")
(mount? #t))))
(users (cons (user-account
(name "wsluser")
(group "users")
(supplementary-groups '("wheel")))
%base-user-accounts))
(packages
(append
(cons*
(map ( compose list specification->package+output)
`( "openssh" "git" "nss-certs" ; packages here
))) %base-packages ))
(services (list (service guix-service-type)))))
os
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment