Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@jason-chandler
Copy link

jason-chandler commented Jun 23, 2021

This really could not be simpler, thanks a lot!

@minikN
Copy link

minikN commented Jul 27, 2021

Hello, how would I actually run guix after installing it? Is guix-init.sh only for one-time initialisation, or should it be used to run guix every time? Because for me nothing happens:

PS C:\Users\deb> wsl.exe -d guix /bin/busybox sh -c "/mnt/c/Users/deb/Desktop/guix-init.sh"
PS C:\Users\deb>

But this seems to work:

PS C:\Users\deb> wsl -d guix
-bash-5.0# uname -a
Linux guix 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 GNU/Linux
-bash-5.0#

What is the proper way? Thanks!

@jason-chandler
Copy link

jason-chandler commented Jul 28, 2021

Hello, how would I actually run guix after installing it? Is guix-init.sh only for one-time initialisation, or should it be used to run guix every time? Because for me nothing happens:

PS C:\Users\deb> wsl.exe -d guix /bin/busybox sh -c "/mnt/c/Users/deb/Desktop/guix-init.sh"
PS C:\Users\deb>

But this seems to work:

PS C:\Users\deb> wsl -d guix
-bash-5.0# uname -a
Linux guix 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 GNU/Linux
-bash-5.0#

What is the proper way? Thanks!

You only need to rerun
wsl.exe -d guix /bin/busybox sh -c "/mnt/c/Users/deb/Desktop/guix-init.sh"
whenever
'wsl -d guix' returns '-bash: /run/current-system/profile/etc/profile: No such file or directory'
as this error means herd is not running, which is a prerequisite to start Guix-SD.

After you run that top command again, herd will start up and you can access 'wsl -d guix' as normal.
From there it's like a regular Guix-SD install and you can use "guix install package" or whatever else.

I prefer to use the Windows Terminal app since it adds a convenient dropdown arrow to simply click guix from the Windows shell.
Good luck!

@minikN
Copy link

minikN commented Jul 29, 2021

You only need to rerun
wsl.exe -d guix /bin/busybox sh -c "/mnt/c/Users/deb/Desktop/guix-init.sh"
whenever
'wsl -d guix' returns '-bash: /run/current-system/profile/etc/profile: No such file or directory'
as this error means herd is not running, which is a prerequisite to start Guix-SD.

After you run that top command again, herd will start up and you can access 'wsl -d guix' as normal.
From there it's like a regular Guix-SD install and you can use "guix install package" or whatever else.

I prefer to use the Windows Terminal app since it adds a convenient dropdown arrow to simply click guix from the Windows shell.
Good luck!

Thank you. I changed two things.

  1. I added my guix channels in the first script so I could make use of them in the .scm file
cat <<EOM >> /etc/guix/channels.scm
(cons* (channel
        (name 'flat)
        (url "https://github.com/flatwhatson/guix-channel.git")
        (introduction
         (make-channel-introduction
          "33f86a4b48205c0dc19d7c036c85393f0766f806"
          (openpgp-fingerprint
           "736A C00E 1254 378B A982  7AF6 9DBE 8265 81B6 4490"))))
       (channel
        (name 'nonguix)
        (url "https://gitlab.com/nonguix/nonguix")
        ;; Enable signature verification:
        (introduction
         (make-channel-introduction
          "46c1d8bcca674d3a71cd077c52dde9552a89873d"
          (openpgp-fingerprint
           "2A39 3FFF 68F4 EF7A 3D29  12AF 6F51 20A0 22FB B2D5"))))
       %default-channels)
EOM
  1. I changed the guix system reconfigure command in the first script to this:
guix system reconfigure --no-bootloader --no-grafts -L $(dirname $(readlink -f $1)) $1

That way you can manually specify the path to the .scm file instead of hardcoding it, it enables you to also use self-written modules (like for example I have a base-system.scm and then a wsl.scm inheriting from it) as long as they are in the same load path.

I use it like this:

wsl -d guix /bin/busybox sh -c "/mnt/c/Users/deb/Desktop/guix/guix-infect.sh /mnt/c/Users/deb/Desktop/guix/wsl.scm"

@Thorocaine
Copy link

Thorocaine commented Oct 8, 2021

He, I know I am probably being stupid, but could you give me an instruction on how to run this?

I ended up here after following your comment from https://gist.github.com/giuliano108/49ec5bd0a9339db98535bc793ceb5ab4
(Which I also can't get working)

@minikN
Copy link

minikN commented Oct 8, 2021

He, I know I am probably being stupid, but could you give me an instruction on how to run this?

I ended up here after following your comment from https://gist.github.com/giuliano108/49ec5bd0a9339db98535bc793ceb5ab4 (Which I also can't get working)

I wrote a guide about it: https://github.com/minikN/wiki-site/blob/main/content/guix/wsl.org (may not be fully correct but should serve as a foundation)

@Thorocaine
Copy link

Thorocaine commented Oct 8, 2021

I wrote a guide about it: https://github.com/minikN/wiki-site/blob/main/content/guix/wsl.org (may not be fully correct but should serve as a foundation)

That was a quick response.
I'm going to try this now. Thank you 😁

@rekado
Copy link

rekado commented Dec 8, 2021

There is some overlap between this and the script at https://guix.gnu.org/install.sh. Would you be willing to contribute changes to this installer script so that installation to WSL works out of the box?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment