1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-24 11:19:35 +01:00

Make docker.nix match Nixpkgs's idioms

1. `target` is the wrong name, that is just for compilers per out
standard terminology. We just need to worry about "build" and "host".

2. We only need one `pkgs`. `pkgs.buildPackages` is how we get anything
we need at build time.

3. `crossSystem` is the name of a nixpkgs parameter that is actually an
attribute set, not a 2-part "cpu-os" string.

3. `pkgsCross` effectively evaluates Nixpkgs twice, which is
inefficient. It is just there for people poking around the CLI / REPL
(and I am skeptical even that is a good idea), and *not* what written
code should use, especially code that is merely parametric in the package set
it is given.

4. We don't need to memoize Nixpkgs here because we are only doing one
pkg set at a time (no `genAttrs`) so it's better to just delete all this
stuff. `flake.nix` instead would do something like that, with
`genAttrs` (though without `pkgsCross`), if and when we have hydra jobs
for cross builds.
This commit is contained in:
John Ericson 2021-11-16 10:32:26 -05:00 committed by Rok Garbas
parent 06ce280a15
commit 066f990d0a
No known key found for this signature in database
GPG key ID: A0E01EF44C27BF00

View file

@ -2,24 +2,11 @@
, lib ? pkgs.lib , lib ? pkgs.lib
, name ? "nix" , name ? "nix"
, tag ? "latest" , tag ? "latest"
, crossSystem ? null
, channelName ? "nixpkgs" , channelName ? "nixpkgs"
, channelURL ? "https://nixos.org/channels/nixpkgs-unstable" , channelURL ? "https://nixos.org/channels/nixpkgs-unstable"
}: }:
let let
buildPkgs = pkgs; defaultPkgs = with pkgs; [
targetPkgs =
if crossSystem != null && crossSystem != pkgs.system
then {
aarch64-linux = pkgs.pkgsCross.aarch64-multiplatform;
armv7l-linux = pkgs.pkgsCross.armv7l-hf-multiplatform.system;
x86_64-linux = pkgs.pkgsCross.gnu64;
powerpc64le-linux = pkgs.pkgsCross.musl-power;
i686-linux = pkgs.pkgsCross.gnu32;
}.${crossSystem}
else pkgs;
defaultPkgs = with targetPkgs; [
nix nix
bashInteractive bashInteractive
coreutils-full coreutils-full
@ -140,17 +127,17 @@ let
baseSystem = baseSystem =
let let
nixpkgs = targetPkgs.path; nixpkgs = pkgs.path;
channel = targetPkgs.runCommand "channel-nixos" { } '' channel = pkgs.runCommand "channel-nixos" { } ''
mkdir $out mkdir $out
ln -s ${nixpkgs} $out/nixpkgs ln -s ${nixpkgs} $out/nixpkgs
echo "[]" > $out/manifest.nix echo "[]" > $out/manifest.nix
''; '';
rootEnv = pkgs.buildEnv { rootEnv = pkgs.buildPackages.buildEnv {
name = "root-profile-env"; name = "root-profile-env";
paths = defaultPkgs; paths = defaultPkgs;
}; };
profile = targetPkgs.runCommand "user-environment" { } '' profile = pkgs.buildPackages.runCommand "user-environment" { } ''
mkdir $out mkdir $out
cp -a ${rootEnv}/* $out/ cp -a ${rootEnv}/* $out/
@ -175,7 +162,7 @@ let
EOF EOF
''; '';
in in
targetPkgs.runCommand "base-system" pkgs.runCommand "base-system"
{ {
inherit passwdContents groupContents shadowContents nixConfContents; inherit passwdContents groupContents shadowContents nixConfContents;
passAsFile = [ passAsFile = [
@ -225,12 +212,12 @@ let
echo "${channelURL} ${channelName}" > $out/root/.nix-channels echo "${channelURL} ${channelName}" > $out/root/.nix-channels
mkdir -p $out/bin $out/usr/bin mkdir -p $out/bin $out/usr/bin
ln -s ${targetPkgs.coreutils}/bin/env $out/usr/bin/env ln -s ${pkgs.coreutils}/bin/env $out/usr/bin/env
ln -s ${targetPkgs.bashInteractive}/bin/bash $out/bin/sh ln -s ${pkgs.bashInteractive}/bin/bash $out/bin/sh
''; '';
in in
targetPkgs.dockerTools.buildLayeredImageWithNixDb { pkgs.dockerTools.buildLayeredImageWithNixDb {
inherit name tag; inherit name tag;