Skip to content

Instantly share code, notes, and snippets.

@dwt
Created November 21, 2024 23:58
Show Gist options
  • Save dwt/f8e1de5e9be77ce2d7f3219741beaf43 to your computer and use it in GitHub Desktop.
Save dwt/f8e1de5e9be77ce2d7f3219741beaf43 to your computer and use it in GitHub Desktop.
{
"nodes": {
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1732179756,
"owner": "cachix",
"repo": "devenv",
"rev": "24f0aac5d4798899a0a739ea2c13396850fad2a8",
"type": "github"
},
"original": {
"dir": "src/modules",
"owner": "cachix",
"repo": "devenv",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1716977621,
"owner": "cachix",
"repo": "devenv-nixpkgs",
"rev": "4267e705586473d3e5c8d50299e71503f16a6fb6",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "rolling",
"repo": "devenv-nixpkgs",
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1731797254,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e8c38b73aeb218e27163376a2d617e61a2ad9b59",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-unstable": {
"locked": {
"lastModified": 1732014248,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "23e89b7da85c3640bbc2173fe04f4bd114342367",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1732021966,
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "3308484d1a443fc5bc92012435d79e80458fe43c",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"devenv": "devenv",
"nixpkgs": "nixpkgs",
"nixpkgs-unstable": "nixpkgs-unstable",
"pre-commit-hooks": "pre-commit-hooks"
}
}
},
"root": "root",
"version": 7
}
{ pkgs, lib, config, inputs, ... }:
let
pkgs-unstable = import inputs.nixpkgs-unstable { system = pkgs.stdenv.system; };
rosettaPkgs =
if pkgs-unstable.stdenv.isDarwin && pkgs-unstable.stdenv.isAarch64
then pkgs-unstable.pkgsx86_64Darwin
else pkgs-unstable;
# these are required so uv pip install works
# however it builds the arm version instead of the x86 version
# why?
in
{
name = "x86 python that compiles dependencies";
starship.enable = true;
packages = with rosettaPkgs; [
# if I want to configure git for difftastic or delta, enable here
pkgs.git
# these are the packages required for pymssql
# cannot be part of languages.python.libraries for some reason
freetds
krb5
openssl
];
# required so x86 compilation works
# this contains the compiler and it's toolchain
stdenv = rosettaPkgs.stdenv;
# https://devenv.sh/languages/
languages.python = {
enable = true;
package = rosettaPkgs.python312Full;
# dependencies for pymssql
libraries = with rosettaPkgs; [
# required so ibm_db finds symbols like __ZNKSt8__detail20_Prime_rehash_policy14_M_need_rehashEmmm
# maybe this could also be provided by the libcxx package, which contains the libc++.1.0.dylib
# which supposedly is the llvm implementation of that package
gcc14.cc
];
venv.enable = true;
venv.requirements = ./requirements.txt;
# much faster, but can't compile yet.
# @see https://github.com/astral-sh/uv/issues/8588
# actually compilation is broken for pip too still because
# devenv can't get the x86 stdenv right because I cannot
# switch the mkShell implementation to rosetta
uv.enable = true;
uv.package = rosettaPkgs.uv;
# uv.sync.enable = true;
# uv.sync.allExtras = true;
};
enterShell = ''
# This should be covevered by 'languages.python.libraries', but that does not work for me
export DYLD_FALLBACK_LIBRARY_PATH="${rosettaPkgs.lib.makeLibraryPath [ rosettaPkgs.gcc14.cc] }:$DYLD_FALLBACK_LIBRARY_PATH"
if test ! -d pymssql; then
git clone [email protected]:pymssql/pymssql.git
fi
function test() {
(
set -x
type python
python --version
python -c "import ibm_db" || echo "ibm_db failed"
python -c "import pymssql" || echo "pymssql failed"
)
}
rm -rf venv
${rosettaPkgs.python312Full}/bin/python3 -m venv venv
source venv/bin/activate
pip install --requirement requirements.txt
test
echo testing x86 compile
(
cd pymssql
pip install -e .
)
test
rm -rf venv
'';
}
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
inputs:
nixpkgs:
url: github:cachix/devenv-nixpkgs/rolling
nixpkgs-unstable:
url: github:NixOS/nixpkgs/nixos-unstable
# If you're using non-OSS software, you can set allowUnfree to true.
# allowUnfree: true
# If you're willing to use a package that's vulnerable
# permittedInsecurePackages:
# - "openssl-1.1.1w"
# If you have more than one devenv you can merge them
#imports:
# - ./backend
ibm_db_sa
pymssql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment