49
Composing System Services in GuixSD or how we came to wonder what a “system service” really is FOSDEM, February 2017

Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

Composing System Servicesin GuixSD

or how we came to wonder what a “system service”really is

FOSDEM, February 2017

Page 2: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm
Page 3: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

(operating-system

(host-name "schememachine")

(timezone "Europe/Brussels")

(locale "fr_BE.utf8")

(bootloader (grub-configuration (device "/dev/sda")))

(file-systems (cons (file-system

(device "my-root")

(title ’label)

(mount-point "/")

(type "ext4"))

%base-file-systems))

(users (cons (user-account

(name "charlie")

(group "users")

(home-directory "/home/charlie"))

%base-user-accounts))

(services (cons* (dhcp-client-service)

(service openssh-service-type)

%base-services)))

Page 4: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

(service openssh-service-type

(openssh-configuration

(x11-forwarding? #t)

(permit-root-login ’without-password)))

Page 5: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

(operating-system

;; ...(services (remove (lambda (service)

(eq? ntp-service-type

(service-kind service)))

%desktop-services)))

Page 6: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

(define %my-services

;; My very own list of services.

(modify-services %desktop-services

(mingetty-service-type config =>

(mingetty-configuration

(inherit config)

(motd (plain-file "motd"

"Howdy FOSDEM!"))))

(upower-service-type config =>

(upower-configuration

(inherit config)

(ignore-lid? #true)

(percentage-critical 5.)))))

Page 7: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

$ guix system build config.scm

...

$ guix system vm config.scm

...

$ guix system container config.scm

...

$ guix system reconfigure config.scm

...

Page 8: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

Linux-libre

Page 9: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

Linux-libre

initial RAM disk

Page 10: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

Linux-libre

initial RAM disk Guile

Page 11: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

Linux-libre

initial RAM disk

PID 1: GNU Shepherdservices...

Guile

Page 12: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

Linux-libre

initial RAM disk

PID 1: GNU Shepherdservices...

Guile

Guile

Page 13: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

Linux-libre

initial RAM disk

PID 1: GNU Shepherdservices...

applications

Guile

Guile

Page 14: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

;; Service definition for the GNU Shepherd (PID 1)

;; embedded in GuixSD.

(shepherd-service

(provision ’(mysql))

(documentation "Run the MySQL server.")

(start (let ((my.cnf (mysql-configuration-file config)))

#~(make-forkexec-constructor

(list (string-append #$mysql "/bin/mysqld")

(string-append "--defaults-file="

#$my.cnf))

#:user "mysql" #:group "mysql")))

(stop #~(make-kill-destructor)))

Page 15: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

;; Shepherd service to mount/unmount a file system.

(with-imported-modules ’((gnu build file-systems))

(shepherd-service

(provision ’(file-system-/home))

(start #~(lambda ()

(mount "/dev/foo" "/home" "ext4")))

(stop #~(lambda ()

(umount "/home")))))

Page 16: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

;; Shepherd service for the BitlBee IRC gateway daemon.

;; Running in a container!

(with-imported-modules ’((gnu build linux-container))

(shepherd-service

(provision ’(bitlbee))

(requirement ’(loopback))

(start #~(make-forkexec-constructor

/container

(list #$(file-append bitlbee "/sbin/bitlbee")

...)))(stop #~(make-kill-destructor)))

)

Page 17: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

;; Shepherd service for the BitlBee IRC gateway daemon.

;; Running in a container!

(with-imported-modules ’((gnu build linux-container))

(shepherd-service

(provision ’(bitlbee))

(requirement ’(loopback))

(start #~(make-forkexec-constructor/container

(list #$(file-append bitlbee "/sbin/bitlbee")

...)))(stop #~(make-kill-destructor))))

worldpremiere!

Page 18: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

Services, take #1.

Page 19: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

user-file-systems

file-systems

root-file-system

file-system-/dev/pts file-system-/dev/shm file-system-/gnu/store

user-processes user-homes

nscd guix-daemon urandom-seedsyslogd term-tty4

udev host-name

term-tty3 term-tty2term-tty1networking

ssh-daemon console-font-tty4 console-font-tty3 console-font-tty2console-font-tty1 loopback

guix system shepherd-graph

Page 20: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

(service

(provision ’(postgres))

(requirement ’(user-processes loopback))

(start #~(make-forkexec-constructor #$postgresql ...))(stop #~(make-kill-destructor)))

(activate #~(begin ...))(user-groups (list (user-group

(name "postgres")

(system? #t))))

(user-accounts (list (user-account

(name "postgres")

(group "postgres")

(system? #t)

(shell ...)))))

Page 21: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

(service

(provision ’(postgres))

(requirement ’(user-processes loopback))

(start #~(make-forkexec-constructor #$postgresql ...))(stop #~(make-kill-destructor))

(activate #~(begin ...)))

(user-groups (list (user-group

(name "postgres")

(system? #t))))

(user-accounts (list (user-account

(name "postgres")

(group "postgres")

(system? #t)

(shell ...)))))

Page 22: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

(service

(provision ’(postgres))

(requirement ’(user-processes loopback))

(start #~(make-forkexec-constructor #$postgresql ...))(stop #~(make-kill-destructor))

(activate #~(begin ...))(user-groups (list (user-group

(name "postgres")

(system? #t))))

(user-accounts (list (user-account

(name "postgres")

(group "postgres")

(system? #t)

(shell ...)))))

Page 23: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

(service

(provision ’(postgres))

(requirement ’(user-processes loopback))

(start #~(make-forkexec-constructor #$postgresql ...))(stop #~(make-kill-destructor))

(activate #~(begin ...))(user-groups (list (user-group

(name "postgres")

(system? #t))))

(user-accounts (list (user-account

(name "postgres")

(group "postgres")

(system? #t)

(shell ...)))))

+ PAM

Page 24: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

(service

(provision ’(postgres))

(requirement ’(user-processes loopback))

(start #~(make-forkexec-constructor #$postgresql ...))(stop #~(make-kill-destructor))

(activate #~(begin ...))(user-groups (list (user-group

(name "postgres")

(system? #t))))

(user-accounts (list (user-account

(name "postgres")

(group "postgres")

(system? #t)

(shell ...)))))

+ PAM

+ /etc

Page 25: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

colord geoclue

polkit elogind upower

udev dbus udisks

Page 26: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

colord geoclue

polkit elogind upower

udev dbus udisks

Page 27: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

colord geoclue

polkit elogind upower

udev dbus udisks

Page 28: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

colord geoclue

polkit elogind upower

udev dbus udisks

Page 29: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

colord geoclue

polkit elogind upower

udev dbus udisks

Page 30: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm
Page 31: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

Composable services.

Page 32: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

Key insight:services “extend” eachother.

Page 33: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

Digression:NixOS configuration.

Page 34: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

{ config, lib, pkgs, ... }:

let

cfg = config.services.openssh;

in {

options = ...;

config = mkIf cfg.enable {

users.extraUsers.sshd = { isSystemUser = true; };

environment.etc = authKeysFiles //

{ "ssh/moduli".source = cfg.moduliFile; };

systemd.services.sshd-service =

{ wantedBy = "multi-user.target";

# ...};

security.pam.services.sshd =

{ startSession = true;

unixAuth = cfg.passwordAuthentication;

};

}

Page 35: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

colord geoclue

polkit elogind upower

udev dbus udisks

shepherd /etc

.rules .service

Page 36: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

colord geoclue

polkit elogind upower

udev dbus udisks

shepherd /etc

.rules .service

Page 37: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

colord geoclue

polkit elogind upower

udev dbus udisks

shepherd /etc

.rules .service

Page 38: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

what users type

(operating-system

(host-name "schememachine")

;; ...(services (cons* (dhcp-client-service)

(service openssh-service-type

(openssh-configuration

(x11-forwarding? #t)

(permit-root-login

’without-password)))

(service nginx-service-type ...)%base-services)))

Page 39: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

Services,service types.

Page 40: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

system

profile

etc

activate

boot

shepherd-root

guix

account

file-systems

fstab user-file-systems root-file-system user-processes 4host-name komputilo udevnscd syslogstatic-networking mingetty

openssh

dhcp-clientpam

login

cleanup

firmware linux-bare-metal setuid-program

guix system extension-graph config.scm

Page 41: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

system

profile

etc

activate

boot

shepherd-root

guix

account

elogind

file-systems udev dbus

polkit

pam

upower

udisks

wicd avahi

nscd

slim

xfce-desktopgnome-desktop

fstab user-file-systems root-file-systemuser-processes 4 host-name antelope syslogstatic-networking mingetty

ntp

setuid-program

geoclue

colord

mtp

login screen-locker screen-locker

cleanup

firmware linux-bare-metal

guix system extension-graph config.scm

Page 42: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

fold-services.

Page 43: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

Dear Haskeller,this is a monoid!

Page 44: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

Wrap-up.

Page 45: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

GuixSD leveragesa holistic approachto system services.

Page 46: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

I services can use and extend PID 1I “service extensions” capture

all the service aspectsI makes complex configurations tractable

I come up with your own services!

Page 47: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

I services can use and extend PID 1I “service extensions” capture

all the service aspectsI makes complex configurations tractableI come up with your own services!

Page 48: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

[email protected] https://gnu.org/software/guix/

Page 49: Composing System Services in GuixSD · $ guix system build config.scm... $ guix system vm config.scm... $ guix system container config.scm... $ guix system reconfigure config.scm

Copyright c© 2010, 2012–2017 Ludovic Courtes [email protected].

GNU GuixSD logo, CC-BY-SA 4.0, http://gnu.org/s/guix/graphicsCopyright of other images included in this document is held by their respective owners.

This work is licensed under the Creative Commons Attribution-Share Alike 3.0 License. To view acopy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter toCreative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.

At your option, you may instead copy, distribute and/or modify this document under the terms of theGNU Free Documentation License, Version 1.3 or any later version published by the Free SoftwareFoundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of thelicense is available at http://www.gnu.org/licenses/gfdl.html.

The source of this document is available from http://git.sv.gnu.org/cgit/guix/maintenance.git.