-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake-docker.nix
50 lines (40 loc) · 1.43 KB
/
flake-docker.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{ pkgs }:
let
contents = with pkgs; [ ## Minimal dependencies (~50MB)
nixFlakes coreutils shadow cacert bashInteractive
## Requirements for circleci (~110MB)
git gnutar gzip
];
binPath = pkgs.stdenv.lib.makeBinPath contents;
in
pkgs.dockerTools.buildImage {
name = "johannesloetzsch/nix-flake";
tag = "latest";
contents = contents;
runAsRoot = ''
## nix flakes support
mkdir -p /etc/nix /etc/nixos
echo 'experimental-features = nix-command flakes' > /etc/nix/nix.conf
## keep the flake.nix and the flake.lock
## this allows us to install software of the same pkgs state inside the container
cp ${./flake.nix} /etc/nixos/flake.nix
cp ${./flake.lock} /etc/nixos/flake.lock
## minimal essentials required to run nix
ln -s /etc/ssl/certs/ca-bundle.crt /etc/ssl/certs/ca-certificates.crt
mkdir /tmp/ && chmod 777 /tmp/
groupadd -g 0 root
useradd -u 0 -g root -d /root -m root
groupmems -g root -a root
groupadd --system nixbld
useradd --system -g nixbld nixbld
groupmems -g nixbld -a nixbld
## a few common expectations by other tools
groupadd nogroup
useradd --system -g nogroup nobody
mkdir -p /usr/bin && cp $(${pkgs.which}/bin/which env) /usr/bin/
'';
config = {
Cmd = [ "bash" ];
Env = [ "PATH=${binPath}:/nix/var/nix/profiles/default/bin" ];
};
}