Skip to content

Non-standard directory in platform #1460

Closed

Description

@jtojnar

I am packaging Flatpak on NixOS and am currently stuck on making the installed tests work. In particular, make-test-runtime.sh script is not really compatible with Nix ways.

Nix ditches the traditional FHS in favour of each package having its own hierarchy under /nix/store. For example, Flatpak will have something like the following:

/nix/store/5imy6c6gpfijrlfgch2801jwnnqk63r2-flatpak-0.11.3
├── bin
│  ├── flatpak
│  └── flatpak-bisect
├── etc
│  ├── dbus-1
│  │  └── …
│  └── profile.d
│     └── flatpak.sh
├── include
│  └── …
├── lib
│  ├── girepository-1.0
│  │  └── Flatpak-1.0.typelib
│  └── …
├── libexec
│  └── …
└── share
   └── …

We might be tempted to merge the package hierarchies into a single FHS-compliant tree, after all, that is basically what traditional package managers do, but Nix relies heavily on absolute paths, so this method would almost certainly lead to a broken platform. For that reason, I have decided to copy the whole transitive closure of required packages to the platform, and then symlink the executables from the FHS tree. Here is the modified code:

#!/bin/sh

set -e

DIR=`mktemp -d`

REPONAME=$1
shift
ID=$1
shift
COLLECTION_ID=$1
shift

mkdir ${DIR}/files
mkdir ${DIR}/usr
cat > ${DIR}/metadata <<EOF
[Runtime]
name=${ID}
EOF

cat ${DIR}/metadata

# Add bash and dependencies
mkdir -p ${DIR}/nix/store
mkdir -p ${DIR}/usr/bin
mkdir -p ${DIR}/usr/lib
ln -s ../lib ${DIR}/usr/lib64
ln -s ../lib ${DIR}/usr/lib32
if test -f /sbin/ldconfig.real; then
    cp /sbin/ldconfig.real ${DIR}/usr/bin/ldconfig
else
    cp `which ldconfig` ${DIR}/usr/bin
fi
for i in $@; do
    I=$(readlink -f $(which $i))
    requisites=$(nix-store --query --requisites "$I")
    for r in $requisites; do
        # a single store item can be needed by multiple paths, no need to copy it again
        if [ ! -e ${DIR}/$r ]; then
            # --no-preserve since we do not want read-only tree
            cp --no-preserve=mode -r $r ${DIR}/$r
        fi
    done
    ln -s $I ${DIR}/usr/bin/$i
done

# We copy the whole locale archive because we do not have C.UTF8 locale
mkdir -p ${DIR}/usr/lib/locale/
cp @glibcLocales@/lib/locale/locale-archive ${DIR}/usr/lib/locale/locale-archive

if [ x$COLLECTION_ID != x ]; then
    collection_args=--collection-id=${COLLECTION_ID}
else
    collection_args=
fi

mkdir -p repos
flatpak build-export ${collection_args} --runtime ${GPGARGS-} repos/${REPONAME} ${DIR}
rm -rf ${DIR}

Running it as make-test-runtime.sh test org.test.Platform bash true will result in the following $DIR

/tmp/tmp.EIY7o8XZyP
├── files
├── metadata
├── nix
│  └── store
│     ├── 069g827lh3hrhp4vkcq3rsh5jh65pm3l-ncurses-6.0-20171125
│     │  └── …
│     ├── 2kcrj1ksd2a14bm5sky182fv2xwfhfap-glibc-2.26-131
│     │  └── …
│     ├── 9xg3d7r173zzybgh8v4lhf3zcf0wx51g-bash-4.4-p12
│     │  ├── …
│     ├── a2vpf37zn5z4k6r6cvydl3m1i0757i73-readline-7.0p3
│     │  └── …
│     ├── cb3slv3szhp46xkrczqw7mscy5mnk64l-coreutils-8.29
│     │  ├── bin
│     │  │  ├── …
│     │  │  ├── true -> coreutils
│     │  │  ├── …
│     │  │  └── yes -> coreutils
│     │  ├── libexec
│     │  │  └── …
│     │  └── share
│     │     └── …
│     ├── lird33c2j4mr289q1q17qihqhwq188wh-acl-2.2.52
│     │  └── …
│     ├── z3mpzgxjzx72l64pw3glppj48cd49lm8-attr-2.4.47
│     │  └── …
│     └── zqh3l3lyw32q1ayb15bnvg9f24j5v2p0-bash-4.4-p12
│        ├── bin
│        │  ├── bash
│        │  └── sh -> bash
│        └── lib
│           └── …
└── usr
   ├── bin
   │  ├── bash -> /nix/store/9xg3d7r173zzybgh8v4lhf3zcf0wx51g-bash-4.4-p12/bin/bash
   │  ├── ldconfig
   │  └── true -> /nix/store/cb3slv3szhp46xkrczqw7mscy5mnk64l-coreutils-8.29/bin/coreutils
   ├── lib
   ├── lib32 -> ../lib
   └── lib64 -> ../lib

But ostree ls --repo repos/${REPONAME} runtime/${ID}/x86_64/master -R will show, the Nix store is not really added. Actually, it seems only the contents of /usr is used:

d00755 0 0      0 /
-00644 0 0     33 /metadata
d00755 0 0      0 /files
l00777 0 0      0 /files/lib32 -> ../lib
l00777 0 0      0 /files/lib64 -> ../lib
d00755 0 0      0 /files/bin
l00777 0 0      0 /files/bin/bash -> /nix/store/9xg3d7r173zzybgh8v4lhf3zcf0wx51g-bash-4.4-p12/bin/bash
-00755 0 0 909152 /files/bin/ldconfig
l00777 0 0      0 /files/bin/true -> /nix/store/cb3slv3szhp46xkrczqw7mscy5mnk64l-coreutils-8.29/bin/coreutils
d00755 0 0      0 /files/lib
d00755 0 0      0 /files/lib/locale
-00644 0 0 114228912 /files/lib/locale/locale-archive

How would I go about retaining the /nix/store inside the platform?

Activity

  1. jtojnar commented on Mar 14, 2018

    @jtojnar
    ContributorAuthor

    I solved it by changing /nix/store to /usr/store and seding the references in all the files, see NixOS/nixpkgs#33371

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions