Skip to content

Commit 99c20e6

Browse files
authored
Merge pull request #13328 from h0nIg/patch-3
docker: add docu references & remove duplicate code
2 parents 6bf997e + ba12adc commit 99c20e6

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

docker.nix

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -176,24 +176,20 @@ let
176176
"${k}:x:${toString gid}:${lib.concatStringsSep "," members}";
177177
groupContents = (lib.concatStringsSep "\n" (lib.attrValues (lib.mapAttrs groupToGroup groups)));
178178

179-
defaultNixConf = {
180-
sandbox = "false";
179+
toConf =
180+
with pkgs.lib.generators;
181+
toKeyValue {
182+
mkKeyValue = mkKeyValueDefault {
183+
mkValueString = v: if lib.isList v then lib.concatStringsSep " " v else mkValueStringDefault { } v;
184+
} " = ";
185+
};
186+
187+
nixConfContents = toConf {
188+
sandbox = false;
181189
build-users-group = "nixbld";
182190
trusted-public-keys = [ "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" ];
183191
};
184192

185-
nixConfContents =
186-
(lib.concatStringsSep "\n" (
187-
lib.mapAttrsToList (
188-
n: v:
189-
let
190-
vStr = if builtins.isList v then lib.concatStringsSep " " v else v;
191-
in
192-
"${n} = ${vStr}"
193-
) (defaultNixConf // nixConf)
194-
))
195-
+ "\n";
196-
197193
userHome = if uid == 0 then "/root" else "/home/${uname}";
198194

199195
baseSystem =
@@ -211,10 +207,7 @@ let
211207
echo "[]" > $out/manifest.nix
212208
fi
213209
'';
214-
rootEnv = buildPackages.buildEnv {
215-
name = "root-profile-env";
216-
paths = defaultPkgs;
217-
};
210+
# doc/manual/source/command-ref/files/manifest.nix.md
218211
manifest = buildPackages.runCommand "manifest.nix" { } ''
219212
cat > $out <<EOF
220213
[
@@ -244,11 +237,15 @@ let
244237
]
245238
EOF
246239
'';
247-
profile = buildPackages.runCommand "user-environment" { } ''
248-
mkdir $out
249-
cp -a ${rootEnv}/* $out/
250-
ln -s ${manifest} $out/manifest.nix
251-
'';
240+
profile = buildPackages.buildEnv {
241+
name = "root-profile-env";
242+
paths = defaultPkgs;
243+
244+
postBuild = ''
245+
mv $out/manifest $out/manifest.nix
246+
'';
247+
inherit manifest;
248+
};
252249
flake-registry-path =
253250
if (flake-registry == null) then
254251
null
@@ -280,6 +277,7 @@ let
280277
set -x
281278
mkdir -p $out/etc
282279
280+
# may get replaced by pkgs.dockerTools.caCertificates
283281
mkdir -p $out/etc/ssl/certs
284282
ln -s /nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt $out/etc/ssl/certs
285283
@@ -307,16 +305,20 @@ let
307305
mkdir -p $out${userHome}
308306
mkdir -p $out/nix/var/nix/profiles/per-user/${uname}
309307
308+
# see doc/manual/source/command-ref/files/profiles.md
310309
ln -s ${profile} $out/nix/var/nix/profiles/default-1-link
311310
ln -s /nix/var/nix/profiles/default-1-link $out/nix/var/nix/profiles/default
312311
312+
# see doc/manual/source/command-ref/files/channels.md
313313
ln -s ${channel} $out/nix/var/nix/profiles/per-user/${uname}/channels-1-link
314314
ln -s /nix/var/nix/profiles/per-user/${uname}/channels-1-link $out/nix/var/nix/profiles/per-user/${uname}/channels
315315
316+
# see doc/manual/source/command-ref/files/default-nix-expression.md
316317
mkdir -p $out${userHome}/.nix-defexpr
317318
ln -s /nix/var/nix/profiles/per-user/${uname}/channels $out${userHome}/.nix-defexpr/channels
318319
echo "${channelURL} ${channelName}" > $out${userHome}/.nix-channels
319320
321+
# may get replaced by pkgs.dockerTools.binSh & pkgs.dockerTools.usrBinEnv
320322
mkdir -p $out/bin $out/usr/bin
321323
ln -s ${lib.getExe' coreutils-full "env"} $out/usr/bin/env
322324
ln -s ${lib.getExe bashInteractive} $out/bin/sh

0 commit comments

Comments
 (0)