Skip to content

Instantly share code, notes, and snippets.

Nixpkgs: issues with stdenv.mkDerivation

This document describes some of the issues that exist with stdenv.mkDerivation and that could or should be considered when redesigning it.

Phase ordering

stdenv.mkDerivation comes with several fixed phases. It is possible to override these phases or add other phases. It is however difficult to make phases depend on one another as that requires describing their relative order

@FRidh
FRidh / default.nix
Last active November 20, 2019 17:16
Override Python interpreter to obtain older version (3.7.2). Just `nix-build -A python372` to build it.
let
overlay = self: super: {
python372 = let
py = super.python37.override {
self = py;
sourceVersion = {
major = "3";
minor = "7";
patch = "2";
suffix = "";
@FRidh
FRidh / default.nix
Last active January 17, 2022 15:42
# # Python package set in Nixpkgs over time
#
# This gist is a Nix expression and generates a figure showing the size
# of the Python package set from September 2015 until now.
#
# To build the figure:
#
# nix-build
let
import os
import subprocess
os.environ["FOO"] = "BAR"
subprocess.run("python3 -c 'import os; print(os.environ.get(\"FOO\", \"\"))'", shell=True)
del os.environ["FOO"]
subprocess.run("python3 -c 'import os; print(os.environ.get(\"FOO\", \"\"))'", shell=True)
let
pkgs = import (fetchTarball channel:nixos-18.03) {};
custom-store = "/home/freddy/nix_custom_store";
# Run nix in a mount namespace
nix-wrapped = pkgs.writeShellScriptBin "nix" ''
${pkgs.bubblewrap}/bin/bwrap \
--unshare-all \
--proc /proc \
--dev /dev \
--tmpfs /run \
# Get nix 2.0 image from https://hub.docker.com/r/nixos/nix/
FROM nixos/nix:2.0
# Include the Nix expression we want to build
ADD default.nix default.nix
# We want the possibility for a custom store location
# Note that by using "/" there is effectively no mount namespace
# opening the doors for impurities.
ARG MOUNT_NIX_STORE
{pkgs ? (import <nixpkgs> {})}:
pkgs.stdenv.mkDerivation {
name = "fetchtarballtest";
src = pkgs.fetchurl {
url = https://github.com/NixOS/nixpkgs/archive/9c90ff7e7df9ceadc7335bb43cc67ba92e171d53.tar.gz;
sha256 = "0f8ynrrj24i4g8flp978ccsb2hlwk1n321z8xwj0wakj0ak4c8i9";
};
#! /usr/bin/env python
"""
Filter a .bib file with keys referred to in an .aux file. Print result to STDOUT.
"""
import argparse
import bibtexparser
import re
import itertools
@FRidh
FRidh / default.nix
Last active September 3, 2016 11:58 — forked from olejorgenb/propagatedPython.nix
Find python packages that are likely to fail when used through "nix-shell -p"
# Produce a list of derivations that should likely have pythonPath set
with import <nixpkgs> {};
with builtins;
let
# Package set to check
pythonPackages = pkgs.python2Packages;
# evaluate expr, returning default on error
@FRidh
FRidh / overview.md
Last active February 12, 2023 18:00

Python on Nix infrastructure

Introduction

Python is used throughout Nixpkgs. We use it for certain scripts, we provide Python libraries, and we provide applications. There are several methods on how to use Python on Nix, each with their pros and cons. An overview of all issues with the current Python infrastructure on Nix is available in the placeholder issue 1819.

Goal