►
From YouTube: NixOS Office Hours, 2019-12-13
Description
Today Eelco Dolstra is coming to talk about how we're using Rust in Nix, a C++ project.
A
From
different
frets,
so
it
needs
to
be
guarded
so
okay,
so
this
is
just
an
example
of
how
much
nicer
rust
is,
and
it's
not
just
the
language
there's
also
the
the
ecosystem
so
and
so
in
on
the
west
side
to
do
HTTP
requests,
I
can
just
use
racast
or
I
can
just
use
hyper.
So
I
can
say:
client
dog
gets
on
a
URL
and
that's
all
I
need
to
do,
whereas
on
the
c+
website.
A
A
Http
requests,
so
that's
all
code
that
you
can
just
get
rid
of
if
you're
feeling
lost,
so
that's
so
much
nicer
world
so
would
have
been
great
if
Nix
was
written
in
rust
from
the
start,
but
it
isn't
so
all
these
nice
nice
code
is
basically
useless,
so
we
can't
use
it
in
the
C++
code
base,
because
there
is
no
very
clear
story
as
to
how
you
could
extend
the
C++
code
base
in
rust.
The
rust
C++
interrupt
story
is
not
very
great.
A
Basically,
the
interrupt
story
with
is
rust
and
C,
as
we
can
call
C
functions
from
rust,
or
vice
versa.
We're
doing
we
have
any
sort
of
non-trivial
interaction
with
the
C++
code
base.
As
far
as
you
know,
a
lot
of
solutions
for
that
sort
of
example.
In
this
particular
case,
what
I
would
really
like
is
to
write
things
like
storing
permutations
in
rust
or
something
like
the
binary
cash
store.
A
I
would
be
pretty
trivial
to
to
rewrite
and
rust,
as
this
example
shows,
but
the
problem
is,
of
course,
that
it
needs
to
subclass
the
C++
class.
So
that's
this
thing
over
here
and
so
you
can
use
codes
based
or
class
and
have
to
somehow
subclass
step
from
rust
and
yeah.
That's
that's
not
possible!
So
and
so
I
don't
know
how
to
do
that.
So
that's
that's!
For
now,
yeah
this
code
over
here
is
yeah.
It's
fully
code,
it's
nice,
but
it
doesn't
do
anything.
B
So
so
it
seems
to
explain
that
if
Knicks
were
in
rust,
it
would
make
you
a
lot
happier
right.
Yes,.
A
B
A
A
A
So
there's
this
little
function
on
bekstaarr
file,
which
takes
a
path
which
is
the
path
to
the
sorry
which
is
the
after
the
destination
directory,
and
it
takes
this
Finkle
is
a
source
which,
which
is
basically
the
rest,
read
class,
only
it's
actually
the
C++
source
class
that
we
have
to
make
so
so
that
actually
allows
calling
back
into
the
C++
code
so
yeah.
So
this
just
uses
the
dark
rate
to
enumerate
the
contents
of
authority,
L
right
disks
or
create
directories
like
files,
great
symlinks
yeah,
and
so
we
can
call
this
from
from
C++.
A
So
there's
a
little
bit
of
complexity
going
on
here,
but
not
much
really
so
we
use
extra
messy
bindings,
so
there's
no
extra
in
C++.
If
you
want
to
you
can't
pass,
you
can't
call
C++
functions
from
rust.
You
can
only
call
C
functions
and
yeah
and
vice
versa.
If
you
want
to
call
a
rust
function
from
C++,
you
have
to
write
a
essentially
a
wrapper
function
on
the
left
side
that
has
C
linkage.
So
that's
this
unpacked
our
file
function
and
some
complexity.
A
C
Of
unavoidable
so
I'm
an
honest
topic
of
Interop
I
know:
there's
been
some
heartburn
around
some
of
the
some
of
the
choices
about
the
datatypes
being
used
in
rest
and
used
in
c++
and
some
concerns
around.
How
would
the
the
ABI
for
c++
isn't
stable
and
the
ABI
for
rust
isn't
stable?
So
how
do
you
take
to
unstable
api's
and
have
them
happily
talk
to
each
other?
So.
A
A
A
And
that
it's
followed
by
the
contents
of
that
type
or
the
error
which,
which
is
always
an
exception
pointer
in
this
case,
but
so
in
theory
yeah,
the
the
memory
representation
of
the
result
type
could
change.
So
if
they
change
the
they
will
arrest
compiler
that
all
the
definition
of
the
result
died.
Then
this
could
change,
but
it's
not
particularly
likely
that
that
will
change.
I
believe.
B
We
have
some
of
the
question.
It's
puck.
D
I
have
been
the
one
that
has
been
also
noting
some
of
these
concerns,
because
there's
more
issues
than
just
the
fact
that
the
ABI,
for
example,
one
of
the
examples
which
I
am
somewhat
surprised
you
haven't
hit
yet,
is
that
the
rest
is
Naish
filling
where
in
the
case,
that's
an
enum.
For
example,
if
you
have
a
box
of
some
some
sorts,
it
can't
ever
be
null.
So
if
you
have
them
so
it
can
do
some
optimizations
by
using
the
null
value
for
something
else.
D
A
A
I
mean
it's
it's
it's.
Our
undefined
behavior
can
occur
if
the
compiler
starts
making
so,
for
example,
in
C++.
If
you
have
something
like
and
you
collude
or
you
try
to
do
something
with
them,
I
mean
it's
very
good
component
could
be
making
arbitrary
assumptions
or
optimizations.
So
anything
could
happen
there,
but
here
the
layout
of
the
data
pipe,
it
must
have
a
layout
so
that
layout
might
change
in
some
future
version
of
the
compiler.
A
D
Layouts
of
structs
in
c++
is,
as
far
as
I
understand,
completely
defined,
but
in
rust
anything
that's
repres
like
the
rust
representation,
is
not
anything
and
not
specified
its
structure,
but
it's
also
completely
unspecified,
even
if
the
two
completions
of
the
same
binary
at
the
same
source,
more
end
up
with
the
same
stroke.
Layouts
that
is
all
allowed
to
channel
and
I
have
actually
been
talking
and
I
have
been
thinking
about
actually
changing
a
very
slight
we're
like
making
a
very
slight
change
in
the
rest,
compiler
and
I'm
just
testing
italics.
D
A
So,
of
course,
so
if
if
that
changes,
then
this
will
break
and
then
we
need
to
fix
this
but
yeah
so
I'm
relatively
unworried
about
that
I
mean
so.
It
makes
other
assumptions
here,
I
like
the
the
layout
of
a
slice,
that's
a
pointer,
followed
by
size,
yeah,
and
it's
also
something
that
they
could
flip
those
around.
A
D
B
E
E
Okay,
okay
I
was
wondering
supposed
that
the
Knicks
would
be
written
in
rust.
This
means
that
basically
rust
would
become
an
assistant
dependency
of
the
lowest
level
of
the
whole
ecosystem
right
you
would
need
a
compiler
to
compile
Nicks
and
my
understanding
I
have
very
little
practical
experience
with
rust,
so
I
know
for
sure
what
I've
seen
is
that
compiling
rust
is
actually
not
simple,
because
the
compiler
is
being
very
quickly
involves
the
language
standard,
so
you
can't
just
use
any
version
of
the
compiler
to
compile
any
other
source
code.
E
You
need
very
specific
version
ranges
to
get
certain
features
and
build
runs
for
several
hours
on
a
fast
machine,
and
this
all
sounds
to
me
like
this
is
a
major
investment
right
that
we
say
you
have
to
provide
the
birth
compiler
before
you
can
get
next.
Is
that
do
you
share
that
concern,
or
do
you
have
a
work
around
for
that
or
and
I
just
completely
off
with
that
motion.
A
Yeah,
so
that
that's
an
issue
but
I
mean,
unfortunately,
we
have
Nicks
for
that.
So
if
you
just
one
big
shell,
then
you
get
the
build
environment
for
building
mix
so
which
includes
the
rest
compiler
from
the
binary
cash.
So
in
practice
it's
it's
yeah.
It
makes
the
sort
of
the
closure
for
building
makes
bigger,
obviously
or
quite
a
big,
bigger
bust
is
pretty
big,
so
yeah
I
mean
that
is
a
downside,
but
I
think.
A
B
A
Okay
yeah,
so
I
don't
know
about
that,
but
I
think
in
principle
the
west's
cross-compilation
situation,
as
far
as
I
know,
is
much
better
than
with
C++
compilers
in
general,
but
I
might
be
wrong
about
that.
But
as
far
as
I
know,
it's
pretty
easy
to
cross
compiler,
Scouts
or
at
least
fuel
to
do
things
like
that
compiled
to
assembly.
That's
very
easy,
yeah
might
be
show
me
some
problems
there.
It
might
be
that
it's
more
of
a
problem
in
how
we
hook
up
rustic
are
going
to
make
files.
A
A
A
A
Yeah,
but
so
that
doesn't
really
help
because
on
both
sides
of
the
connection,
you
need
a
huge
amount
of
C++
code,
a
actually
you
need
basically
the
same
amount
of
code.
The
only
difference
between
the
demon
and
the
client
side
is:
what
do
you
use
the
remote
store,
the
local
store
class,
so
yeah?
Everything
else
is
the
same.
A
A
There's
no
I
mean
so
rewriting
the
demon
in
rust
would
actually
be
very
nice
with
site
security,
but
yeah,
then
you
would
have
to
rewrite
local
store,
which
is
yeah
a
huge
amount
of
code
there.
So
something
like
local
store.
That's
Lucy
is
fifteen
hundred
CCS
5,000
lines
and
and
and
there's
a
lot
more
source
files,
and
so
that
that's
all
the
stuff
you
would
have
to
rely
just
to
get
the
demon
to
work
and.
A
C
A
But
that
sounds
like
it
would
actually
be
more
codes
than
f
of
I.
So
the
problem
with
this
secret
plus
F
the
fly
is
that
you
need
to
do
a
lot
of
marshal,
aiming
to
get
say:
C++
datatypes
into
the
into
the
CFO
file
format,
and
and
vice
versa,
and
if
you
went
but
so
now,
you
would
have
to
write
quite
a
lot
of
code
with
if
you
serialize
it.
You
also
have
to
write
a
lot
of
code,
so
it
would
not
necessarily
be
the
easier
and
it
occurred
to
overthink.
A
A
D
D
So
you
just
basically
write
C
bindings
for
the
existing
for,
for
example,
the
store
class.
You
could
write
a
function.
You
could
write
an
implementation
of
that
class
that
just
defers
everything
to
arrest,
enter
like
arrests,
extra
and
see
set
of
functions
and
then,
on
the
other
side,
have
the
exact
opposite.
Where
yeah
they
will.
You
also
have
a
dynamic
traits
objects
that
you
then
use
to
implements
that
you
then
use
have
a
generic
store
on
the
west
side.
D
A
A
D
A
A
D
A
A
So
if
these
flip
around
then
Bergen
will
crash
right
away,
it's
not
going
to
crash
randomly
for
certain
inputs.
It's
it's
going
to
crash
really
Victor
mystically.
So
the
test
suite
will
cover
that
I
mean
we
can
definitely
add
an
explicit
vest
for
that.
My
phone
was
kind
of
I
mean
that
desk
doesn't
really
add
a
lot
over
the
implicit
vest.
I
mean
this
is
already
covered.
What.
A
So
it
used
to
be
an
ad
thing
that
C++
API
we
pass
through
pass
around
us
as
unchecked
strings,
and
now
it's
a
more
so
sorry
how
you
could
pass
completely
invalid
store
path
to
a
store
function.
So,
for
example,
a
couple
of
weeks
ago,
we
have
a
book
that
it
doesn't
actually
check
anywhere
that
whether
the
name
is
non-empty
so
nowadays
so
now
it
uses
a
a
store
path
value.
So
all
these
functions
in.
A
Like
say,
it's
valid
path
takes
a
store
path
as
an
argument
and
the
constructor
of
store
path,
checks
that
the
store
path
is
is
Fallot,
so
the
hash
positive,
the
install
path
is
a
is
a
base
for
the
to
hash.
The
main
parts
is
most
non
empty
and
only
contains
fellow
characters.
So
if
you
can
construct
a
store
bath
object,
then
you
know
that
it's
a
synthetic
app.
So
after
that
you
don't
have
to
check
anything
anymore.
So
it's
just
a
more
like
safe
interface,
so
the
store
bath
class
is
implemented
in
rust.
So.
A
So,
for
example,
there
are
functions
like
store
path,
name
which
gets
the
name,
but
it
because
the
FFI
function
to
extract
the
name.
So
so
it
doesn't
make
any
assumptions
about
the
internal
layout.
The
only
nasty
finger
is
left.
Currently,
it
needs
to
know
what
the
size
of
the
store
path
object
is,
so
that's
currently
hard
to
go
through
then,
the
super
one,
the
C++
side
and
that's,
obviously,
very
nasty.
A
A
C
A
A
A
Yeah,
okay
and
then
probably
so,
I
mean
the
the
the
adventurous
part.
Really
here
is
the
having
move
semantics
between
West
and
C++
self,
and
these
values
like
store
paths,
we're
not
returning
pointer
Stewie
strings,
but
we
were
returning
the
actual
values
which
works
fine,
because
dust
values
are
it's
just
that
the
only
complication
is
that
exceed
bus
was
when
a
rebellious,
be
moved
out
of
is
a
dynamic
property.
A
So
if
you
move
a
a
rushed
value
around
now,
you
have
to
know
when
to
well
its
destructor
or
its
drug
function,
and
that
makes
it
a
bit
tricky,
but
probably
returning
structs
like
store
path,
yeah
I'm,
not
sure
whether
that's
covered
by
the
a
yeah
I
mean
it
doesn't
give
any
error
messages
about
it.
So
I
suppose
it's
fine,
but.
A
C
C
Alright,
so
we'll
get
that
open
right
after
we
end
this
call
for
what
it's
worth
our
next
edition
of
office
hours
is
on
December
27th
it'll,
be
probably
pretty
casual
with
like
a
cleric
west
review,
nothing
to
commit
it,
and
it
may
also
not
even
be
recorded,
because
I'll
probably
be
out
of
town,
but
I
will
be
present.
Thank
you
everybody
for
coming.
Thank
you
also
for
coming
and
talking
about
your
your
work
with
rust,
yeah.