Let $F(d_1,d_2,\ldots,d_k;n )$ be the variety of all flags $\mathbb A^{d_1} \subset\mathbb A^{d_2}\subset\ldots\subset \mathbb A^{d_k}\subset \mathbb A^{n}$. This variety has the natural maps to Grassmann varieties: $$ f_i:F(d_1,d_2,\ldots,d_k; n) \to F(d_i;n), $$ and pull-backs $f_i^*\mathcal O(1)$ from Grassmannians give a basis of $\mathrm{Pic}(F(d_1,\ldots,d_k;n))$. Or, combinatorially, the pullbacks of the unique Shubert divisors on Grassmannians are Shubert divisors on $F(d_1,\ldots,d_k;n)$ and they generate the Picard group.

How can one calculate the canonical class of $F(d_1,\ldots, d_k; n)$ in these terms?

Or, one can ask more general question.

Let $G/P$ be a projective homogeneous space. Here $P\subset G$ is parabolic and $G/P$ can be described by a system of roots (for $G$) and its subsystem (for $P$). How can one calculate the canonical class of $G/P$ in this terms?