Skip to content

Commit 38766d3

Browse files
committed
Configure fonts on both docker containers
1 parent 8d55304 commit 38766d3

3 files changed

Lines changed: 33 additions & 14 deletions

File tree

Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ RUN nix-shell -p dos2unix --run 'find . -exec dos2unix {} +'
1919
# itselves) using the default nix binary cache.
2020
RUN nix-build
2121

22+
# Build required fonts and their cache.
23+
RUN mkdir -p /etc/fonts && nix-build nix/fontconfig.nix --out-link /etc/fonts/fonts.conf
24+
RUN mkdir -p /var/cache/fontconfig && nix-shell -p fontconfig --run fc-cache
25+
2226
# Copy DiffDetective with all runtime dependencies (ignoring build-time
2327
# dependencies) to a separate folder. Such a subset of the Nix store is called a
2428
# closure and enables us to create a minimal Docker container.
2529
RUN mkdir closure
26-
RUN nix-store -qR result | xargs cp -Rt closure
30+
RUN nix-store -qR result /etc/fonts/fonts.conf | xargs cp -Rt closure
2731

2832
# Start building the final container.
2933
FROM scratch
@@ -40,5 +44,9 @@ COPY --from=builder /home/user/result /DiffDetective
4044
# Copy the necessary data. Beware that this directory might have impure files.
4145
COPY data /home/user/data
4246

47+
# Install fonts
48+
COPY --from=builder /etc/fonts/fonts.conf /etc/fonts/fonts.conf
49+
COPY --from=builder /var/cache/fontconfig /var/cache/fontconfig
50+
4351
ENV DISPLAY=:0 HOME=/home/user
4452
CMD ["/DiffDetective/bin/DiffDetective-Demo"]

nix/docker.nix

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,12 @@ in {
1616

1717
copyToRoot = pkgs.buildEnv {
1818
name = "DiffDetective-Demo-image-root";
19-
paths = [ (DiffDetectiveDemo.src + "/data") ];
19+
paths = [(DiffDetectiveDemo.src + "/data")];
2020
extraPrefix = config.WorkingDir + "/data";
2121
};
2222

2323
runAsRoot = ''
24-
mkdir -p /etc/fonts
25-
26-
cat >/etc/fonts/fonts.conf <<"EOF"
27-
<?xml version="1.0" encoding="UTF-8"?>
28-
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
29-
<fontconfig>
30-
<description>Configuration file</description>
31-
<dir>${pkgs.dejavu_fonts}/share/fonts</dir>
32-
<cachedir>/var/cache/fontconfig</cachedir>
33-
</fontconfig>
34-
EOF
35-
24+
install -Dm644 ${import ./fontconfig.nix {inherit sources system pkgs;}} /etc/fonts/fonts.conf
3625
mkdir -p /var/cache/fontconfig
3726
${pkgs.fontconfig}/bin/fc-cache
3827
'';

nix/fontconfig.nix

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
sources ? import ./sources.nix,
3+
system ? builtins.currentSystem,
4+
pkgs ?
5+
import sources.nixpkgs {
6+
overlays = [];
7+
config = {};
8+
inherit system;
9+
},
10+
}:
11+
pkgs.writeTextFile {
12+
name = "fonts.conf";
13+
text = ''
14+
<?xml version="1.0" encoding="UTF-8"?>
15+
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
16+
<fontconfig>
17+
<description>Configuration file</description>
18+
<dir>${pkgs.dejavu_fonts}/share/fonts</dir>
19+
<cachedir>/var/cache/fontconfig</cachedir>
20+
</fontconfig>
21+
'';
22+
}

0 commit comments

Comments
 (0)