├── docs ├── src │ ├── docs.md │ ├── index.md │ ├── v1-api │ │ ├── .nav.yml │ │ ├── users.md │ │ ├── consuming │ │ │ └── inspect-options.md │ │ ├── summary.md │ │ └── problems.md │ ├── guides │ │ └── .nav.yml │ ├── favicon.png │ ├── style.css │ └── .nav.yml └── theme │ ├── partials │ └── toc-item.html │ ├── reference_header.html │ └── reference_options.html ├── .envrc ├── examples ├── repo-with-packages │ ├── .project-root │ ├── default.nix │ └── packages │ │ └── hello │ │ └── default.nix ├── packages │ ├── languages │ │ ├── haskell-local-development-cabal │ │ │ ├── .gitignore │ │ │ ├── app │ │ │ │ └── Main.hs │ │ │ ├── my-test-project.cabal │ │ │ └── default.nix │ │ ├── python-local-development-pdm-pytorch-from-nixpkgs │ │ │ ├── .gitignore │ │ │ ├── my_tool │ │ │ │ └── __init__.py │ │ │ └── pyproject.toml │ │ ├── python-local-development-multiple-packages │ │ │ ├── subpkg1 │ │ │ │ ├── subpkg1.py │ │ │ │ └── pyproject.toml │ │ │ ├── subpkg2 │ │ │ │ ├── subpkg2.py │ │ │ │ └── pyproject.toml │ │ │ ├── lock.aarch64-darwin.json │ │ │ ├── lock.x86_64-linux.json │ │ │ └── default.nix │ │ ├── nodejs-local-development-nextjs │ │ │ ├── nextjs-app │ │ │ │ ├── .eslintrc.json │ │ │ │ ├── postcss.config.js │ │ │ │ ├── next.config.mjs │ │ │ │ ├── src │ │ │ │ │ └── app │ │ │ │ │ │ ├── favicon.ico │ │ │ │ │ │ ├── layout.tsx │ │ │ │ │ │ └── globals.css │ │ │ │ ├── .gitignore │ │ │ │ ├── tailwind.config.ts │ │ │ │ ├── public │ │ │ │ │ ├── vercel.svg │ │ │ │ │ └── next.svg │ │ │ │ ├── package.json │ │ │ │ └── tsconfig.json │ │ │ ├── README.md │ │ │ └── default.nix │ │ ├── rust-local-development-workspace │ │ │ ├── app │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ └── main.rs │ │ │ ├── Cargo.toml │ │ │ ├── Cargo.lock │ │ │ └── default.nix │ │ ├── nodejs-local-development-no-lock-file │ │ │ ├── app.ts │ │ │ ├── package.json │ │ │ ├── default.nix │ │ │ └── lock.json │ │ ├── python-local-development-pdm │ │ │ ├── my_tool │ │ │ │ └── __init__.py │ │ │ ├── pyproject.toml │ │ │ └── default.nix │ │ ├── python-local-development │ │ │ ├── src │ │ │ │ └── my_tool │ │ │ │ │ └── __init__.py │ │ │ └── pyproject.toml │ │ ├── python-local-development-machine-learning │ │ │ ├── someproject │ │ │ │ └── __index__.py │ │ │ ├── pyproject.toml │ │ │ └── default.nix │ │ ├── spago-local-development │ │ │ ├── .gitignore │ │ │ ├── src │ │ │ │ └── Main.purs │ │ │ ├── default.nix │ │ │ ├── test │ │ │ │ └── Test │ │ │ │ │ └── Main.purs │ │ │ └── spago.yaml │ │ ├── python-packaging-ansible │ │ │ └── default.nix │ │ ├── python-packaging-pillow │ │ │ ├── lock.x86_64-linux.json │ │ │ ├── lock.aarch64-darwin.json │ │ │ └── default.nix │ │ ├── php-packaging │ │ │ └── default.nix │ │ ├── nodejs-packaging-devshell-only │ │ │ └── default.nix │ │ ├── nodejs-packaging │ │ │ └── default.nix │ │ ├── rust-packaging-buildRustPackage │ │ │ └── default.nix │ │ └── rust-packaging │ │ │ └── default.nix │ ├── basics │ │ ├── derivation │ │ │ └── default.nix │ │ └── mkDerivation │ │ │ └── default.nix │ └── README.md └── repo-with-packages-flake │ ├── packages │ └── hello │ │ └── default.nix │ └── flake.nix ├── modules ├── dream2nix │ ├── python-pdm │ │ ├── tests │ │ │ └── packages │ │ │ │ ├── jupyter-lab │ │ │ │ ├── flake.lock │ │ │ │ ├── .gitignore │ │ │ │ ├── pyproject.toml │ │ │ │ ├── default.nix │ │ │ │ └── flake.nix │ │ │ │ └── python-local-development │ │ │ │ ├── README.md │ │ │ │ ├── .gitignore │ │ │ │ ├── my_project │ │ │ │ └── __init__.py │ │ │ │ ├── pyproject.toml │ │ │ │ ├── default.nix │ │ │ │ └── flake.nix │ │ ├── README.md │ │ ├── interface-dependency.nix │ │ ├── sourceSelectorOption.nix │ │ └── interface.nix │ ├── core │ │ ├── docs │ │ │ ├── src │ │ │ │ └── SUMMARY.md │ │ │ ├── theme │ │ │ │ └── favicon.png │ │ │ └── book.toml │ │ ├── flags │ │ │ └── default.nix │ │ ├── README.md │ │ ├── default.nix │ │ ├── public │ │ │ ├── default.nix │ │ │ ├── optsPackageCompat.nix │ │ │ ├── optsPackage.nix │ │ │ ├── optsPackageDrvParts.nix │ │ │ └── interface.nix │ │ ├── ui │ │ │ └── default.nix │ │ ├── env │ │ │ └── default.nix │ │ ├── tests │ │ │ └── packages │ │ │ │ └── nixpkgs │ │ │ │ └── default.nix │ │ ├── paths │ │ │ ├── find-root.py │ │ │ └── default.nix │ │ └── assertions.nix │ ├── overrides │ │ ├── default.nix │ │ └── README.md │ ├── WIP-spago │ │ ├── README.md │ │ ├── interface.nix │ │ └── lock.py │ ├── nodejs-package-json │ │ ├── tests │ │ │ └── packages │ │ │ │ └── basic │ │ │ │ ├── app.ts │ │ │ │ ├── package.json │ │ │ │ ├── default.nix │ │ │ │ └── lock.json │ │ ├── README.md │ │ └── interface.nix │ ├── php-granular │ │ ├── README.md │ │ ├── devShell.nix │ │ └── interface.nix │ ├── rust-crane │ │ └── README.md │ ├── nodejs-devshell │ │ ├── README.md │ │ ├── tests │ │ │ └── packages │ │ │ │ └── basic │ │ │ │ ├── package.json │ │ │ │ ├── default.nix │ │ │ │ └── package-lock.json │ │ └── interface.nix │ ├── nodejs-granular │ │ ├── README.md │ │ ├── installPhase.nix │ │ ├── buildPhase.nix │ │ ├── configurePhase.nix │ │ └── unpackPhase.nix │ ├── WIP-haskell-cabal │ │ ├── README.md │ │ └── interface.nix │ ├── WIP-nodejs-builder-v3 │ │ ├── tests │ │ │ └── packages │ │ │ │ ├── nodejs-nextjs │ │ │ │ ├── nextjs-app │ │ │ │ │ ├── .eslintrc.json │ │ │ │ │ ├── postcss.config.js │ │ │ │ │ ├── next.config.mjs │ │ │ │ │ ├── src │ │ │ │ │ │ └── app │ │ │ │ │ │ │ ├── favicon.ico │ │ │ │ │ │ │ ├── layout.tsx │ │ │ │ │ │ │ └── globals.css │ │ │ │ │ ├── .gitignore │ │ │ │ │ ├── tailwind.config.ts │ │ │ │ │ ├── public │ │ │ │ │ │ ├── vercel.svg │ │ │ │ │ │ └── next.svg │ │ │ │ │ ├── package.json │ │ │ │ │ └── tsconfig.json │ │ │ │ ├── README.md │ │ │ │ ├── default.nix │ │ │ │ └── flake.nix │ │ │ │ ├── nodejs-packaging-package-lock │ │ │ │ ├── default.nix │ │ │ │ └── flake.nix │ │ │ │ └── nodejs-packaging-package-lock-v1 │ │ │ │ ├── default.nix │ │ │ │ └── flake.nix │ │ ├── README.md │ │ └── modules │ │ │ ├── prepared-prod.nix │ │ │ ├── prepared-dev.nix │ │ │ ├── installed.nix │ │ │ └── dist.nix │ ├── buildPythonPackage │ │ ├── README.md │ │ ├── tests │ │ │ └── packages │ │ │ │ └── basic │ │ │ │ └── default.nix │ │ ├── default.nix │ │ └── interface.nix │ ├── buildRustPackage │ │ ├── README.md │ │ └── interface.nix │ ├── nixpkgs-overrides │ │ ├── README.md │ │ └── interface.nix │ ├── nodejs-devshell-v3 │ │ ├── README.md │ │ └── interface.nix │ ├── nodejs-granular-v3 │ │ ├── README.md │ │ ├── installPhase.nix │ │ ├── buildPhase.nix │ │ ├── configurePhase.nix │ │ └── unpackPhase.nix │ ├── php-composer-lock │ │ └── README.md │ ├── rust-cargo-lock │ │ ├── README.md │ │ ├── interface.nix │ │ └── findAllCrates.nix │ ├── WIP-python-pyproject │ │ ├── README.md │ │ └── default.nix │ ├── builtins-derivation │ │ ├── README.md │ │ ├── interface.nix │ │ ├── default.nix │ │ └── derivation-common │ │ │ └── options.nix │ ├── nodejs-node-modules │ │ ├── README.md │ │ └── tests │ │ │ └── packages │ │ │ ├── basic │ │ │ ├── package.json │ │ │ ├── default.nix │ │ │ └── package-lock.json │ │ │ └── nodejs-packaging-node-modules-only │ │ │ ├── default.nix │ │ │ └── flake.nix │ ├── nodejs-package-lock │ │ └── README.md │ ├── rust-cargo-vendor │ │ ├── README.md │ │ └── interface.nix │ ├── buildPythonPackage-mixin │ │ ├── README.md │ │ ├── tests │ │ │ └── packages │ │ │ │ └── basic │ │ │ │ └── default.nix │ │ ├── interface.nix │ │ └── default.nix │ ├── nodejs-node-modules-v3 │ │ └── README.md │ ├── nodejs-package-json-v3 │ │ ├── README.md │ │ └── interface.nix │ ├── nodejs-package-lock-v3 │ │ └── README.md │ ├── multi-derivation-package │ │ ├── README.md │ │ ├── interface.nix │ │ └── default.nix │ ├── WIP-groups │ │ ├── default.nix │ │ ├── interface.nix │ │ └── groups-option.nix │ ├── _template │ │ ├── default.nix │ │ └── interface.nix │ ├── mkDerivation │ │ ├── README.md │ │ ├── tests │ │ │ └── packages │ │ │ │ └── basic │ │ │ │ └── default.nix │ │ └── interface.nix │ ├── pip │ │ ├── tests │ │ │ └── packages │ │ │ │ ├── can-build-setuptools │ │ │ │ ├── my_tool │ │ │ │ │ └── __init__.py │ │ │ │ ├── pyproject.toml │ │ │ │ ├── lock.x86_64-linux.json │ │ │ │ ├── default.nix │ │ │ │ └── flake.nix │ │ │ │ ├── can-handle-setuptools-runtime-dep │ │ │ │ ├── my_tool │ │ │ │ │ └── __init__.py │ │ │ │ ├── pyproject.toml │ │ │ │ ├── default.nix │ │ │ │ └── flake.nix │ │ │ │ ├── lock-script-works │ │ │ │ ├── my_tool │ │ │ │ │ └── __init__.py │ │ │ │ └── pyproject.toml │ │ │ │ └── python-nodejs │ │ │ │ └── flake.nix │ │ ├── pip-hotfixes │ │ │ ├── interface.nix │ │ │ └── default.nix │ │ └── README.md │ ├── mkDerivation-mixin │ │ ├── tests │ │ │ └── packages │ │ │ │ └── basic │ │ │ │ └── default.nix │ │ ├── README.md │ │ └── interface.nix │ └── python-editables │ │ ├── editable.nix │ │ └── default.nix └── flake-parts │ ├── drv-parts-deprecated.nix │ ├── _template.nix │ ├── overrides.nix │ ├── formatter.nix │ ├── pre-commit-check.nix │ ├── apps.update-caches.nix │ ├── core-modules.nix │ ├── website-options.nix │ ├── checks.nix-unit.nix │ └── reference-website │ └── frontmatter.nix ├── pkgs └── fetchPipMetadata │ ├── src │ ├── .envrc │ ├── tests │ │ ├── conftest.py │ │ ├── test_path_from_file_url.py │ │ ├── test_evaluate_extras.py │ │ ├── test_lock_info_from_fod.py │ │ └── test_lock_info_from_path.py │ └── pyproject.toml │ ├── package.nix │ └── flake-module.nix ├── overrides ├── python │ ├── _template │ │ └── default.nix │ ├── nvidia-cublas-cu12 │ │ ├── default.nix │ │ └── remove-nvidia-init.nix │ ├── nvidia-cudnn-cu12 │ │ └── default.nix │ ├── nvidia-cufft-cu12 │ │ └── default.nix │ ├── nvidia-nccl-cu12 │ │ └── default.nix │ ├── nvidia-cuda-cupti-cu12 │ │ └── default.nix │ ├── nvidia-cuda-nvrtc-cu12 │ │ └── default.nix │ ├── nvidia-curand-cu12 │ │ └── default.nix │ ├── nvidia-cusolver-cu12 │ │ └── default.nix │ ├── nvidia-cusparse-cu12 │ │ └── default.nix │ ├── nvidia-nvjitlink-cu12 │ │ └── default.nix │ ├── nvidia-cuda-runtime-cu12 │ │ └── default.nix │ ├── triton │ │ └── default.nix │ ├── reuse │ │ └── default.nix │ ├── certifi │ │ └── default.nix │ ├── pillow │ │ └── default.nix │ ├── psycopg2 │ │ └── default.nix │ ├── torch │ │ └── default.nix │ └── opencv-python │ │ └── default.nix └── rust │ └── jack-sys │ └── default.nix ├── .github ├── dependabot.yml └── workflows │ ├── flake-update.yml │ └── pages.yml ├── .gitignore ├── shell.nix ├── dev-flake ├── default.nix └── flake.nix ├── tests └── nix-unit │ ├── test_graph_utils │ └── default.nix │ ├── test_nodejs_node_builder_v3 │ ├── package.json │ └── lib │ │ └── package.json │ ├── test_nodejs_lock_v3 │ └── lib │ │ └── package.json │ ├── test_python-pdm-lib │ └── fixtures │ │ ├── pyproject.toml │ │ └── pdm-extras.lock │ ├── fixtures.nix │ └── test_python-pdm │ └── default.nix ├── lib ├── internal │ ├── sanitizeRelativePath.nix │ ├── fetchers │ │ ├── path │ │ │ └── default.nix │ │ ├── gitlab │ │ │ └── default.nix │ │ ├── github │ │ │ └── default.nix │ │ ├── archive │ │ │ └── default.nix │ │ ├── pypi-wheel │ │ │ └── default.nix │ │ ├── pypi-sdist │ │ │ └── default.nix │ │ ├── crates-io │ │ │ └── default.nix │ │ ├── http │ │ │ └── default.nix │ │ └── extractSource.nix │ ├── mkSubmodule.nix │ ├── sanitizePath.nix │ ├── hashFile.nix │ ├── hashPath.nix │ ├── dreamLockUtils.nix │ ├── parseSpdxId.nix │ ├── getDreamLockSource.nix │ └── nodejsLockUtils.nix └── types │ └── default.nix ├── aliases └── WIP-python-pdm.nix ├── default.nix ├── treefmt.toml ├── scripts ├── update-examples.sh ├── update-aarch64-locks.sh └── flake.nix ├── .mergify.yml ├── CHANGELOG.md ├── misc └── benchmarks │ └── benchmark.sh └── LICENSE /docs/src/docs.md: -------------------------------------------------------------------------------- 1 | ../README.md -------------------------------------------------------------------------------- /.envrc: -------------------------------------------------------------------------------- 1 | use flake ./dev-flake 2 | -------------------------------------------------------------------------------- /docs/src/index.md: -------------------------------------------------------------------------------- 1 | ../../README.md -------------------------------------------------------------------------------- /examples/repo-with-packages/.project-root: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/src/v1-api/.nav.yml: -------------------------------------------------------------------------------- 1 | nav: 2 | - summary.md 3 | - ... 4 | -------------------------------------------------------------------------------- /modules/dream2nix/python-pdm/tests/packages/jupyter-lab/flake.lock: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pkgs/fetchPipMetadata/src/.envrc: -------------------------------------------------------------------------------- 1 | use flake .#fetch-pip-metadata 2 | -------------------------------------------------------------------------------- /examples/packages/languages/haskell-local-development-cabal/.gitignore: -------------------------------------------------------------------------------- 1 | dist-newstyle 2 | -------------------------------------------------------------------------------- /docs/src/guides/.nav.yml: -------------------------------------------------------------------------------- 1 | nav: 2 | - getting-started.md 3 | - "Python & pip": pip.md 4 | -------------------------------------------------------------------------------- /overrides/python/_template/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: { 6 | } 7 | -------------------------------------------------------------------------------- /docs/src/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nix-community/dream2nix/HEAD/docs/src/favicon.png -------------------------------------------------------------------------------- /modules/dream2nix/core/docs/src/SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | - [Options](./options/options.md) 4 | -------------------------------------------------------------------------------- /modules/dream2nix/core/flags/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [ 3 | ./interface.nix 4 | ]; 5 | } 6 | -------------------------------------------------------------------------------- /modules/dream2nix/overrides/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [ 3 | ./interface.nix 4 | ]; 5 | } 6 | -------------------------------------------------------------------------------- /modules/dream2nix/python-pdm/tests/packages/python-local-development/README.md: -------------------------------------------------------------------------------- 1 | # example-package 2 | -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development-pdm-pytorch-from-nixpkgs/.gitignore: -------------------------------------------------------------------------------- 1 | .pdm-python 2 | -------------------------------------------------------------------------------- /modules/dream2nix/python-pdm/tests/packages/jupyter-lab/.gitignore: -------------------------------------------------------------------------------- 1 | __pypackages__ 2 | .pdm-build 3 | .pdm-python 4 | -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development-multiple-packages/subpkg1/subpkg1.py: -------------------------------------------------------------------------------- 1 | from subpkg2 import where 2 | -------------------------------------------------------------------------------- /modules/dream2nix/core/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "core" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /overrides/python/nvidia-cublas-cu12/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [ 3 | ./remove-nvidia-init.nix 4 | ]; 5 | } 6 | -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development-multiple-packages/subpkg2/subpkg2.py: -------------------------------------------------------------------------------- 1 | def where(): 2 | print(__name__) 3 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-spago/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "spago" 3 | state: "experimental" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/overrides/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "overrides" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/python-pdm/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "python-pdm" 3 | state: "released" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/python-pdm/tests/packages/python-local-development/.gitignore: -------------------------------------------------------------------------------- 1 | __pypackages__ 2 | .pdm-build 3 | .pdm-python 4 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-nextjs/nextjs-app/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /examples/packages/languages/rust-local-development-workspace/app/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "app" 3 | version.workspace = true 4 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-package-json/tests/packages/basic/app.ts: -------------------------------------------------------------------------------- 1 | let message: string = 'Hello, World!'; 2 | console.log(message); 3 | -------------------------------------------------------------------------------- /modules/dream2nix/php-granular/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "php-granular" 3 | state: "released" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/rust-crane/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "rust-crane" 3 | state: "experimental" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /overrides/python/nvidia-cudnn-cu12/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [ 3 | ../nvidia-cublas-cu12/remove-nvidia-init.nix 4 | ]; 5 | } 6 | -------------------------------------------------------------------------------- /overrides/python/nvidia-cufft-cu12/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [ 3 | ../nvidia-cublas-cu12/remove-nvidia-init.nix 4 | ]; 5 | } 6 | -------------------------------------------------------------------------------- /overrides/python/nvidia-nccl-cu12/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [ 3 | ../nvidia-cublas-cu12/remove-nvidia-init.nix 4 | ]; 5 | } 6 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-no-lock-file/app.ts: -------------------------------------------------------------------------------- 1 | let message: string = 'Hello, World!'; 2 | console.log(message); 3 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-devshell/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "nodejs-devshell" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-granular/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "nodejs-granular" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /overrides/python/nvidia-cuda-cupti-cu12/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [ 3 | ../nvidia-cublas-cu12/remove-nvidia-init.nix 4 | ]; 5 | } 6 | -------------------------------------------------------------------------------- /overrides/python/nvidia-cuda-nvrtc-cu12/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [ 3 | ../nvidia-cublas-cu12/remove-nvidia-init.nix 4 | ]; 5 | } 6 | -------------------------------------------------------------------------------- /overrides/python/nvidia-curand-cu12/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [ 3 | ../nvidia-cublas-cu12/remove-nvidia-init.nix 4 | ]; 5 | } 6 | -------------------------------------------------------------------------------- /overrides/python/nvidia-cusolver-cu12/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [ 3 | ../nvidia-cublas-cu12/remove-nvidia-init.nix 4 | ]; 5 | } 6 | -------------------------------------------------------------------------------- /overrides/python/nvidia-cusparse-cu12/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [ 3 | ../nvidia-cublas-cu12/remove-nvidia-init.nix 4 | ]; 5 | } 6 | -------------------------------------------------------------------------------- /overrides/python/nvidia-nvjitlink-cu12/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [ 3 | ../nvidia-cublas-cu12/remove-nvidia-init.nix 4 | ]; 5 | } 6 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-haskell-cabal/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "haskell-cabal" 3 | state: "experimental" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-nextjs/nextjs-app/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /modules/dream2nix/buildPythonPackage/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "buildPythonPackage" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/buildRustPackage/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "buildRustPackage" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/nixpkgs-overrides/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "nixpkgs-overrides" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-devshell-v3/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "nodejs-devshell-v3" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-granular-v3/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "nodejs-granular-v3" 3 | state: "released" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/php-composer-lock/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "php-composer-lock" 3 | state: "released" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/rust-cargo-lock/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "rust-cargo-lock" 3 | state: "experimental" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /overrides/python/nvidia-cuda-runtime-cu12/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [ 3 | ../nvidia-cublas-cu12/remove-nvidia-init.nix 4 | ]; 5 | } 6 | -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development-pdm/my_tool/__init__.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | 4 | def main(): 5 | print("Hello World!") 6 | -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development/src/my_tool/__init__.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | 4 | def main(): 5 | print("Hello World!") 6 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-python-pyproject/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "python-pyproject" 3 | state: "experimental" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/builtins-derivation/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "builtins-derivation" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/core/docs/theme/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nix-community/dream2nix/HEAD/modules/dream2nix/core/docs/theme/favicon.png -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-node-modules/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "nodejs-node-modules" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-package-json/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "nodejs-package-json" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-package-lock/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "nodejs-package-lock" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/rust-cargo-vendor/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "rust-cargo-vendor" 3 | state: "experimental" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "nodejs-builder-v3" 3 | state: "experimental" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/buildPythonPackage-mixin/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "buildPythonPackage" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-node-modules-v3/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "nodejs-node-modules-v3" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-package-json-v3/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "nodejs-package-json-v3" 3 | state: "released" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-package-lock-v3/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "nodejs-package-lock-v3" 3 | state: "released" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /examples/packages/languages/haskell-local-development-cabal/app/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | main :: IO () 4 | main = putStrLn "Hello from dream2nix!" 5 | -------------------------------------------------------------------------------- /examples/packages/languages/rust-local-development-workspace/Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["app"] 3 | 4 | [workspace.package] 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /examples/packages/languages/rust-local-development-workspace/app/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("hello from v{}", env!("CARGO_PKG_VERSION")); 3 | } 4 | -------------------------------------------------------------------------------- /modules/dream2nix/multi-derivation-package/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "multi-derivation-package" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | -------------------------------------------------------------------------------- /modules/dream2nix/python-pdm/tests/packages/python-local-development/my_project/__init__.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | 4 | def main(): 5 | print("Hello, world!") 6 | -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development-machine-learning/someproject/__index__.py: -------------------------------------------------------------------------------- 1 | import PIL 2 | import sklearn 3 | import torch 4 | 5 | print("hello world") 6 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-groups/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: { 6 | imports = [ 7 | ./interface.nix 8 | ../overrides 9 | ]; 10 | } 11 | -------------------------------------------------------------------------------- /modules/dream2nix/python-pdm/interface-dependency.nix: -------------------------------------------------------------------------------- 1 | {lib, ...}: { 2 | options = { 3 | sourceSelector = import ./sourceSelectorOption.nix {inherit lib;}; 4 | }; 5 | } 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .*/ 2 | !.github/ 3 | 4 | /.pre-commit-config.yaml 5 | result 6 | interpreter 7 | __pycache__ 8 | *.egg-info 9 | # symlink for devshell 10 | docs/src/reference 11 | -------------------------------------------------------------------------------- /modules/dream2nix/_template/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: { 6 | imports = [ 7 | ./interface.nix 8 | ]; 9 | config = { 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development-pdm-pytorch-from-nixpkgs/my_tool/__init__.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import torch 3 | 4 | 5 | def main(): 6 | print("Hello World!") 7 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | (import ./default.nix).devShells.${builtins.currentSystem}.default 2 | or (throw "dev-shell not defined. Cannot find flake attribute devShell.${builtins.currentSystem}.default") 3 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-nextjs/nextjs-app/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /dev-flake/default.nix: -------------------------------------------------------------------------------- 1 | # This file provides backward compatibility to nix < 2.4 clients 2 | let 3 | flake = 4 | import 5 | ./flake-compat.nix 6 | {src = ./.;}; 7 | in 8 | flake.defaultNix 9 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-haskell-cabal/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | ... 5 | }: let 6 | l = lib // builtins; 7 | t = l.types; 8 | in { 9 | options.haskell-cabal = {}; 10 | } 11 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-nextjs/nextjs-app/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /modules/flake-parts/drv-parts-deprecated.nix: -------------------------------------------------------------------------------- 1 | { 2 | flake.modules.drv-parts = throw '' 3 | dream2nix.modules.drv-parts is deprecated. 4 | Use dream2nix.modules.dream2nix instead. 5 | ''; 6 | } 7 | -------------------------------------------------------------------------------- /tests/nix-unit/test_graph_utils/default.nix: -------------------------------------------------------------------------------- 1 | {lib ? import , ...}: let 2 | sanitizeGraphTests = import ./sanitizeGraph.nix {inherit lib;}; 3 | in { 4 | inherit sanitizeGraphTests; 5 | } 6 | -------------------------------------------------------------------------------- /modules/dream2nix/mkDerivation/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "mkDerivation" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | 8 | A package module based on the mkDerivation builder from nixpkgs 9 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-devshell/tests/packages/basic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 3 | "version": "1.0.0", 4 | "dependencies": { 5 | "typescript": "^5.1.6" 6 | }, 7 | "bin": "app.js" 8 | } 9 | -------------------------------------------------------------------------------- /modules/dream2nix/core/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [ 3 | ./assertions.nix 4 | ./docs 5 | ./deps 6 | ./env 7 | ./lock 8 | ./paths 9 | ./public 10 | ./ui 11 | ]; 12 | } 13 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-node-modules/tests/packages/basic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 3 | "version": "1.0.0", 4 | "dependencies": { 5 | "typescript": "^5.1.6" 6 | }, 7 | "bin": "app.js" 8 | } 9 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-package-json/tests/packages/basic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 3 | "version": "1.0.0", 4 | "dependencies": { 5 | "typescript": "^5.1.6" 6 | }, 7 | "bin": "app.js" 8 | } 9 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-nextjs/nextjs-app/next.config.mjs: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = { 3 | output: "export", 4 | }; 5 | 6 | export default nextConfig; 7 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-no-lock-file/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 3 | "version": "1.0.0", 4 | "dependencies": { 5 | "typescript": "^5.1.6" 6 | }, 7 | "bin": "app.js" 8 | } 9 | -------------------------------------------------------------------------------- /lib/internal/sanitizeRelativePath.nix: -------------------------------------------------------------------------------- 1 | {lib, ...}: let 2 | l = builtins // lib; 3 | 4 | sanitizeRelativePath = path: 5 | l.removePrefix "/" (l.toString (l.toPath "/${path}")); 6 | in 7 | sanitizeRelativePath 8 | -------------------------------------------------------------------------------- /modules/dream2nix/core/public/default.nix: -------------------------------------------------------------------------------- 1 | # Defining the core of what drv-parts is about. 2 | # This does nothing except defining the structure of public. 3 | { 4 | imports = [ 5 | ./interface.nix 6 | ]; 7 | } 8 | -------------------------------------------------------------------------------- /aliases/WIP-python-pdm.nix: -------------------------------------------------------------------------------- 1 | {dream2nix, ...}: { 2 | imports = [dream2nix.modules.dream2nix.python-pdm]; 3 | warnings = [ 4 | "The dream2nix module `WIP-python-pdm` has been renamed to `python-pdm`." 5 | ]; 6 | } 7 | -------------------------------------------------------------------------------- /modules/dream2nix/_template/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: let 6 | t = lib.types; 7 | in { 8 | options = lib.mapAttrs (_: lib.mkOption) { 9 | # put options here 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-groups/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | specialArgs, 5 | ... 6 | }: { 7 | options.groups = import ./groups-option.nix { 8 | inherit config lib specialArgs; 9 | }; 10 | } 11 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-nextjs/nextjs-app/next.config.mjs: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = { 3 | output: "export", 4 | }; 5 | 6 | export default nextConfig; 7 | -------------------------------------------------------------------------------- /modules/dream2nix/pip/tests/packages/can-build-setuptools/my_tool/__init__.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | 4 | def main(): 5 | print("Hello World!") 6 | 7 | 8 | if __name__ == "__main__": 9 | main() 10 | -------------------------------------------------------------------------------- /modules/dream2nix/pip/tests/packages/can-handle-setuptools-runtime-dep/my_tool/__init__.py: -------------------------------------------------------------------------------- 1 | import websocket 2 | 3 | 4 | def main(): 5 | print("Hello World!") 6 | 7 | 8 | if __name__ == "__main__": 9 | main() 10 | -------------------------------------------------------------------------------- /modules/dream2nix/pip/tests/packages/lock-script-works/my_tool/__init__.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | 4 | def main(): 5 | print("Hello World!") 6 | 7 | 8 | if __name__ == "__main__": 9 | main() 10 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-nextjs/nextjs-app/src/app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nix-community/dream2nix/HEAD/examples/packages/languages/nodejs-local-development-nextjs/nextjs-app/src/app/favicon.ico -------------------------------------------------------------------------------- /modules/flake-parts/_template.nix: -------------------------------------------------------------------------------- 1 | { 2 | self, 3 | lib, 4 | ... 5 | }: { 6 | perSystem = { 7 | config, 8 | self', 9 | inputs', 10 | pkgs, 11 | ... 12 | }: { 13 | }; 14 | flake = { 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /examples/packages/languages/rust-local-development-workspace/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "app" 7 | version = "1.0.0" 8 | -------------------------------------------------------------------------------- /examples/packages/languages/spago-local-development/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | bower_components/ 3 | node_modules/ 4 | .pulp-cache/ 5 | output/ 6 | output-es/ 7 | generated-docs/ 8 | .psc-package/ 9 | .psc* 10 | .purs* 11 | .psa* 12 | .spago 13 | -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development-multiple-packages/subpkg2/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ "setuptools" ] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "subpkg2" 7 | version = "0.0.2" 8 | -------------------------------------------------------------------------------- /examples/packages/languages/spago-local-development/src/Main.purs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Prelude 4 | 5 | import Effect (Effect) 6 | import Effect.Console (log) 7 | 8 | main :: Effect Unit 9 | main = do 10 | log "🍝" 11 | 12 | -------------------------------------------------------------------------------- /lib/internal/fetchers/path/default.nix: -------------------------------------------------------------------------------- 1 | {utils, ...}: { 2 | inputs = [ 3 | "path" 4 | ]; 5 | 6 | outputs = {path, ...}: { 7 | calcHash = algo: utils.hashPath "${path}"; 8 | 9 | fetched = hash: "${path}"; 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /lib/internal/mkSubmodule.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | specialArgs, 4 | ... 5 | }: module: 6 | lib.mkOption { 7 | type = lib.types.submoduleWith { 8 | inherit specialArgs; 9 | modules = [ 10 | module 11 | ]; 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-nextjs/README.md: -------------------------------------------------------------------------------- 1 | # Nextjs Example 2 | 3 | Here we package nextjs statically with `output: "export"`. 4 | 5 | Which can be served statically with any web-server e.g. 6 | 7 | `npx http-server result/out/` -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-nextjs/nextjs-app/src/app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nix-community/dream2nix/HEAD/modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-nextjs/nextjs-app/src/app/favicon.ico -------------------------------------------------------------------------------- /overrides/python/triton/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: { 6 | env.pythonRemoveDeps = [ 7 | "torch" 8 | ]; 9 | mkDerivation.nativeBuildInputs = [ 10 | config.deps.python.pkgs.pythonRelaxDepsHook 11 | ]; 12 | } 13 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-nextjs/README.md: -------------------------------------------------------------------------------- 1 | # Nextjs Example 2 | 3 | Here we package nextjs statically with `output: "export"`. 4 | 5 | Which can be served statically with any web-server e.g. 6 | 7 | `npx http-server result/out/` -------------------------------------------------------------------------------- /tests/nix-unit/test_nodejs_node_builder_v3/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minimal", 3 | "version": "1.0.0", 4 | "dependencies": { 5 | "kitten": "^0.0.2" 6 | }, 7 | "scripts": { 8 | "build": "node ./node_modules/.bin/esparse --version" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/packages/languages/spago-local-development/default.nix: -------------------------------------------------------------------------------- 1 | {dream2nix, ...}: { 2 | imports = [ 3 | dream2nix.modules.dream2nix.WIP-spago 4 | ]; 5 | 6 | name = "test"; 7 | version = "1.0.0"; 8 | 9 | mkDerivation = { 10 | src = ./.; 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development-multiple-packages/subpkg1/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ "setuptools" ] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "subpkg1" 7 | version = "0.0.1" 8 | dependencies = [ 9 | "subpkg2" 10 | ] 11 | -------------------------------------------------------------------------------- /examples/packages/languages/spago-local-development/test/Test/Main.purs: -------------------------------------------------------------------------------- 1 | module Test.Main where 2 | 3 | import Prelude 4 | 5 | import Effect (Effect) 6 | import Effect.Class.Console (log) 7 | 8 | main :: Effect Unit 9 | main = do 10 | log "🍕" 11 | log "You should add some tests." 12 | 13 | -------------------------------------------------------------------------------- /overrides/rust/jack-sys/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: { 6 | deps = {nixpkgs, ...}: { 7 | inherit (nixpkgs) pkg-config libjack2; 8 | }; 9 | 10 | mkDerivation.buildInputs = [config.deps.libjack2]; 11 | mkDerivation.nativeBuildInputs = [config.deps.pkg-config]; 12 | } 13 | -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development-machine-learning/pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "someproject" 3 | version = "0.1.0" 4 | 5 | dependencies = [ 6 | "pillow", 7 | "scikit-learn", 8 | "torch", 9 | ] 10 | 11 | [tool.setuptools.packages.find] 12 | include = [ 13 | "someproject", 14 | ] 15 | -------------------------------------------------------------------------------- /tests/nix-unit/test_nodejs_lock_v3/lib/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lib", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC" 12 | } 13 | -------------------------------------------------------------------------------- /pkgs/fetchPipMetadata/src/tests/conftest.py: -------------------------------------------------------------------------------- 1 | from os import environ 2 | import pytest 3 | import subprocess 4 | from pathlib import Path 5 | from tempfile import TemporaryDirectory 6 | 7 | 8 | @pytest.fixture() 9 | def git_repo_path(tmp_path): 10 | subprocess.run(["git", "init"], cwd=tmp_path) 11 | return tmp_path 12 | -------------------------------------------------------------------------------- /tests/nix-unit/test_nodejs_node_builder_v3/lib/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lib", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC" 12 | } 13 | -------------------------------------------------------------------------------- /default.nix: -------------------------------------------------------------------------------- 1 | # This file provides backward compatibility to nix < 2.4 clients 2 | let 3 | flake = 4 | import 5 | ./dev-flake/flake-compat.nix 6 | {src = ./.;}; 7 | in 8 | flake.defaultNix 9 | # allow overriding inputs 10 | // { 11 | __functor = defaultNix: inputs: defaultNix.overrideInputs inputs; 12 | } 13 | -------------------------------------------------------------------------------- /treefmt.toml: -------------------------------------------------------------------------------- 1 | [formatter.nix] 2 | command = "alejandra" 3 | includes = ["*.nix"] 4 | excludes = [ 5 | "overrides/nodejs/electron/*", 6 | "src/templates/translators/*", 7 | "src/modules/_template/*", 8 | "src/modules/utils/poetry2nix/semver.nix", 9 | ] 10 | 11 | [formatter.py] 12 | command = "black" 13 | includes = ["*.py"] 14 | -------------------------------------------------------------------------------- /modules/dream2nix/mkDerivation-mixin/tests/packages/basic/default.nix: -------------------------------------------------------------------------------- 1 | {dream2nix, ...}: { 2 | imports = [ 3 | dream2nix.modules.dream2nix.mkDerivation-mixin 4 | dream2nix.modules.dream2nix.core 5 | ]; 6 | name = "test"; 7 | version = "1.0.0"; 8 | phases = ["buildPhase"]; 9 | buildPhase = "echo -n hello > $out"; 10 | } 11 | -------------------------------------------------------------------------------- /overrides/python/nvidia-cublas-cu12/remove-nvidia-init.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: { 6 | mkDerivation.postFixup = 7 | # prevents conflicts in nixpkgs buildEnv for python 8 | lib.mkIf (lib.hasSuffix ".whl" config.mkDerivation.src) 9 | "rm $out/lib/*/site-packages/nvidia/__pycache__/__init__.*"; 10 | } 11 | -------------------------------------------------------------------------------- /modules/dream2nix/mkDerivation/tests/packages/basic/default.nix: -------------------------------------------------------------------------------- 1 | {dream2nix, ...}: { 2 | imports = [ 3 | dream2nix.modules.dream2nix.mkDerivation 4 | dream2nix.modules.dream2nix.core 5 | ]; 6 | name = "test"; 7 | version = "1.0.0"; 8 | mkDerivation.phases = ["buildPhase"]; 9 | mkDerivation.buildPhase = "echo -n hello > $out"; 10 | } 11 | -------------------------------------------------------------------------------- /modules/dream2nix/pip/tests/packages/lock-script-works/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ "setuptools" ] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "my-tool" 7 | description = "my tool" 8 | version = "1.0.0" 9 | dependencies = [ 10 | "setuptools" 11 | ] 12 | 13 | [project.scripts] 14 | my-tool = "my_tool:main" 15 | -------------------------------------------------------------------------------- /modules/dream2nix/mkDerivation-mixin/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "mkDerivation-mixin" 3 | state: "internal" 4 | maintainers: 5 | - DavHau 6 | --- 7 | 8 | A package module based on the mkDerivation builder from nixpkgs 9 | 10 | Equivalent to the dream2nix module `mkDerivation`, but all options are declared at the toplevel instead of under `mkDerivation.[...]`. 11 | -------------------------------------------------------------------------------- /modules/dream2nix/pip/tests/packages/can-build-setuptools/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ "setuptools" ] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "my-tool" 7 | description = "my tool" 8 | version = "1.0.0" 9 | dependencies = [ 10 | "setuptools" 11 | ] 12 | 13 | [project.scripts] 14 | my-tool = "my_tool:main" 15 | -------------------------------------------------------------------------------- /overrides/python/reuse/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | dream2nix, 5 | ... 6 | }: let 7 | isSdist = lib.hasSuffix ".tar.gz" config.mkDerivation.src; 8 | python = config.deps.python; 9 | in { 10 | buildPythonPackage.pyproject = lib.mkIf isSdist true; 11 | mkDerivation.nativeBuildInputs = lib.mkIf isSdist [python.pkgs.poetry-core]; 12 | } 13 | -------------------------------------------------------------------------------- /lib/internal/sanitizePath.nix: -------------------------------------------------------------------------------- 1 | {lib, ...}: let 2 | l = builtins // lib; 3 | 4 | sanitizePath = path: let 5 | absolute = (l.substring 0 1 path) == "/"; 6 | sanitizedRelPath = l.removePrefix "/" (l.toString (l.toPath "/${path}")); 7 | in 8 | if absolute 9 | then "/${sanitizedRelPath}" 10 | else sanitizedRelPath; 11 | in 12 | sanitizePath 13 | -------------------------------------------------------------------------------- /scripts/update-examples.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # find script directory 4 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 5 | 6 | # find examples directory 7 | packagesDir="$DIR/../examples/packages" 8 | 9 | # iterate over all double nested package directories and copy the flake file there 10 | echo "$packagesDir"/*/*/ | xargs -n 1 cp "$DIR"/flake.nix 11 | -------------------------------------------------------------------------------- /.mergify.yml: -------------------------------------------------------------------------------- 1 | queue_rules: 2 | - name: default 3 | queue_conditions: 4 | - base=main 5 | - label~=merge-queue|auto-merge|dependencies 6 | merge_conditions: 7 | - check-success=buildbot/nix-build 8 | merge_method: rebase 9 | 10 | pull_request_rules: 11 | - name: merge using the merge queue 12 | conditions: [] 13 | actions: 14 | queue: 15 | -------------------------------------------------------------------------------- /modules/dream2nix/buildRustPackage/interface.nix: -------------------------------------------------------------------------------- 1 | {lib, ...}: { 2 | options.deps = { 3 | cargo = lib.mkOption { 4 | type = lib.types.package; 5 | description = "The cargo package to use"; 6 | }; 7 | writeText = lib.mkOption { 8 | type = lib.types.raw; 9 | description = "The function to use to write text to a file"; 10 | }; 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /modules/dream2nix/core/docs/book.toml: -------------------------------------------------------------------------------- 1 | [book] 2 | authors = ["dream2nix", "You"] 3 | language = "en" 4 | multilingual = false 5 | src = "src" 6 | title = "__TITLE__" 7 | 8 | [output.html] 9 | no-section-label = true 10 | 11 | [output.html.print] 12 | enable = false # big single page; don't need that 13 | 14 | [output.linkcheck] 15 | follow-web-links = false # no Internet during the build 16 | -------------------------------------------------------------------------------- /overrides/python/certifi/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | dream2nix, 5 | ... 6 | }: let 7 | isSdist = lib.hasSuffix ".tar.gz" config.mkDerivation.src; 8 | in { 9 | # enable overrides from nixpkgs 10 | imports = [dream2nix.modules.dream2nix.nixpkgs-overrides]; 11 | nixpkgs-overrides.enable = isSdist; 12 | nixpkgs-overrides.exclude = ["propagatedBuildInputs"]; 13 | } 14 | -------------------------------------------------------------------------------- /overrides/python/pillow/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | dream2nix, 5 | ... 6 | }: let 7 | isSdist = lib.hasSuffix ".tar.gz" config.mkDerivation.src; 8 | in { 9 | # enable overrides from nixpkgs 10 | imports = [dream2nix.modules.dream2nix.nixpkgs-overrides]; 11 | nixpkgs-overrides.enable = isSdist; 12 | nixpkgs-overrides.exclude = ["propagatedBuildInputs"]; 13 | } 14 | -------------------------------------------------------------------------------- /modules/flake-parts/overrides.nix: -------------------------------------------------------------------------------- 1 | {self, ...}: let 2 | overridesDir = ../../overrides; 3 | in { 4 | flake.overrides = 5 | builtins.mapAttrs 6 | ( 7 | category: _type: 8 | builtins.mapAttrs 9 | (name: _type: overridesDir + "/${category}/${name}") 10 | (builtins.readDir (overridesDir + "/${category}")) 11 | ) 12 | (builtins.readDir overridesDir); 13 | } 14 | -------------------------------------------------------------------------------- /modules/flake-parts/formatter.nix: -------------------------------------------------------------------------------- 1 | { 2 | perSystem = { 3 | lib, 4 | pkgs, 5 | ... 6 | }: { 7 | formatter = let 8 | path = lib.makeBinPath [ 9 | pkgs.alejandra 10 | pkgs.python3.pkgs.black 11 | ]; 12 | in (pkgs.writeScriptBin "format" '' 13 | export PATH="${path}" 14 | ${pkgs.treefmt}/bin/treefmt --clear-cache "$@" 15 | ''); 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ "setuptools" ] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "my-tool" 7 | description = "my tool" 8 | version = "1.0.0" 9 | dependencies = [ 10 | "requests", 11 | "click @ git+https://github.com/pallets/click.git@main" 12 | ] 13 | 14 | [project.scripts] 15 | my-tool = "my_tool:main" 16 | -------------------------------------------------------------------------------- /examples/packages/languages/spago-local-development/spago.yaml: -------------------------------------------------------------------------------- 1 | package: 2 | dependencies: 3 | - abc-parser # added just for having transitive dependencies 4 | - console 5 | - effect 6 | - prelude 7 | - psci-support # TODO hardcode 8 | name: spago-project 9 | test: 10 | dependencies: [] 11 | main: Test.Main 12 | workspace: 13 | extra_packages: {} 14 | package_set: 15 | registry: 42.1.0 16 | -------------------------------------------------------------------------------- /modules/dream2nix/python-pdm/tests/packages/jupyter-lab/pyproject.toml: -------------------------------------------------------------------------------- 1 | 2 | [project] 3 | name = "my-project" 4 | version = "0.1.0" 5 | description = "" 6 | requires-python = ">=3.10" 7 | license = {text = "MIT"} 8 | dependencies = [ 9 | "jupyterlab>=4.1.4", 10 | ] 11 | 12 | 13 | [tool.pdm.options] 14 | add = ["--no-sync", "--no-self"] 15 | update = ["--no-sync", "--no-self"] 16 | remove = ["--no-sync", "--no-self"] 17 | -------------------------------------------------------------------------------- /examples/packages/basics/derivation/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | dream2nix, 4 | lib, 5 | ... 6 | }: { 7 | # select builtins.derivation as a backend for this package 8 | imports = [ 9 | dream2nix.modules.dream2nix.builtins-derivation 10 | ]; 11 | 12 | name = "test"; 13 | 14 | # set options 15 | builtins-derivation = { 16 | builder = "/bin/sh"; 17 | args = ["-c" "echo $name > $out"]; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /modules/dream2nix/multi-derivation-package/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | dream2nix, 4 | lib, 5 | specialArgs, 6 | ... 7 | }: let 8 | t = lib.types; 9 | dreamTypes = import ../../../lib/types { 10 | inherit dream2nix lib specialArgs; 11 | }; 12 | in { 13 | options = { 14 | out = lib.mkOption { 15 | type = dreamTypes.drvPart; 16 | description = "default output 'out'"; 17 | }; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /modules/dream2nix/python-editables/editable.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | findRoot, 4 | writeText, 5 | unzip, 6 | pyEnv, 7 | editables, 8 | rootName, 9 | }: let 10 | args = writeText "args" (builtins.toJSON { 11 | inherit findRoot unzip rootName pyEnv editables; 12 | inherit (pyEnv) sitePackages; 13 | inherit (builtins) storeDir; 14 | }); 15 | in '' 16 | source <(${pyEnv}/bin/python ${./editable.py} ${args}) 17 | '' 18 | -------------------------------------------------------------------------------- /docs/src/v1-api/users.md: -------------------------------------------------------------------------------- 1 | # The users of dream2nix 2 | The following groups of users are relevant regarding the v1 API design. 3 | 4 | ## Integration Maintainers (Level1) 5 | People who use dream2nix to maintain language2nix integrations 6 | 7 | ## Package Maintainers (Level2) 8 | People who use dream2nix to maintain nix derivations for packages 9 | 10 | ## Consumers (Level3) 11 | People who use and customize packages created via dream2nix 12 | -------------------------------------------------------------------------------- /lib/internal/hashFile.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | runCommandLocal, 4 | nix, 5 | ... 6 | }: let 7 | l = builtins // lib; 8 | 9 | # hash a file via `nix hash file` 10 | hashFile = algo: path: let 11 | hashFile = runCommandLocal "hash-${algo}" {} '' 12 | ${nix}/bin/nix --option experimental-features nix-command hash file ${path} | tr --delete '\n' > $out 13 | ''; 14 | in 15 | l.readFile hashFile; 16 | in 17 | hashFile 18 | -------------------------------------------------------------------------------- /modules/dream2nix/buildPythonPackage-mixin/tests/packages/basic/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.buildPythonPackage-mixin 9 | dream2nix.modules.dream2nix.core 10 | ]; 11 | name = "test"; 12 | version = "1.0.0"; 13 | phases = ["buildPhase"]; 14 | buildPhase = "echo -n hello > $out && cp $out $dist"; 15 | format = "setuptools"; 16 | } 17 | -------------------------------------------------------------------------------- /scripts/update-aarch64-locks.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | 3 | ssh hetzner@mac01.numtide.com " 4 | cd dave/dream2nix/examples/packages/languages/python-local-development \ 5 | && git pull \ 6 | && nix run .#default.lock 7 | " 8 | 9 | scp hetzner@mac01.numtide.com:~/dave/dream2nix/examples/packages/languages/python-local-development/lock.aarch64-darwin.json \ 10 | examples/packages/languages/python-local-development/lock.aarch64-darwin.json 11 | -------------------------------------------------------------------------------- /lib/internal/hashPath.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | runCommandLocal, 4 | nix, 5 | ... 6 | }: let 7 | l = builtins // lib; 8 | 9 | # hash the contents of a path via `nix hash path` 10 | hashPath = algo: path: let 11 | hashPath = runCommandLocal "hash-${algo}" {} '' 12 | ${nix}/bin/nix --option experimental-features nix-command hash path ${path} | tr --delete '\n' > $out 13 | ''; 14 | in 15 | l.readFile hashPath; 16 | in 17 | hashPath 18 | -------------------------------------------------------------------------------- /modules/dream2nix/buildPythonPackage/tests/packages/basic/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.buildPythonPackage 9 | dream2nix.modules.dream2nix.core 10 | ]; 11 | name = "test"; 12 | version = "1.0.0"; 13 | mkDerivation.phases = ["buildPhase"]; 14 | buildPythonPackage.format = "setuptools"; 15 | mkDerivation.buildPhase = "echo -n hello > $out && cp $out $dist"; 16 | } 17 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-spago/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | ... 5 | }: let 6 | l = lib // builtins; 7 | t = l.types; 8 | in { 9 | options.spago = { 10 | spagoYamlFile = l.mkOption { 11 | type = t.path; 12 | default = "${config.mkDerivation.src}/spago.yaml"; 13 | defaultText = "\${config.mkDerivation.src}/spago.yaml"; 14 | }; 15 | 16 | sources = l.mkOption { 17 | type = t.lazyAttrsOf t.package; 18 | }; 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /modules/dream2nix/core/ui/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: { 6 | imports = [ 7 | ./interface.nix 8 | ../public 9 | ]; 10 | 11 | config.public.name = lib.mkDefault config.name; 12 | config.public.version = lib.mkDefault config.version; 13 | config.public.${ 14 | if config ? lock 15 | then "lock" 16 | else null 17 | } = 18 | config.lock.refresh; 19 | config.type = "derivation"; 20 | config.drvPath = config.public.drvPath; 21 | } 22 | -------------------------------------------------------------------------------- /examples/packages/languages/haskell-local-development-cabal/my-test-project.cabal: -------------------------------------------------------------------------------- 1 | cabal-version: 3.4 2 | name: my-test-project 3 | version: 1.0.0 4 | build-type: Simple 5 | 6 | common warnings 7 | ghc-options: -Wall 8 | 9 | executable my-test-project 10 | import: warnings 11 | main-is: Main.hs 12 | build-depends: 13 | , base 14 | , zlib 15 | , free 16 | hs-source-dirs: app 17 | default-language: GHC2021 18 | -------------------------------------------------------------------------------- /modules/dream2nix/pip/tests/packages/can-handle-setuptools-runtime-dep/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ "setuptools" ] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "my-tool" 7 | description = "my tool" 8 | version = "1.0.0" 9 | dependencies = [ 10 | # This depends on setuptools at runtime as well as during build time 11 | # It must not lead to a conflict with the nixpkgs setuptools 12 | "websocket" 13 | ] 14 | 15 | [project.scripts] 16 | my-tool = "my_tool:main" 17 | -------------------------------------------------------------------------------- /tests/nix-unit/test_python-pdm-lib/fixtures/pyproject.toml: -------------------------------------------------------------------------------- 1 | 2 | [project] 3 | name = "my-project" 4 | version = "0.1.0" 5 | description = "" 6 | dependencies = [ 7 | "requests>=2.31.0", 8 | ] 9 | requires-python = ">=3.10" 10 | readme = "README.md" 11 | license = {text = "MIT"} 12 | 13 | [project.scripts] 14 | my-script = "my_project:main" 15 | 16 | [project.optional-dependencies] 17 | dev = [ 18 | "pi>=0.1.2", 19 | ] 20 | 21 | [build-system] 22 | requires = ["pdm-backend"] 23 | build-backend = "pdm.backend" 24 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-nextjs/nextjs-app/src/app/layout.tsx: -------------------------------------------------------------------------------- 1 | import type { Metadata } from "next"; 2 | import "./globals.css"; 3 | 4 | export const metadata: Metadata = { 5 | title: "Create Next App", 6 | description: "Generated by create next app", 7 | }; 8 | 9 | export default function RootLayout({ 10 | children, 11 | }: Readonly<{ 12 | children: React.ReactNode; 13 | }>) { 14 | return ( 15 | 16 | {children} 17 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-nextjs/nextjs-app/src/app/layout.tsx: -------------------------------------------------------------------------------- 1 | import type { Metadata } from "next"; 2 | import "./globals.css"; 3 | 4 | export const metadata: Metadata = { 5 | title: "Create Next App", 6 | description: "Generated by create next app", 7 | }; 8 | 9 | export default function RootLayout({ 10 | children, 11 | }: Readonly<{ 12 | children: React.ReactNode; 13 | }>) { 14 | return ( 15 | 16 | {children} 17 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /modules/dream2nix/python-pdm/tests/packages/jupyter-lab/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | dream2nix, 4 | lib, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.WIP-python-pdm 9 | ]; 10 | # select python 3.10 11 | deps = {nixpkgs, ...}: { 12 | python = nixpkgs.python310; 13 | }; 14 | pdm.lockfile = ./pdm.lock; 15 | pdm.pyproject = ./pyproject.toml; 16 | mkDerivation = { 17 | src = ./.; 18 | buildInputs = [ 19 | config.deps.python.pkgs.pdm-backend 20 | ]; 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development-machine-learning/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | dream2nix, 3 | config, 4 | lib, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.WIP-python-pyproject 9 | ]; 10 | 11 | deps = {nixpkgs, ...}: { 12 | python = nixpkgs.python310; 13 | }; 14 | 15 | mkDerivation = { 16 | src = ./.; 17 | }; 18 | 19 | # This is not strictly required, but setting it will keep most dependencies 20 | # locked, even when new dependencies are added via pyproject.toml 21 | } 22 | -------------------------------------------------------------------------------- /modules/dream2nix/python-pdm/tests/packages/python-local-development/pyproject.toml: -------------------------------------------------------------------------------- 1 | 2 | [project] 3 | name = "my-project" 4 | version = "0.1.0" 5 | description = "" 6 | dependencies = [ 7 | "pi>=0.1.2", 8 | ] 9 | requires-python = ">=3.10" 10 | readme = "README.md" 11 | license = {text = "MIT"} 12 | 13 | [project.scripts] 14 | my-script = "my_project:main" 15 | 16 | [project.optional-dependencies] 17 | dev = [ 18 | "requests>=2.31.0", 19 | ] 20 | 21 | [build-system] 22 | requires = ["pdm-backend"] 23 | build-backend = "pdm.backend" 24 | -------------------------------------------------------------------------------- /tests/nix-unit/fixtures.nix: -------------------------------------------------------------------------------- 1 | {dream2nix}: rec { 2 | basic-derivation = named-derivation "hello"; 3 | named-derivation = name: { 4 | # select builtins.derivation as a backend for this package 5 | imports = [ 6 | dream2nix.modules.dream2nix.builtins-derivation 7 | ]; 8 | 9 | inherit name; 10 | version = "1.0.0"; 11 | 12 | # set options 13 | builtins-derivation = { 14 | builder = "/bin/sh"; 15 | args = ["-c" "echo $name > $out"]; 16 | system = "x86_64-linux"; 17 | }; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /examples/packages/languages/rust-local-development-workspace/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.rust-cargo-lock 9 | dream2nix.modules.dream2nix.rust-cargo-vendor 10 | dream2nix.modules.dream2nix.rust-crane 11 | ]; 12 | 13 | mkDerivation = { 14 | src = ./.; 15 | }; 16 | 17 | deps = {nixpkgs, ...}: { 18 | inherit 19 | (nixpkgs) 20 | stdenv 21 | ; 22 | }; 23 | 24 | name = "app"; 25 | version = "0.1.0"; 26 | } 27 | -------------------------------------------------------------------------------- /overrides/python/psycopg2/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | dream2nix, 5 | ... 6 | }: let 7 | isSdist = lib.hasSuffix ".tar.gz" config.mkDerivation.src; 8 | in { 9 | deps = {nixpkgs, ...}: { 10 | inherit (nixpkgs) postgresql; 11 | }; 12 | 13 | # enable overrides from nixpkgs 14 | imports = [dream2nix.modules.dream2nix.nixpkgs-overrides]; 15 | nixpkgs-overrides.enable = isSdist; 16 | 17 | # add postgresql to nativeBuildInputs 18 | mkDerivation.nativeBuildInputs = lib.mkIf isSdist [config.deps.postgresql]; 19 | } 20 | -------------------------------------------------------------------------------- /docs/src/style.css: -------------------------------------------------------------------------------- 1 | .md-header .md-logo { 2 | background-color: white; 3 | border-radius: 100%; 4 | } 5 | 6 | [data-md-component="toc"] .md-nav__link { 7 | display: inline-flex; 8 | } 9 | 10 | .md-typeset td pre { 11 | margin: 0; 12 | } 13 | 14 | /* increase the width of the while site */ 15 | .md-grid { 16 | max-width: 80rem; 17 | } 18 | 19 | /* increase the width of the right hand side bar to display long option names better*/ 20 | .md-sidebar--secondary { 21 | width: 25rem !important; 22 | left: -25rem !important; 23 | } 24 | -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development-pdm/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ "setuptools" ] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "my-tool" 7 | description = "my tool" 8 | version = "1.0.0" 9 | dependencies = [ 10 | "requests", 11 | ] 12 | requires-python = ">=3.8" 13 | 14 | [project.scripts] 15 | my-tool = "my_tool:main" 16 | 17 | [project.optional-dependencies] 18 | extra = [ 19 | "simplejson>=3.19.2", 20 | ] 21 | [tool.pdm.dev-dependencies] 22 | test = [ 23 | "pytest>=8.2.1", 24 | ] 25 | -------------------------------------------------------------------------------- /modules/dream2nix/buildPythonPackage/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | dream2nix, 4 | lib, 5 | ... 6 | }: let 7 | l = lib // builtins; 8 | in { 9 | imports = [ 10 | ./interface.nix 11 | dream2nix.modules.dream2nix.mkDerivation 12 | dream2nix.modules.dream2nix.deps 13 | ]; 14 | config = { 15 | package-func.func = config.deps.python.pkgs.buildPythonPackage; 16 | package-func.args = config.buildPythonPackage; 17 | 18 | deps = {nixpkgs, ...}: { 19 | python = l.mkOptionDefault nixpkgs.python3; 20 | }; 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /modules/dream2nix/python-pdm/tests/packages/python-local-development/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | dream2nix, 4 | lib, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.WIP-python-pdm 9 | ]; 10 | # select python 3.10 11 | deps = {nixpkgs, ...}: { 12 | python = nixpkgs.python310; 13 | }; 14 | pdm.lockfile = ./pdm.lock; 15 | pdm.pyproject = ./pyproject.toml; 16 | pdm.group = "dev"; 17 | mkDerivation = { 18 | src = ./.; 19 | buildInputs = [ 20 | config.deps.python.pkgs.pdm-backend 21 | ]; 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /modules/dream2nix/core/env/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: let 6 | l = lib // builtins; 7 | t = l.types; 8 | in { 9 | options = { 10 | env = lib.mkOption { 11 | type = let 12 | baseTypes = [t.bool t.int t.str t.path t.package]; 13 | allTypes = baseTypes ++ [(t.listOf (t.oneOf baseTypes))]; 14 | in 15 | t.attrsOf (t.nullOr (t.oneOf allTypes)); 16 | default = {}; 17 | description = '' 18 | environment variables passed to the build environment 19 | ''; 20 | }; 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /pkgs/fetchPipMetadata/src/tests/test_path_from_file_url.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import lock_file_from_report as l 3 | from pathlib import Path 4 | 5 | 6 | def test_wrong_prefix(): 7 | assert l.path_from_file_url("http://") == None 8 | 9 | 10 | def test_relative_path(): 11 | url = "file://foo/bar" 12 | expected = Path("./foo/bar").absolute() 13 | assert l.path_from_file_url(url) == expected 14 | 15 | 16 | def test_absolute_path(): 17 | url = "file:///foo/bar" 18 | expected = Path("/foo/bar") 19 | assert l.path_from_file_url(url) == expected 20 | -------------------------------------------------------------------------------- /docs/theme/partials/toc-item.html: -------------------------------------------------------------------------------- 1 |
  • 2 | 3 | 4 | {{ toc_item.title | replace(".", ".")}} 5 | 6 | 7 | {% if toc_item.children %} 8 | 15 | {% endif %} 16 |
  • 17 | -------------------------------------------------------------------------------- /modules/dream2nix/mkDerivation/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | specialArgs, 5 | dream2nix, 6 | ... 7 | }: let 8 | l = lib // builtins; 9 | t = l.types; 10 | 11 | mkDerivationOptions = import ./options.nix { 12 | inherit dream2nix lib specialArgs; 13 | }; 14 | in { 15 | imports = [ 16 | ../package-func/interface.nix 17 | ]; 18 | 19 | options.mkDerivation = mkDerivationOptions; 20 | 21 | options.deps.stdenv = l.mkOption { 22 | type = t.raw; 23 | description = '' 24 | The stdenv used for building this package 25 | ''; 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /modules/dream2nix/php-granular/devShell.nix: -------------------------------------------------------------------------------- 1 | { 2 | name, 3 | pkg, 4 | mkShell, 5 | php, 6 | composer, 7 | }: 8 | mkShell { 9 | buildInputs = [ 10 | php 11 | composer 12 | ]; 13 | shellHook = let 14 | vendorDir = 15 | pkg.config.package-func.result.overrideAttrs 16 | (_: { 17 | dontInstall = true; 18 | }) 19 | + "/lib/vendor/${name}/vendor"; 20 | in '' 21 | rm -rf ./vendor 22 | mkdir vendor 23 | cp -r ${vendorDir}/* vendor/ 24 | chmod -R +w ./vendor 25 | export PATH="$PATH:$(realpath ./vendor)/bin" 26 | ''; 27 | } 28 | -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development-pdm-pytorch-from-nixpkgs/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ "setuptools" ] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "my-tool" 7 | description = "my tool" 8 | version = "1.0.0" 9 | dependencies = [ 10 | "requests", 11 | "torch==2.*", 12 | ] 13 | requires-python = ">=3.10" 14 | 15 | [project.scripts] 16 | my-tool = "my_tool:main" 17 | 18 | [project.optional-dependencies] 19 | extra = [ 20 | "simplejson>=3.19.2", 21 | ] 22 | [tool.pdm.dev-dependencies] 23 | test = [ 24 | "pytest>=8.2.1", 25 | ] 26 | -------------------------------------------------------------------------------- /docs/theme/reference_header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 15 | 16 |
    state:{{ meta.state | default("experimental") }}
    maintainers: 9 | {% if meta.maintainers -%} 10 | {% for m in meta.maintainers -%}@{{m}}{{ ", " if not loop.last else "" }}{%- endfor -%} 11 | {%- else -%} 12 | noone, maybe you? 13 | {% endif %} 14 |
    17 | 18 | ## Introduction 19 | -------------------------------------------------------------------------------- /pkgs/fetchPipMetadata/src/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["flit_core >=3.2,<4"] 3 | build-backend = "flit_core.buildapi" 4 | 5 | [tool.flit.module] 6 | name = "fetch_pip_metadata" 7 | 8 | 9 | [project] 10 | name = "fetch_pip_metadata" 11 | description = "internal tooling of dream2nix python subsystem" 12 | authors = [{name = "Paul Haerle", email = "hello@phaer.org"}] 13 | dynamic = ["version"] 14 | dependencies = ["packaging"] 15 | scripts = {fetch_pip_metadata = "fetch_pip_metadata:fetch_pip_metadata"} 16 | 17 | [tool.pytest.ini_options] 18 | pythonpath = [ 19 | "fetch_pip_metadata" 20 | ] 21 | -------------------------------------------------------------------------------- /examples/packages/languages/python-packaging-ansible/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.pip 9 | ]; 10 | 11 | deps = {nixpkgs, ...}: { 12 | python = nixpkgs.python313; 13 | }; 14 | 15 | name = "ansible"; 16 | version = "2.7.1"; 17 | 18 | buildPythonPackage = { 19 | pythonImportsCheck = [ 20 | config.name 21 | ]; 22 | }; 23 | 24 | paths.lockFile = "lock.${config.deps.stdenv.system}.json"; 25 | pip = { 26 | requirementsList = ["${config.name}==${config.version}"]; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-devshell/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | dream2nix, 5 | packageSets, 6 | ... 7 | }: let 8 | l = lib // builtins; 9 | t = l.types; 10 | in { 11 | options.nodejs-devshell = { 12 | nodeModules = l.mkOption { 13 | description = "drv-parts module for the node_modules derivation"; 14 | type = t.submoduleWith { 15 | specialArgs = {inherit packageSets dream2nix;}; 16 | modules = [ 17 | dream2nix.modules.dream2nix.core 18 | dream2nix.modules.dream2nix.nodejs-node-modules 19 | ]; 20 | }; 21 | }; 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-nextjs/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.WIP-nodejs-builder-v3 9 | ]; 10 | 11 | mkDerivation = { 12 | src = ./nextjs-app; 13 | }; 14 | 15 | deps = {nixpkgs, ...}: { 16 | inherit 17 | (nixpkgs) 18 | fetchFromGitHub 19 | stdenv 20 | ; 21 | }; 22 | 23 | WIP-nodejs-builder-v3 = { 24 | packageLockFile = "${config.mkDerivation.src}/package-lock.json"; 25 | }; 26 | 27 | name = "nextjs-app"; 28 | version = "0.1.0"; 29 | } 30 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-nextjs/nextjs-app/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | .yarn/install-state.gz 8 | 9 | # testing 10 | /coverage 11 | 12 | # next.js 13 | /.next/ 14 | /out/ 15 | 16 | # production 17 | /build 18 | 19 | # misc 20 | .DS_Store 21 | *.pem 22 | 23 | # debug 24 | npm-debug.log* 25 | yarn-debug.log* 26 | yarn-error.log* 27 | 28 | # local env files 29 | .env*.local 30 | 31 | # vercel 32 | .vercel 33 | 34 | # typescript 35 | *.tsbuildinfo 36 | next-env.d.ts 37 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-devshell-v3/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | dream2nix, 5 | packageSets, 6 | ... 7 | }: let 8 | l = lib // builtins; 9 | t = l.types; 10 | in { 11 | options.nodejs-devshell-v3 = { 12 | nodeModules = l.mkOption { 13 | description = "drv-parts module for the node_modules derivation"; 14 | type = t.submoduleWith { 15 | specialArgs = {inherit packageSets dream2nix;}; 16 | modules = [ 17 | dream2nix.modules.dream2nix.core 18 | dream2nix.modules.dream2nix.nodejs-node-modules-v3 19 | ]; 20 | }; 21 | }; 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /overrides/python/torch/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: { 6 | # stripping doesn't reduce the file size much, and it takes a long time 7 | mkDerivation.dontStrip = true; 8 | 9 | # use the autoAddDriverRunpath to add /run/opengl-driver/lib to the RPATH 10 | # of all ELF files 11 | deps = {nixpkgs, ...}: { 12 | inherit (nixpkgs) autoAddDriverRunpath; 13 | }; 14 | mkDerivation.nativeBuildInputs = [ 15 | config.deps.autoAddDriverRunpath 16 | ]; 17 | 18 | # this file is patched manually, so ignore it in autoPatchelf 19 | env.autoPatchelfIgnoreMissingDeps = ["libcuda.so.1"]; 20 | } 21 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-groups/groups-option.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | specialArgs, 5 | ... 6 | }: let 7 | t = lib.types; 8 | groupType = t.submoduleWith { 9 | modules = [ 10 | (import ./group.nix { 11 | inherit (config) overrideAll; 12 | overrides = config.overrides; 13 | }) 14 | ]; 15 | inherit specialArgs; 16 | }; 17 | in 18 | lib.mkOption { 19 | type = t.lazyAttrsOf groupType; 20 | description = '' 21 | Holds multiple package sets (eg. groups). 22 | Holds shared config (overrideAll) and overrides on a global and on a per group basis. 23 | ''; 24 | } 25 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-nextjs/nextjs-app/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | .yarn/install-state.gz 8 | 9 | # testing 10 | /coverage 11 | 12 | # next.js 13 | /.next/ 14 | /out/ 15 | 16 | # production 17 | /build 18 | 19 | # misc 20 | .DS_Store 21 | *.pem 22 | 23 | # debug 24 | npm-debug.log* 25 | yarn-debug.log* 26 | yarn-error.log* 27 | 28 | # local env files 29 | .env*.local 30 | 31 | # vercel 32 | .vercel 33 | 34 | # typescript 35 | *.tsbuildinfo 36 | next-env.d.ts 37 | -------------------------------------------------------------------------------- /lib/internal/fetchers/gitlab/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | pkgs, 3 | utils, 4 | ... 5 | }: { 6 | inputs = [ 7 | "owner" 8 | "repo" 9 | "rev" 10 | ]; 11 | 12 | versionField = "rev"; 13 | 14 | outputs = { 15 | owner, 16 | repo, 17 | rev, 18 | ... 19 | }: let 20 | b = builtins; 21 | in { 22 | calcHash = algo: 23 | utils.hashPath algo (b.fetchTarball { 24 | url = "https://gitlab.com/${owner}/${repo}/-/archive/${rev}/${repo}-${rev}.tar.gz"; 25 | }); 26 | 27 | fetched = hash: 28 | pkgs.fetchFromGitLab { 29 | inherit owner repo rev hash; 30 | }; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /modules/dream2nix/builtins-derivation/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: let 6 | l = lib // builtins; 7 | t = l.types; 8 | 9 | common-options = import ./derivation-common/options.nix {inherit lib;}; 10 | 11 | builtin-derivation-options = { 12 | # basic arguments 13 | builder = lib.mkOption { 14 | type = t.oneOf [t.str t.path t.package]; 15 | }; 16 | system = lib.mkOption { 17 | type = t.str; 18 | }; 19 | }; 20 | in { 21 | imports = [ 22 | ../package-func/interface.nix 23 | ]; 24 | 25 | options.builtins-derivation = common-options // builtin-derivation-options; 26 | } 27 | -------------------------------------------------------------------------------- /modules/dream2nix/mkDerivation-mixin/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | specialArgs, 5 | dream2nix, 6 | ... 7 | }: let 8 | l = lib // builtins; 9 | t = l.types; 10 | 11 | mkDerivationOptions = import ../mkDerivation/options.nix { 12 | inherit dream2nix lib specialArgs; 13 | }; 14 | in { 15 | imports = [ 16 | ../package-func/interface.nix 17 | ]; 18 | 19 | options = 20 | mkDerivationOptions 21 | // { 22 | deps.stdenv = l.mkOption { 23 | type = t.raw; 24 | description = '' 25 | The stdenv used for building this package 26 | ''; 27 | }; 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-node-modules/tests/packages/basic/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.nodejs-node-modules 9 | dream2nix.modules.dream2nix.nodejs-package-lock 10 | ]; 11 | 12 | deps = {nixpkgs, ...}: { 13 | inherit 14 | (nixpkgs) 15 | fetchFromGitHub 16 | mkShell 17 | stdenv 18 | ; 19 | }; 20 | 21 | nodejs-package-lock = { 22 | source = ./.; 23 | }; 24 | 25 | name = "app"; 26 | version = "1.0.0"; 27 | mkDerivation = { 28 | src = config.nodejs-package-lock.source; 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /modules/dream2nix/core/public/optsPackageCompat.nix: -------------------------------------------------------------------------------- 1 | # The proposal in https://github.com/NixOS/nix/issues/6507 is not entirely 2 | # compatible to the current implementation of nix. 3 | # This module adds fields that are needed to ensure compatibility. 4 | {lib, ...}: let 5 | l = lib // builtins; 6 | t = l.types; 7 | in { 8 | drvPath = l.mkOption { 9 | type = t.path; 10 | }; 11 | outPath = l.mkOption { 12 | type = t.path; 13 | }; 14 | # Needed by nix run .#installable 15 | outputName = l.mkOption { 16 | type = t.str; 17 | }; 18 | type = l.mkOption { 19 | type = t.str; 20 | default = "derivation"; 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /modules/dream2nix/buildPythonPackage-mixin/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: let 6 | l = lib // builtins; 7 | t = l.types; 8 | 9 | buildPythonPackageOptions = import ../buildPythonPackage/options.nix {inherit config lib;}; 10 | in { 11 | options = 12 | buildPythonPackageOptions 13 | // { 14 | deps.python = l.mkOption { 15 | type = t.package; 16 | description = "The python interpreter package to use"; 17 | }; 18 | }; 19 | 20 | config = { 21 | format = lib.mkOptionDefault ( 22 | if config.pyproject == null 23 | then "setuptools" 24 | else null 25 | ); 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/modules/prepared-prod.nix: -------------------------------------------------------------------------------- 1 | { 2 | dream2nix, 3 | # _module.args 4 | plent, 5 | packageName, 6 | fileSystem, 7 | nodejs, 8 | ... 9 | }: let 10 | makeNodeModules = ../scripts/build-node-modules.mjs; 11 | in { 12 | imports = [ 13 | dream2nix.modules.dream2nix.mkDerivation 14 | ]; 15 | 16 | inherit (plent) version; 17 | name = packageName + "-node_modules-prod"; 18 | env = { 19 | FILESYSTEM = builtins.toJSON fileSystem; 20 | }; 21 | mkDerivation = { 22 | dontUnpack = true; 23 | buildInputs = [nodejs]; 24 | buildPhase = '' 25 | node ${makeNodeModules} 26 | ''; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-nextjs/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.nodejs-package-lock-v3 9 | dream2nix.modules.dream2nix.nodejs-granular-v3 10 | ]; 11 | 12 | mkDerivation = { 13 | src = ./nextjs-app; 14 | }; 15 | 16 | deps = {nixpkgs, ...}: { 17 | inherit 18 | (nixpkgs) 19 | fetchFromGitHub 20 | stdenv 21 | ; 22 | }; 23 | 24 | nodejs-package-lock-v3 = { 25 | packageLockFile = "${config.mkDerivation.src}/package-lock.json"; 26 | }; 27 | 28 | name = "nextjs-app"; 29 | version = "0.1.0"; 30 | } 31 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/modules/prepared-dev.nix: -------------------------------------------------------------------------------- 1 | { 2 | dream2nix, 3 | # _module.args 4 | plent, 5 | packageName, 6 | fileSystem, 7 | nodejs, 8 | ... 9 | }: let 10 | makeNodeModules = ../scripts/build-node-modules.mjs; 11 | in { 12 | imports = [ 13 | dream2nix.modules.dream2nix.mkDerivation 14 | ]; 15 | 16 | inherit (plent) version; 17 | name = packageName + "-node_modules-dev"; 18 | env = { 19 | FILESYSTEM = builtins.toJSON fileSystem; 20 | }; 21 | 22 | mkDerivation = { 23 | dontUnpack = true; 24 | buildInputs = [nodejs]; 25 | buildPhase = '' 26 | node ${makeNodeModules} 27 | ''; 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /modules/dream2nix/buildPythonPackage/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: let 6 | l = lib // builtins; 7 | t = l.types; 8 | 9 | buildPythonPackageOptions = import ./options.nix {inherit config lib;}; 10 | in { 11 | options = { 12 | buildPythonPackage = buildPythonPackageOptions; 13 | deps.python = l.mkOption { 14 | type = t.package; 15 | description = "The python interpreter package to use"; 16 | }; 17 | }; 18 | config = { 19 | buildPythonPackage.format = lib.mkOptionDefault ( 20 | if config.buildPythonPackage.pyproject == null 21 | then "setuptools" 22 | else null 23 | ); 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /modules/dream2nix/python-editables/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | dream2nix, 5 | ... 6 | }: let 7 | editables = lib.filterAttrs (_name: path: path != false) config.editables; 8 | in { 9 | imports = [ 10 | ./interface.nix 11 | dream2nix.modules.dream2nix.deps 12 | ]; 13 | deps = {nixpkgs, ...}: { 14 | inherit (nixpkgs) unzip writeText mkShell; 15 | python = nixpkgs.python3; 16 | }; 17 | editablesShellHook = import ./editable.nix { 18 | inherit lib; 19 | inherit (config.deps) unzip writeText; 20 | inherit (config.paths) findRoot; 21 | inherit (config) editables pyEnv; 22 | rootName = config.name; 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-nextjs/nextjs-app/tailwind.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from "tailwindcss"; 2 | 3 | const config: Config = { 4 | content: [ 5 | "./src/pages/**/*.{js,ts,jsx,tsx,mdx}", 6 | "./src/components/**/*.{js,ts,jsx,tsx,mdx}", 7 | "./src/app/**/*.{js,ts,jsx,tsx,mdx}", 8 | ], 9 | theme: { 10 | extend: { 11 | backgroundImage: { 12 | "gradient-radial": "radial-gradient(var(--tw-gradient-stops))", 13 | "gradient-conic": 14 | "conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))", 15 | }, 16 | }, 17 | }, 18 | plugins: [], 19 | }; 20 | export default config; 21 | -------------------------------------------------------------------------------- /overrides/python/opencv-python/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: { 6 | # TODO: supply more of the dependencies instead of ignoring them 7 | env.autoPatchelfIgnoreMissingDeps = true; 8 | mkDerivation = { 9 | buildInputs = [ 10 | config.deps.libglvnd 11 | config.deps.glib 12 | config.deps.qt6Packages.qtbase 13 | ]; 14 | nativeBuildInputs = [ 15 | config.deps.qt6Packages.wrapQtAppsHook 16 | ]; 17 | }; 18 | deps = {nixpkgs, ...}: 19 | lib.mapAttrs (_: lib.mkDefault) { 20 | inherit 21 | (nixpkgs) 22 | libglvnd 23 | glib 24 | qt6Packages 25 | ; 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /pkgs/fetchPipMetadata/package.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | # This python is for the locking logic, not the python to lock packages for. 4 | python3, 5 | gitMinimal, 6 | nix-prefetch-scripts, 7 | }: let 8 | package = python3.pkgs.buildPythonPackage { 9 | name = "fetch-pip-metadata"; 10 | pyproject = true; 11 | src = ./src; 12 | nativeBuildInputs = [ 13 | gitMinimal 14 | python3.pkgs.pytestCheckHook 15 | ]; 16 | propagatedBuildInputs = with python3.pkgs; [ 17 | packaging 18 | flit-core 19 | nix-prefetch-scripts 20 | pip 21 | ]; 22 | 23 | meta.mainProgram = "fetch_pip_metadata"; 24 | }; 25 | in 26 | package 27 | -------------------------------------------------------------------------------- /lib/internal/fetchers/github/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | pkgs, 3 | lib, 4 | utils, 5 | ... 6 | }: { 7 | inputs = [ 8 | "owner" 9 | "repo" 10 | "rev" 11 | ]; 12 | 13 | versionField = "rev"; 14 | 15 | defaultUpdater = "githubNewestReleaseTag"; 16 | 17 | outputs = { 18 | owner, 19 | repo, 20 | rev, 21 | ... 22 | }: let 23 | b = builtins; 24 | in { 25 | calcHash = algo: 26 | utils.hashPath algo (b.fetchTarball { 27 | url = "https://github.com/${owner}/${repo}/tarball/${rev}"; 28 | }); 29 | 30 | fetched = hash: 31 | pkgs.fetchFromGitHub { 32 | inherit owner repo rev hash; 33 | }; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-nextjs/nextjs-app/tailwind.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from "tailwindcss"; 2 | 3 | const config: Config = { 4 | content: [ 5 | "./src/pages/**/*.{js,ts,jsx,tsx,mdx}", 6 | "./src/components/**/*.{js,ts,jsx,tsx,mdx}", 7 | "./src/app/**/*.{js,ts,jsx,tsx,mdx}", 8 | ], 9 | theme: { 10 | extend: { 11 | backgroundImage: { 12 | "gradient-radial": "radial-gradient(var(--tw-gradient-stops))", 13 | "gradient-conic": 14 | "conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))", 15 | }, 16 | }, 17 | }, 18 | plugins: [], 19 | }; 20 | export default config; 21 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-nextjs/nextjs-app/public/vercel.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/packages/languages/python-packaging-pillow/lock.x86_64-linux.json: -------------------------------------------------------------------------------- 1 | { 2 | "fetchPipMetadata": { 3 | "sources": { 4 | "pillow": { 5 | "is_direct": false, 6 | "sha256": "166c1cd4d24309b30d61f79f4a9114b7b2313d7450912277855ff5dfd7cd4a06", 7 | "type": "url", 8 | "url": "https://files.pythonhosted.org/packages/cd/74/ad3d526f3bf7b6d3f408b73fde271ec69dfac8b81341a318ce825f2b3812/pillow-10.4.0.tar.gz", 9 | "version": "10.4.0" 10 | } 11 | }, 12 | "targets": { 13 | "default": { 14 | "pillow": [] 15 | } 16 | } 17 | }, 18 | "invalidationHash": "0e7079891a40d9873f5b3f5fdd4d8007c92e4819e8801631a33bbb714fcf6b04" 19 | } -------------------------------------------------------------------------------- /.github/workflows/flake-update.yml: -------------------------------------------------------------------------------- 1 | name: update-flake-lock 2 | on: 3 | workflow_dispatch: 4 | schedule: 5 | - cron: '15 18 * * *' # runs daily at 18:15 UTC 6 | 7 | jobs: 8 | lockfile: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout repository 12 | uses: actions/checkout@v6.0.1 13 | - name: Install Nix 14 | uses: DeterminateSystems/nix-installer-action@main 15 | - name: Update flake.lock 16 | uses: DavHau/update-flake-lock@main 17 | with: 18 | pr-title: "Update nixpkgs" 19 | pr-labels: dependencies 20 | inputs: nixpkgs pyproject-nix purescript-overlay 21 | flake-dirs: . ./dev-flake 22 | -------------------------------------------------------------------------------- /examples/packages/languages/python-packaging-pillow/lock.aarch64-darwin.json: -------------------------------------------------------------------------------- 1 | { 2 | "fetchPipMetadata": { 3 | "sources": { 4 | "pillow": { 5 | "is_direct": false, 6 | "sha256": "166c1cd4d24309b30d61f79f4a9114b7b2313d7450912277855ff5dfd7cd4a06", 7 | "type": "url", 8 | "url": "https://files.pythonhosted.org/packages/cd/74/ad3d526f3bf7b6d3f408b73fde271ec69dfac8b81341a318ce825f2b3812/pillow-10.4.0.tar.gz", 9 | "version": "10.4.0" 10 | } 11 | }, 12 | "targets": { 13 | "default": { 14 | "pillow": [] 15 | } 16 | } 17 | }, 18 | "invalidationHash": "0e7079891a40d9873f5b3f5fdd4d8007c92e4819e8801631a33bbb714fcf6b04" 19 | } -------------------------------------------------------------------------------- /modules/dream2nix/multi-derivation-package/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | dream2nix, 5 | extendModules, 6 | ... 7 | }: { 8 | imports = [ 9 | ./interface.nix 10 | dream2nix.modules.dream2nix.core 11 | ]; 12 | # make the core module happy 13 | name = config.out.name; 14 | version = config.out.version; 15 | 16 | # make the top-level look like a derivation under 'out' 17 | public = { 18 | inherit extendModules; 19 | inherit 20 | (config.out) 21 | config 22 | drvPath 23 | name 24 | outPath 25 | outputName 26 | outputs 27 | type 28 | version 29 | ; 30 | out = config.out.public; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-nextjs/nextjs-app/public/vercel.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/repo-with-packages/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | dream2nixSource ? 3 | builtins.fetchTarball { 4 | url = "https://github.com/nix-community/dream2nix/tarball/main"; 5 | # sha256 = ""; 6 | }, 7 | pkgs ? import (import dream2nixSource {}).inputs.nixpkgs {}, 8 | }: let 9 | dream2nix = import dream2nixSource {}; 10 | # all packages defined inside ./packages/ 11 | packages = dream2nix.lib.importPackages { 12 | projectRoot = ./.; 13 | # can be changed to ".git" to get rid of .project-root 14 | projectRootFile = ".project-root"; 15 | packagesDir = ./packages; 16 | packageSets.nixpkgs = pkgs; 17 | }; 18 | in 19 | # all packages defined inside ./packages/ 20 | packages 21 | -------------------------------------------------------------------------------- /modules/dream2nix/python-pdm/sourceSelectorOption.nix: -------------------------------------------------------------------------------- 1 | {lib}: 2 | lib.mkOption { 3 | type = 4 | lib.types.either 5 | (lib.types.enum ["wheel" "sdist"]) 6 | (lib.types.functionTo lib.types.str); 7 | description = '' 8 | A selector function which picks a source for a specific dependency 9 | Python dependencies can have multiple possible sources, like for example: 10 | - requests-2.31.0.tar.gz 11 | - requests-2.31.0-py3-none-any.whl 12 | The selector receives a list of possible sources and should return either a single source or null. 13 | ''; 14 | example = lib.literalExpression '' 15 | fnames: lib.findFirst (fname: lib.hasSuffix "none-any.whl") none fnames 16 | ''; 17 | } 18 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) 6 | 7 | ## [Unreleased] 8 | 9 | ### Added 10 | 11 | #### Unified override interface across languages 12 | 13 | New options `overrides.${name}` and `overrideAll` for all language modules that manage a dependency tree. 14 | 15 | ### Changed 16 | 17 | #### Modified choice of output used as top-level output in package-func 18 | 19 | Changed the top-level output selected for multi-output derivations to be the first output declared in `package-func.outputs` or the default output (if the attribute `outputSpecified` is true) instead of 'out'. -------------------------------------------------------------------------------- /modules/dream2nix/pip/tests/packages/can-build-setuptools/lock.x86_64-linux.json: -------------------------------------------------------------------------------- 1 | { 2 | "fetchPipMetadata": { 3 | "sources": { 4 | "setuptools": { 5 | "is_direct": false, 6 | "sha256": "33874fdc59b3188304b2e7c80d9029097ea31627180896fb549c578ceb8a0855", 7 | "type": "url", 8 | "url": "https://files.pythonhosted.org/packages/51/a0/ee460cc54e68afcf33190d198299c9579a5eafeadef0016ae8563237ccb6/setuptools-71.1.0-py3-none-any.whl", 9 | "version": "71.1.0" 10 | } 11 | }, 12 | "targets": { 13 | "default": { 14 | "setuptools": [] 15 | } 16 | } 17 | }, 18 | "invalidationHash": "745e402fb87bbcc54e9ced31048027b3dbc05b110cb337c903fbda98adca2361" 19 | } -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development-multiple-packages/lock.aarch64-darwin.json: -------------------------------------------------------------------------------- 1 | { 2 | "fetchPipMetadata": { 3 | "sources": { 4 | "subpkg1": { 5 | "is_direct": true, 6 | "path": "subpkg1", 7 | "type": "local", 8 | "version": "0.0.1" 9 | }, 10 | "subpkg2": { 11 | "is_direct": true, 12 | "path": "subpkg2", 13 | "type": "local", 14 | "version": "0.0.2" 15 | } 16 | }, 17 | "targets": { 18 | "default": { 19 | "subpkg1": [ 20 | "subpkg2" 21 | ], 22 | "subpkg2": [] 23 | } 24 | } 25 | }, 26 | "invalidationHash": "674e8492504c581f03993563444b383363c303130eda97b55ffebb4db414514f" 27 | } -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development-multiple-packages/lock.x86_64-linux.json: -------------------------------------------------------------------------------- 1 | { 2 | "fetchPipMetadata": { 3 | "sources": { 4 | "subpkg1": { 5 | "is_direct": true, 6 | "path": "subpkg1", 7 | "type": "local", 8 | "version": "0.0.1" 9 | }, 10 | "subpkg2": { 11 | "is_direct": true, 12 | "path": "subpkg2", 13 | "type": "local", 14 | "version": "0.0.2" 15 | } 16 | }, 17 | "targets": { 18 | "default": { 19 | "subpkg1": [ 20 | "subpkg2" 21 | ], 22 | "subpkg2": [] 23 | } 24 | } 25 | }, 26 | "invalidationHash": "674e8492504c581f03993563444b383363c303130eda97b55ffebb4db414514f" 27 | } -------------------------------------------------------------------------------- /examples/repo-with-packages/packages/hello/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | dream2nix, 3 | config, 4 | lib, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.mkDerivation 9 | ]; 10 | 11 | name = "hello"; 12 | version = "2.12.1"; 13 | 14 | deps = {nixpkgs, ...}: { 15 | inherit 16 | (nixpkgs) 17 | stdenv 18 | ; 19 | }; 20 | 21 | env = lib.optionalAttrs config.deps.stdenv.hostPlatform.isDarwin { 22 | NIX_LDFLAGS = "-liconv"; 23 | }; 24 | 25 | mkDerivation = { 26 | src = builtins.fetchTarball { 27 | url = "https://ftp.gnu.org/gnu/hello/hello-${config.version}.tar.gz"; 28 | sha256 = "0xw6cr5jgi1ir13q6apvrivwmmpr5j8vbymp0x6ll0kcv6366hnn"; 29 | }; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-python-pyproject/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | dream2nix, 3 | config, 4 | lib, 5 | ... 6 | }: let 7 | pyproject = 8 | builtins.fromTOML 9 | (builtins.readFile (config.mkDerivation.src + /pyproject.toml)); 10 | in { 11 | imports = [ 12 | dream2nix.modules.dream2nix.pip 13 | ]; 14 | 15 | mkDerivation = { 16 | buildInputs = 17 | pyproject.build-system.requires 18 | or [config.deps.python.pkgs.setuptools]; 19 | }; 20 | 21 | buildPythonPackage = { 22 | pyproject = true; 23 | }; 24 | 25 | name = pyproject.project.name; 26 | version = pyproject.project.version; 27 | 28 | pip.requirementsList = pyproject.project.dependencies; 29 | pip.flattenDependencies = true; 30 | } 31 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-nextjs/nextjs-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nextjs-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint" 10 | }, 11 | "dependencies": { 12 | "react": "^18", 13 | "react-dom": "^18", 14 | "next": "14.1.0" 15 | }, 16 | "devDependencies": { 17 | "typescript": "^5", 18 | "@types/node": "^20", 19 | "@types/react": "^18", 20 | "@types/react-dom": "^18", 21 | "autoprefixer": "^10.0.1", 22 | "postcss": "^8", 23 | "tailwindcss": "^3.3.0", 24 | "eslint": "^8", 25 | "eslint-config-next": "14.1.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /modules/dream2nix/buildPythonPackage-mixin/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | dream2nix, 4 | lib, 5 | ... 6 | }: let 7 | l = lib // builtins; 8 | 9 | buildPythonPackageOptions = import ../buildPythonPackage/options.nix {inherit config lib;}; 10 | 11 | keepArg = key: val: buildPythonPackageOptions ? ${key}; 12 | in { 13 | imports = [ 14 | ./interface.nix 15 | dream2nix.modules.dream2nix.mkDerivation-mixin 16 | dream2nix.modules.dream2nix.deps 17 | ]; 18 | config = { 19 | package-func.func = config.deps.python.pkgs.buildPythonPackage; 20 | package-func.args = lib.filterAttrs keepArg config; 21 | 22 | deps = {nixpkgs, ...}: { 23 | python = l.mkOptionDefault nixpkgs.python3; 24 | }; 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /examples/repo-with-packages-flake/packages/hello/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | dream2nix, 3 | config, 4 | lib, 5 | self, 6 | ... 7 | }: { 8 | imports = [ 9 | dream2nix.modules.dream2nix.mkDerivation 10 | ]; 11 | 12 | name = "hello"; 13 | version = "2.12"; 14 | 15 | deps = {nixpkgs, ...}: { 16 | inherit 17 | (nixpkgs) 18 | stdenv 19 | ; 20 | }; 21 | 22 | env = lib.optionalAttrs config.deps.stdenv.hostPlatform.isDarwin { 23 | NIX_LDFLAGS = "-liconv"; 24 | }; 25 | 26 | mkDerivation = { 27 | src = builtins.fetchTarball { 28 | url = "https://ftp.gnu.org/gnu/hello/hello-${config.version}.tar.gz"; 29 | sha256 = "sha256-4GQeKLIxoWfYiOraJub5RsHNVQBr2H+3bfPP22PegdU="; 30 | }; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-devshell/tests/packages/basic/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.nodejs-devshell 9 | dream2nix.modules.dream2nix.nodejs-package-lock 10 | ]; 11 | 12 | nodejs-package-lock = { 13 | source = ./.; 14 | }; 15 | 16 | deps = {nixpkgs, ...}: { 17 | inherit 18 | (nixpkgs) 19 | fetchFromGitHub 20 | mkShell 21 | rsync 22 | stdenv 23 | ; 24 | }; 25 | 26 | name = "app"; 27 | version = "1.0.0"; 28 | 29 | mkDerivation = { 30 | src = config.nodejs-package-lock.source; 31 | # allow devshell to be built -> CI pipeline happy 32 | buildPhase = "mkdir $out"; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-nextjs/nextjs-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nextjs-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint" 10 | }, 11 | "dependencies": { 12 | "react": "^18", 13 | "react-dom": "^18", 14 | "next": "14.1.0" 15 | }, 16 | "devDependencies": { 17 | "typescript": "^5", 18 | "@types/node": "^20", 19 | "@types/react": "^18", 20 | "@types/react-dom": "^18", 21 | "autoprefixer": "^10.0.1", 22 | "postcss": "^8", 23 | "tailwindcss": "^3.3.0", 24 | "eslint": "^8", 25 | "eslint-config-next": "14.1.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-nextjs/nextjs-app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": ["dom", "dom.iterable", "esnext"], 4 | "allowJs": true, 5 | "skipLibCheck": true, 6 | "strict": true, 7 | "noEmit": true, 8 | "esModuleInterop": true, 9 | "module": "esnext", 10 | "moduleResolution": "bundler", 11 | "resolveJsonModule": true, 12 | "isolatedModules": true, 13 | "jsx": "preserve", 14 | "incremental": true, 15 | "plugins": [ 16 | { 17 | "name": "next" 18 | } 19 | ], 20 | "paths": { 21 | "@/*": ["./src/*"] 22 | } 23 | }, 24 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], 25 | "exclude": ["node_modules"] 26 | } 27 | -------------------------------------------------------------------------------- /tests/nix-unit/test_python-pdm-lib/fixtures/pdm-extras.lock: -------------------------------------------------------------------------------- 1 | # Tests: When 'root' is resolved, 2 | 3 | [metadata] 4 | groups = ["default"] 5 | strategy = ["cross_platform"] 6 | lock_version = "4.4" 7 | 8 | [[package]] 9 | name = "foo" 10 | version = "1.0.0" 11 | files = [] 12 | 13 | [[package]] 14 | name = "foo" 15 | extras = ["extra1"] 16 | version = "1.0.0" 17 | files = [] 18 | 19 | [[package]] 20 | name = "bar" 21 | version = "1.0.0" 22 | files = [] 23 | 24 | [[package]] 25 | name = "bar" 26 | extras = ["extra2"] 27 | version = "1.0.0" 28 | files = [] 29 | 30 | [[package]] 31 | name = "root" 32 | version = "1.0.0" 33 | dependencies = [ 34 | "foo[extra1]==1.0.0", 35 | "foo==1.0.0", 36 | "bar==1.0.0", 37 | "bar[extra2]==1.0.0" 38 | ] 39 | files = [] 40 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-nextjs/nextjs-app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": ["dom", "dom.iterable", "esnext"], 4 | "allowJs": true, 5 | "skipLibCheck": true, 6 | "strict": true, 7 | "noEmit": true, 8 | "esModuleInterop": true, 9 | "module": "esnext", 10 | "moduleResolution": "bundler", 11 | "resolveJsonModule": true, 12 | "isolatedModules": true, 13 | "jsx": "preserve", 14 | "incremental": true, 15 | "plugins": [ 16 | { 17 | "name": "next" 18 | } 19 | ], 20 | "paths": { 21 | "@/*": ["./src/*"] 22 | } 23 | }, 24 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], 25 | "exclude": ["node_modules"] 26 | } 27 | -------------------------------------------------------------------------------- /lib/internal/dreamLockUtils.nix: -------------------------------------------------------------------------------- 1 | # This is currently only used for legacy modules ported to v1. 2 | # The dream-lock concept might be deprecated together with this module at some 3 | # point. 4 | {lib, ...}: let 5 | l = builtins // lib; 6 | 7 | mkDiscovereredProject = { 8 | name, 9 | relPath, 10 | subsystem, 11 | subsystemInfo, 12 | translators, 13 | }: { 14 | inherit 15 | name 16 | relPath 17 | subsystem 18 | subsystemInfo 19 | translators 20 | ; 21 | }; 22 | 23 | mkPathSource = { 24 | path, 25 | rootName, 26 | rootVersion, 27 | } @ args: 28 | args 29 | // { 30 | type = "path"; 31 | }; 32 | in { 33 | inherit 34 | mkDiscovereredProject 35 | mkPathSource 36 | ; 37 | } 38 | -------------------------------------------------------------------------------- /examples/packages/languages/php-packaging/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.php-composer-lock 9 | dream2nix.modules.dream2nix.php-granular 10 | ]; 11 | 12 | deps = {nixpkgs, ...}: { 13 | inherit 14 | (nixpkgs) 15 | fetchFromGitHub 16 | stdenv 17 | ; 18 | }; 19 | 20 | name = "cowsay"; 21 | version = "1.2.0"; 22 | 23 | php-composer-lock = { 24 | source = config.deps.fetchFromGitHub { 25 | owner = "Gipetto"; 26 | repo = "CowSay"; 27 | rev = config.version; 28 | sha256 = "sha256-jriyCzmvT2pPeNQskibBg0Bsh+h64cAEO+yOOfX2wbA="; 29 | }; 30 | }; 31 | 32 | mkDerivation = { 33 | src = config.php-composer-lock.source; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /docs/src/.nav.yml: -------------------------------------------------------------------------------- 1 | nav: 2 | - "Home": index.md 3 | - Guides: guides 4 | - Concepts: 5 | - "Modules": modules.md 6 | - "Overriding Dependencies": overrides.md 7 | - Reference: reference 8 | - Reference (experimental): reference-(experimental) 9 | - Reference (internal): reference-(internal) 10 | - Examples: 11 | - "👉 example repository": https://github.com/nix-community/dream2nix/tree/main/examples/repo-with-packages 12 | - "👉 example repository using flakes": https://github.com/nix-community/dream2nix/tree/main/examples/repo-with-packages-flake 13 | - "👉 example packages": https://github.com/nix-community/dream2nix/tree/main/examples/packages 14 | - Documentation: docs.md 15 | - Notes: 16 | - "v1 API design docs": v1-api 17 | - development-roundups 18 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-packaging-devshell-only/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.nodejs-devshell-v3 9 | ]; 10 | 11 | deps = {nixpkgs, ...}: { 12 | inherit 13 | (nixpkgs) 14 | fetchFromGitHub 15 | mkShell 16 | rsync 17 | stdenv 18 | ; 19 | }; 20 | 21 | name = "cowsay"; 22 | version = "1.5.0"; 23 | 24 | mkDerivation = { 25 | src = builtins.fetchGit { 26 | shallow = true; 27 | url = "https://github.com/DavHau/cowsay"; 28 | ref = "package-lock-v3"; 29 | rev = "c89952cb75e3e54b8ca0033bd3499297610083c7"; 30 | }; 31 | # allow devshell to be built -> CI pipeline happy 32 | buildPhase = "mkdir $out"; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /examples/packages/languages/haskell-local-development-cabal/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | dream2nix, 4 | lib, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.WIP-haskell-cabal 9 | ]; 10 | 11 | name = "my-test-project"; 12 | version = "1.0.0"; 13 | 14 | deps = {nixpkgs, ...}: { 15 | haskell-compiler = nixpkgs.haskell.compiler.ghc98; 16 | inherit (nixpkgs) zlib; 17 | }; 18 | 19 | mkDerivation = { 20 | src = lib.cleanSourceWith { 21 | src = lib.cleanSource ./.; 22 | filter = name: type: let 23 | baseName = baseNameOf (toString name); 24 | in 25 | !( 26 | lib.hasSuffix ".nix" baseName 27 | || lib.hasSuffix ".md" baseName 28 | ); 29 | }; 30 | 31 | buildInputs = [config.deps.zlib]; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /docs/src/v1-api/consuming/inspect-options.md: -------------------------------------------------------------------------------- 1 | # Inspect the API of a package 2 | Downstream users can inspect the api of any consumed package as well as raw package modules 3 | 4 | ## Load the dream2nix shell 5 | ```shell 6 | nix-shell https://dream2nix.dev -A devShells.default 7 | ``` 8 | 9 | ## Get manual of package module 10 | Assuming a package module in `./upstream/my-package.nix` 11 | 12 | ```shell 13 | $ dream2nix man ./upstream/my-package.nix 14 | ``` 15 | 16 | ## Get manual of derivation 17 | Assuming derivations defined via `./upstream/default.nix` 18 | 19 | ```shell 20 | dream2nix man ./upstream/default.nix -A packages.my-package 21 | ``` 22 | 23 | ## Get manual of flake attribute 24 | Assuming derivations defined via a flake on github 25 | 26 | ```shell 27 | dream2nix man github:user/repo#some-package 28 | ``` 29 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-packaging-package-lock/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.WIP-nodejs-builder-v3 9 | ]; 10 | 11 | mkDerivation = { 12 | src = builtins.fetchGit { 13 | shallow = true; 14 | url = "https://github.com/DavHau/cowsay"; 15 | ref = "package-lock-v3"; 16 | rev = "c89952cb75e3e54b8ca0033bd3499297610083c7"; 17 | }; 18 | }; 19 | 20 | deps = {nixpkgs, ...}: { 21 | inherit 22 | (nixpkgs) 23 | fetchFromGitHub 24 | stdenv 25 | ; 26 | }; 27 | 28 | WIP-nodejs-builder-v3 = { 29 | packageLockFile = "${config.mkDerivation.src}/package-lock.json"; 30 | }; 31 | 32 | name = "cowsay"; 33 | version = "1.5.0"; 34 | } 35 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-nextjs/nextjs-app/src/app/globals.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | :root { 6 | --foreground-rgb: 0, 0, 0; 7 | --background-start-rgb: 214, 219, 220; 8 | --background-end-rgb: 255, 255, 255; 9 | } 10 | 11 | @media (prefers-color-scheme: dark) { 12 | :root { 13 | --foreground-rgb: 255, 255, 255; 14 | --background-start-rgb: 0, 0, 0; 15 | --background-end-rgb: 0, 0, 0; 16 | } 17 | } 18 | 19 | body { 20 | color: rgb(var(--foreground-rgb)); 21 | background: linear-gradient( 22 | to bottom, 23 | transparent, 24 | rgb(var(--background-end-rgb)) 25 | ) 26 | rgb(var(--background-start-rgb)); 27 | } 28 | 29 | @layer utilities { 30 | .text-balance { 31 | text-wrap: balance; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-packaging/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.nodejs-package-lock-v3 9 | dream2nix.modules.dream2nix.nodejs-granular-v3 10 | ]; 11 | 12 | mkDerivation = { 13 | src = builtins.fetchGit { 14 | shallow = true; 15 | url = "https://github.com/DavHau/cowsay"; 16 | ref = "package-lock-v3"; 17 | rev = "c89952cb75e3e54b8ca0033bd3499297610083c7"; 18 | }; 19 | }; 20 | 21 | deps = {nixpkgs, ...}: { 22 | inherit 23 | (nixpkgs) 24 | fetchFromGitHub 25 | stdenv 26 | ; 27 | }; 28 | 29 | nodejs-package-lock-v3 = { 30 | packageLockFile = "${config.mkDerivation.src}/package-lock.json"; 31 | }; 32 | 33 | name = "cowsay"; 34 | version = "1.5.0"; 35 | } 36 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-nextjs/nextjs-app/src/app/globals.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | :root { 6 | --foreground-rgb: 0, 0, 0; 7 | --background-start-rgb: 214, 219, 220; 8 | --background-end-rgb: 255, 255, 255; 9 | } 10 | 11 | @media (prefers-color-scheme: dark) { 12 | :root { 13 | --foreground-rgb: 255, 255, 255; 14 | --background-start-rgb: 0, 0, 0; 15 | --background-end-rgb: 0, 0, 0; 16 | } 17 | } 18 | 19 | body { 20 | color: rgb(var(--foreground-rgb)); 21 | background: linear-gradient( 22 | to bottom, 23 | transparent, 24 | rgb(var(--background-end-rgb)) 25 | ) 26 | rgb(var(--background-start-rgb)); 27 | } 28 | 29 | @layer utilities { 30 | .text-balance { 31 | text-wrap: balance; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/internal/fetchers/archive/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | pkgs, 3 | lib, 4 | utils, 5 | ... 6 | }: { 7 | inputs = [ 8 | "url" 9 | ]; 10 | 11 | outputs = {url, ...}: let 12 | b = builtins; 13 | in { 14 | calcHash = algo: 15 | utils.hashFile algo (b.fetchTarball { 16 | inherit url; 17 | }); 18 | 19 | fetched = hash: let 20 | drv = 21 | if hash != null && lib.stringLength hash == 40 22 | then 23 | pkgs.fetchzip { 24 | inherit url; 25 | sha1 = hash; 26 | } 27 | else 28 | pkgs.fetchzip { 29 | inherit url hash; 30 | }; 31 | 32 | drvSanitized = drv.overrideAttrs (old: { 33 | name = lib.strings.sanitizeDerivationName old.name; 34 | }); 35 | in 36 | drvSanitized; 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-packaging-package-lock-v1/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.nodejs-package-lock 9 | dream2nix.modules.dream2nix.nodejs-granular 10 | ]; 11 | 12 | nodejs-package-lock = { 13 | source = config.deps.fetchFromGitHub { 14 | owner = "piuccio"; 15 | repo = "cowsay"; 16 | rev = "v1.5.0"; 17 | sha256 = "sha256-TZ3EQGzVptNqK3cNrkLnyP1FzBd81XaszVucEnmBy4Y="; 18 | }; 19 | }; 20 | 21 | deps = {nixpkgs, ...}: { 22 | inherit 23 | (nixpkgs) 24 | fetchFromGitHub 25 | stdenv 26 | ; 27 | }; 28 | 29 | name = "cowsay"; 30 | version = "1.5.0"; 31 | 32 | mkDerivation = { 33 | src = config.nodejs-package-lock.source; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /pkgs/fetchPipMetadata/flake-module.nix: -------------------------------------------------------------------------------- 1 | { 2 | perSystem = { 3 | self', 4 | pkgs, 5 | lib, 6 | ... 7 | }: let 8 | python3 = pkgs.python313; 9 | in { 10 | devShells.fetch-pip-metadata = let 11 | package = self'.packages.fetch-pip-metadata-package; 12 | pythonWithDeps = python3.withPackages ( 13 | ps: 14 | package.propagatedBuildInputs 15 | ++ [ 16 | ps.black 17 | ps.pytest 18 | ps.pytest-cov 19 | ] 20 | ); 21 | in 22 | pkgs.mkShell { 23 | packages = [ 24 | pythonWithDeps 25 | ]; 26 | }; 27 | 28 | packages.fetch-pip-metadata-package = import ./package.nix { 29 | inherit lib; 30 | inherit python3; 31 | inherit (pkgs) gitMinimal nix-prefetch-scripts; 32 | }; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /modules/dream2nix/core/tests/packages/nixpkgs/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | dream2nix, 3 | pkgs, 4 | config, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.mkDerivation-mixin 9 | dream2nix.modules.dream2nix.core 10 | ]; 11 | deps = {nixpkgs, ...}: { 12 | foo = nixpkgs.hello.overrideAttrs (old: { 13 | pname = "foo"; 14 | phases = ["buildPhase"]; 15 | buildPhase = "echo -n hello > $out"; 16 | }); 17 | }; 18 | name = "test"; 19 | version = "0.0.0"; 20 | phases = ["buildPhase"]; 21 | buildPhase = '' 22 | # explicit package 23 | echo ${pkgs.foo} >> $out 24 | # implicit package 25 | echo ${pkgs.hello} >> $out 26 | 27 | if [ "${pkgs.foo}" != "${config.deps.foo}" ]; then 28 | echo "foo mismatch: ${pkgs.foo} != ${config.deps.foo}" >&2 29 | exit 1 30 | fi 31 | ''; 32 | } 33 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-granular-v3/installPhase.nix: -------------------------------------------------------------------------------- 1 | { 2 | stdenv, 3 | # this function needs the following arguments via env 4 | # packageName, 5 | # nodeModules, 6 | }: '' 7 | echo "executing installPhaseNodejs" 8 | 9 | mkdir -p $out/lib 10 | cp -r $nodeModules $out/lib/node_modules 11 | nodeModules=$out/lib/node_modules 12 | cd "$nodeModules/$packageName" 13 | 14 | echo "Symlinking bin entries from package.json" 15 | python $linkBins 16 | 17 | echo "Symlinking manual pages" 18 | if [ -d "$nodeModules/$packageName/man" ] 19 | then 20 | mkdir -p $out/share 21 | for dir in "$nodeModules/$packageName/man/"* 22 | do 23 | mkdir -p $out/share/man/$(basename "$dir") 24 | for page in "$dir"/* 25 | do 26 | ln -s $page $out/share/man/$(basename "$dir") 27 | done 28 | done 29 | fi 30 | '' 31 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-granular/installPhase.nix: -------------------------------------------------------------------------------- 1 | { 2 | stdenv, 3 | # this function needs the following arguments via env 4 | # packageName, 5 | # nodeModules, 6 | }: '' 7 | echo "executing installPhaseNodejs" 8 | 9 | mkdir -p $out/lib 10 | cp -r $nodeModules $out/lib/node_modules 11 | nodeModules=$out/lib/node_modules 12 | cd "$nodeModules/$packageName" 13 | 14 | echo "Symlinking bin entries from package.json" 15 | python $linkBins 16 | 17 | echo "Symlinking manual pages" 18 | if [ -d "$nodeModules/$packageName/man" ] 19 | then 20 | mkdir -p $out/share 21 | for dir in "$nodeModules/$packageName/man/"* 22 | do 23 | mkdir -p $out/share/man/$(basename "$dir") 24 | for page in "$dir"/* 25 | do 26 | ln -s $page $out/share/man/$(basename "$dir") 27 | done 28 | done 29 | fi 30 | '' 31 | -------------------------------------------------------------------------------- /lib/internal/parseSpdxId.nix: -------------------------------------------------------------------------------- 1 | {lib, ...}: let 2 | l = builtins // lib; 3 | 4 | idToLicenseKey = 5 | l.mapAttrs' 6 | (n: v: l.nameValuePair (l.toLower (v.spdxId or v.fullName or n)) n) 7 | l.licenses; 8 | 9 | # Parses a string like "Unlicense OR MIT" to `["unlicense" "mit"]` 10 | # TODO: this does not parse `AND` or `WITH` or paranthesis, so it is 11 | # pretty hacky in how it works. But for most cases this should be okay. 12 | parseSpdxId = _id: let 13 | # some spdx ids might have paranthesis around them 14 | id = l.removePrefix "(" (l.removeSuffix ")" _id); 15 | licenseStrings = l.map l.toLower (l.splitString " OR " id); 16 | _licenses = l.map (string: idToLicenseKey.${string} or null) licenseStrings; 17 | licenses = l.filter (license: license != null) _licenses; 18 | in 19 | licenses; 20 | in 21 | parseSpdxId 22 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-node-modules/tests/packages/nodejs-packaging-node-modules-only/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.nodejs-node-modules 9 | dream2nix.modules.dream2nix.nodejs-package-lock 10 | ]; 11 | 12 | deps = {nixpkgs, ...}: { 13 | inherit 14 | (nixpkgs) 15 | fetchFromGitHub 16 | mkShell 17 | stdenv 18 | ; 19 | }; 20 | 21 | nodejs-package-lock = { 22 | source = config.deps.fetchFromGitHub { 23 | owner = "piuccio"; 24 | repo = "cowsay"; 25 | rev = "v1.5.0"; 26 | sha256 = "sha256-TZ3EQGzVptNqK3cNrkLnyP1FzBd81XaszVucEnmBy4Y="; 27 | }; 28 | }; 29 | 30 | name = "cowsay"; 31 | version = "1.5.0"; 32 | mkDerivation = { 33 | src = config.nodejs-package-lock.source; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /misc/benchmarks/benchmark.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eou pipefail 3 | 4 | export NUM_PKGS=${1:-100} 5 | export NUM_VARS=${2:-100} 6 | 7 | # measure date ini milliseconds 8 | echo -e "\nBenchmarking ${NUM_PKGS}x builtins.derivaton via pkg-funcs" 9 | time nix eval --impure -f ./builtins-derivation-modules-vs-pkg-func.nix --json pkg-funcs > /dev/null 10 | 11 | echo -e "\nBenchmarking ${NUM_PKGS}x builtins.derivaton via modules" 12 | time nix eval --impure -f ./builtins-derivation-modules-vs-pkg-func.nix --json modules > /dev/null 13 | 14 | echo -e "\nBenchmarking ${NUM_PKGS}x mkDerivation via pkg-funcs" 15 | time nix eval --impure -f ./mkDerivation-modules-vs-pkg-func.nix --json pkg-funcs > /dev/null 16 | 17 | echo -e "\nBenchmarking ${NUM_PKGS}x mkDerivation via modules" 18 | time nix eval --impure -f ./mkDerivation-modules-vs-pkg-func.nix --json modules > /dev/null 19 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-package-json/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: let 6 | l = lib // builtins; 7 | t = l.types; 8 | in { 9 | imports = [ 10 | ../nodejs-package-lock/interface.nix 11 | ]; 12 | options.nodejs-package-json = l.mapAttrs (_: l.mkOption) { 13 | source = { 14 | type = t.either t.path t.package; 15 | description = "Source of the package"; 16 | default = config.mkDerivation.src; 17 | defaultText = "config.mkDerivation.src"; 18 | }; 19 | npmArgs = { 20 | type = t.listOf t.str; 21 | description = "extra arguments to pass to 'npm install'"; 22 | default = []; 23 | }; 24 | }; 25 | options.deps = l.mapAttrs (_: l.mkOption) { 26 | npm = { 27 | type = t.package; 28 | description = "The npm package used to build the lock file"; 29 | }; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-package-json-v3/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: let 6 | l = lib // builtins; 7 | t = l.types; 8 | in { 9 | imports = [ 10 | ../nodejs-package-lock-v3/interface.nix 11 | ]; 12 | options.nodejs-package-json = l.mapAttrs (_: l.mkOption) { 13 | source = { 14 | type = t.either t.path t.package; 15 | description = "Source of the package"; 16 | default = config.mkDerivation.src; 17 | defaultText = "config.mkDerivation.src"; 18 | }; 19 | npmArgs = { 20 | type = t.listOf t.str; 21 | description = "extra arguments to pass to 'npm install'"; 22 | default = []; 23 | }; 24 | }; 25 | options.deps = l.mapAttrs (_: l.mkOption) { 26 | npm = { 27 | type = t.package; 28 | description = "The npm package used to build the lock file"; 29 | }; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /modules/dream2nix/core/public/optsPackage.nix: -------------------------------------------------------------------------------- 1 | # Represents a package interface as proposed in: 2 | # https://github.com/NixOS/nix/issues/6507 3 | {lib, ...}: let 4 | l = lib // builtins; 5 | t = l.types; 6 | in { 7 | name = l.mkOption { 8 | type = t.str; 9 | description = "The name of the package"; 10 | }; 11 | meta = l.mkOption { 12 | type = t.attrs; 13 | default = {}; 14 | description = "Extra attributes with meta information about the package"; 15 | }; 16 | outputs = l.mkOption { 17 | type = t.listOf t.str; 18 | description = ''A list of build outputs like "out" or "lib"''; 19 | }; 20 | tests = l.mkOption { 21 | type = t.attrs; 22 | default = {}; 23 | description = "A set of tests for the package"; 24 | }; 25 | version = l.mkOption { 26 | type = t.str; 27 | description = "The version of the package"; 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /modules/dream2nix/pip/pip-hotfixes/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: let 6 | l = lib // builtins; 7 | t = l.types; 8 | in { 9 | options.pip = { 10 | flattenDependencies = l.mkOption { 11 | type = t.bool; 12 | description = '' 13 | Use all dependencies as top-level dependencies, even transitive ones. 14 | 15 | Without this, we would walk the dependency tree from the root package upwards, 16 | adding only the necessary packages to each dependency. With this, it's flat. 17 | 18 | Useful if we are mostly interested in a working environment. 19 | ''; 20 | default = false; 21 | }; 22 | ignoredDependencies = l.mkOption { 23 | type = t.listOf t.str; 24 | description = '' 25 | list of dependencies to ignore 26 | ''; 27 | default = ["wheel"]; 28 | }; 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /lib/internal/fetchers/pypi-wheel/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | pkgs, 3 | utils, 4 | lib, 5 | ... 6 | }: { 7 | inputs = ["filename"]; 8 | 9 | versionField = "version"; 10 | 11 | defaultUpdater = "pypiNewestReleaseVersion"; 12 | 13 | outputs = { 14 | filename, 15 | pname, 16 | version, 17 | }: { 18 | fetched = hash: 19 | pkgs.runCommand 20 | filename 21 | { 22 | buildInputs = [ 23 | pkgs.curl 24 | pkgs.cacert 25 | pkgs.jq 26 | ]; 27 | outputHash = hash; 28 | outputHashAlgo = "sha256"; 29 | outputHashMode = "flat"; 30 | inherit filename pname version; 31 | } 32 | '' 33 | url=$(curl "https://pypi.org/pypi/$pname/json" | jq -r ".releases.\"$version\"[] | select(.filename == \"$filename\") | .url") 34 | curl $url --output $out 35 | ''; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /tests/nix-unit/test_python-pdm/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | pkgs ? import {}, 3 | lib ? import , 4 | dream2nix ? import ../../../. inputs, 5 | inputs ? (import ../../../.).inputs, 6 | }: let 7 | eval = module: 8 | (lib.evalModules { 9 | modules = [ 10 | dream2nix.modules.dream2nix.WIP-python-pdm 11 | module 12 | ]; 13 | specialArgs = { 14 | dream2nix = dream2nix // {inherit inputs;}; 15 | packageSets.nixpkgs = pkgs; 16 | }; 17 | }) 18 | .config; 19 | in { 20 | test_pdm = let 21 | config = eval { 22 | pdm.lockfile = ./../test_python-pdm-lib/fixtures/pdm-example1.lock; 23 | pdm.pyproject = ./../test_python-pdm-lib/fixtures/pyproject.toml; 24 | }; 25 | in { 26 | expr = (lib.head (lib.attrValues config.groups.default.packages.certifi)).public ? drvPath; 27 | expected = true; 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /lib/internal/fetchers/pypi-sdist/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | pkgs, 4 | mkDerivation, 5 | extractSource ? 6 | import ../extractSource.nix { 7 | inherit lib mkDerivation; 8 | }, 9 | ... 10 | }: { 11 | inputs = ["pname" "version"]; 12 | 13 | versionField = "version"; 14 | 15 | defaultUpdater = "pypiNewestReleaseVersion"; 16 | 17 | outputs = { 18 | pname, 19 | version, 20 | extension ? "tar.gz", 21 | }: let 22 | b = builtins; 23 | 24 | firstChar = builtins.substring 0 1 pname; 25 | url = 26 | "https://files.pythonhosted.org/packages/source/" 27 | + "${firstChar}/${pname}/${pname}-${version}.${extension}"; 28 | in { 29 | fetched = hash: let 30 | source = pkgs.fetchurl { 31 | inherit url; 32 | sha256 = hash; 33 | }; 34 | in 35 | extractSource { 36 | inherit source; 37 | }; 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /modules/dream2nix/core/paths/find-root.py: -------------------------------------------------------------------------------- 1 | #!@python3@/bin/python3 2 | 3 | # - identify the root by searching for the marker config.paths.projectRootFile in the current dir and parents 4 | # - if the marker file is not found, raise an error 5 | 6 | import os 7 | 8 | 9 | def find_root(): 10 | marker = "@projectRootFile@" 11 | path = os.getcwd() 12 | while True: 13 | if os.path.exists(os.path.join(path, marker)): 14 | return path 15 | newpath = os.path.dirname(path) 16 | if newpath == path: 17 | raise Exception( 18 | f"Could not find root directory (marker file: {marker})\n" 19 | "Ensure that paths.projectRoot and paths.projectRootFile are set correctly and you are working somewhere within the project directory." 20 | ) 21 | path = newpath 22 | 23 | 24 | if __name__ == "__main__": 25 | print(find_root()) 26 | -------------------------------------------------------------------------------- /modules/flake-parts/pre-commit-check.nix: -------------------------------------------------------------------------------- 1 | { 2 | self, 3 | lib, 4 | inputs, 5 | ... 6 | }: { 7 | perSystem = { 8 | config, 9 | self', 10 | inputs', 11 | pkgs, 12 | ... 13 | }: { 14 | checks = { 15 | pre-commit-check = inputs.pre-commit-hooks.lib.${pkgs.system}.run { 16 | src = ../../.; 17 | hooks = { 18 | treefmt = { 19 | enable = true; 20 | name = "treefmt"; 21 | pass_filenames = false; 22 | entry = toString (pkgs.writeScript "treefmt" '' 23 | #!${pkgs.bash}/bin/bash 24 | export PATH="$PATH:${lib.makeBinPath [ 25 | pkgs.alejandra 26 | pkgs.python3.pkgs.black 27 | ]}" 28 | ${pkgs.treefmt}/bin/treefmt --clear-cache --fail-on-change 29 | ''); 30 | }; 31 | }; 32 | }; 33 | }; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development-pdm/default.nix: -------------------------------------------------------------------------------- 1 | # An example package with dependencies defined via pyproject.toml 2 | { 3 | config, 4 | lib, 5 | dream2nix, 6 | ... 7 | }: { 8 | imports = [ 9 | dream2nix.modules.dream2nix.WIP-python-pdm 10 | ]; 11 | 12 | mkDerivation = { 13 | src = lib.cleanSourceWith { 14 | src = lib.cleanSource ./.; 15 | filter = name: type: 16 | !(builtins.any (x: x) [ 17 | (lib.hasSuffix ".nix" name) 18 | (lib.hasPrefix "." (builtins.baseNameOf name)) 19 | (lib.hasSuffix "flake.lock" name) 20 | ]); 21 | }; 22 | }; 23 | pdm.lockfile = ./pdm.lock; 24 | pdm.pyproject = ./pyproject.toml; 25 | 26 | # specify which pyproject.toml group to use (examples: default, extra, test) 27 | # pdm.group = "test"; 28 | 29 | buildPythonPackage = { 30 | pythonImportsCheck = [ 31 | "my_tool" 32 | ]; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /examples/packages/languages/rust-packaging-buildRustPackage/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.rust-cargo-lock 9 | dream2nix.modules.dream2nix.rust-cargo-vendor 10 | dream2nix.modules.dream2nix.buildRustPackage 11 | ]; 12 | 13 | deps = {nixpkgs, ...}: { 14 | inherit (nixpkgs) fetchFromGitHub; 15 | }; 16 | 17 | name = lib.mkForce "ripgrep"; 18 | version = lib.mkForce "13.0.0"; 19 | 20 | # options defined on top-level will be applied to the main derivation (the derivation that is exposed) 21 | mkDerivation = { 22 | # define the source root that contains the package we want to build. 23 | src = config.deps.fetchFromGitHub { 24 | owner = "BurntSushi"; 25 | repo = "ripgrep"; 26 | rev = config.version; 27 | sha256 = "sha256-udEh+Re2PeO3DnX4fQThsaT1Y3MBHFfrX5Q5EN2XrF0="; 28 | }; 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /modules/dream2nix/core/public/optsPackageDrvParts.nix: -------------------------------------------------------------------------------- 1 | # Adds drv-parts specific fields to the final derivation. 2 | {lib, ...}: let 3 | l = lib // builtins; 4 | t = l.types; 5 | in { 6 | config = l.mkOption { 7 | type = t.raw; 8 | readOnly = true; 9 | description = "The config of the evaluated modules which created the package"; 10 | }; 11 | extendModules = l.mkOption { 12 | type = t.raw; 13 | description = "Allows to modify the existing package by extending it with more modules"; 14 | }; 15 | 16 | # TODO: implement override functions for downward compatibility 17 | # overrideAttrs = l.mkOption { 18 | # type = t.path; 19 | # description = "Legacy machanism for modifying the package. Use `extendModules` instead"; 20 | # }; 21 | # override = l.mkOption { 22 | # type = t.str; 23 | # description = "Legacy machanism for modifying the package. Use `extendModules` instead"; 24 | # }; 25 | } 26 | -------------------------------------------------------------------------------- /lib/internal/getDreamLockSource.nix: -------------------------------------------------------------------------------- 1 | # This is currently only used for legacy modules ported to v1. 2 | # The dream-lock concept might be deprecated together with this module at some 3 | # point. 4 | {lib, ...}: let 5 | l = builtins // lib; 6 | 7 | getDreamLockSource = fetchedSources: pname: version: 8 | if 9 | fetchedSources 10 | ? "${pname}"."${version}" 11 | && fetchedSources."${pname}"."${version}" != "unknown" 12 | then fetchedSources."${pname}"."${version}" 13 | else 14 | throw '' 15 | The source for ${pname}#${version} is not defined. 16 | This can be fixed via an override. Example: 17 | ``` 18 | dream2nix.make[Flake]Outputs { 19 | ... 20 | sourceOverrides = oldSources: { 21 | "${pname}"."${version}" = builtins.fetchurl { ... }; 22 | }; 23 | ... 24 | } 25 | ``` 26 | ''; 27 | in 28 | getDreamLockSource 29 | -------------------------------------------------------------------------------- /.github/workflows/pages.yml: -------------------------------------------------------------------------------- 1 | name: github pages 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | 9 | jobs: 10 | deploy: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v5.0.1 14 | 15 | - name: Install nix 16 | uses: cachix/install-nix-action@3715ab1a11cac9e991980d7b4a28d80c7ebdd8f9 # v27 17 | with: 18 | extra_nix_config: | 19 | experimental-features = nix-command flakes 20 | nix_path: nixpkgs=channel:nixos-unstable 21 | 22 | - name: Build documentation book 23 | run: nix build -L --show-trace .#website 24 | 25 | - name: Deploy 26 | uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0 27 | if: ${{ github.ref == 'refs/heads/main' }} 28 | with: 29 | github_token: ${{ secrets.GITHUB_TOKEN }} 30 | publish_dir: ./result 31 | -------------------------------------------------------------------------------- /modules/dream2nix/pip/tests/packages/can-build-setuptools/default.nix: -------------------------------------------------------------------------------- 1 | # An example package with dependencies defined via pyproject.toml 2 | { 3 | config, 4 | lib, 5 | dream2nix, 6 | ... 7 | }: let 8 | pyproject = lib.importTOML (config.mkDerivation.src + /pyproject.toml); 9 | in { 10 | imports = [ 11 | dream2nix.modules.dream2nix.pip 12 | ]; 13 | 14 | deps = {nixpkgs, ...}: { 15 | python = nixpkgs.python310; 16 | }; 17 | 18 | inherit (pyproject.project) name version; 19 | 20 | mkDerivation = { 21 | src = ./.; 22 | propagatedBuildInputs = [ 23 | config.pip.drvs.setuptools.public 24 | ]; 25 | }; 26 | 27 | buildPythonPackage = { 28 | pyproject = true; 29 | pythonImportsCheck = [ 30 | "my_tool" 31 | ]; 32 | }; 33 | 34 | pip = { 35 | requirementsList = 36 | pyproject.build-system.requires 37 | or [] 38 | ++ pyproject.project.dependencies; 39 | flattenDependencies = true; 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /modules/dream2nix/rust-cargo-lock/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: let 6 | l = lib // builtins; 7 | t = l.types; 8 | in { 9 | options.rust-cargo-lock = l.mapAttrs (_: l.mkOption) { 10 | cargoLock = { 11 | type = t.path; 12 | internal = true; 13 | description = "The dreamlock that was generated as a Cargo.lock file"; 14 | }; 15 | dreamLock = { 16 | type = t.attrs; 17 | internal = true; 18 | description = "The content of the dream2nix generated lock file"; 19 | }; 20 | writeCargoLock = { 21 | type = t.str; 22 | internal = true; 23 | description = "Shell commands to backup original Cargo.lock and use dream2nix one in a rust derivation"; 24 | }; 25 | source = { 26 | type = t.either t.path t.package; 27 | description = "Source of the package"; 28 | default = config.mkDerivation.src; 29 | defaultText = "config.mkDerivation.src"; 30 | }; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-no-lock-file/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.nodejs-package-json-v3 9 | dream2nix.modules.dream2nix.nodejs-granular-v3 10 | ]; 11 | 12 | deps = {nixpkgs, ...}: { 13 | inherit 14 | (nixpkgs) 15 | gnugrep 16 | stdenv 17 | ; 18 | }; 19 | 20 | nodejs-granular-v3 = { 21 | buildScript = '' 22 | tsc ./app.ts 23 | mv app.js app.js.tmp 24 | echo "#!${config.deps.nodejs}/bin/node" > app.js 25 | cat app.js.tmp >> app.js 26 | chmod +x ./app.js 27 | patchShebangs . 28 | ''; 29 | }; 30 | 31 | name = lib.mkForce "app"; 32 | version = lib.mkForce "1.0.0"; 33 | 34 | mkDerivation = { 35 | src = lib.cleanSource ./.; 36 | checkPhase = '' 37 | ./app.js | ${config.deps.gnugrep}/bin/grep -q "Hello, World!" 38 | ''; 39 | doCheck = true; 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /modules/dream2nix/pip/tests/packages/can-handle-setuptools-runtime-dep/default.nix: -------------------------------------------------------------------------------- 1 | # An example package with dependencies defined via pyproject.toml 2 | { 3 | config, 4 | lib, 5 | dream2nix, 6 | ... 7 | }: let 8 | pyproject = lib.importTOML (config.mkDerivation.src + /pyproject.toml); 9 | in { 10 | imports = [ 11 | dream2nix.modules.dream2nix.pip 12 | ]; 13 | 14 | deps = {nixpkgs, ...}: { 15 | python = nixpkgs.python310; 16 | }; 17 | 18 | inherit (pyproject.project) name version; 19 | 20 | mkDerivation = { 21 | src = ./.; 22 | propagatedBuildInputs = [ 23 | config.pip.drvs.setuptools.public 24 | ]; 25 | }; 26 | 27 | buildPythonPackage = { 28 | pyproject = true; 29 | pythonImportsCheck = [ 30 | "my_tool" 31 | ]; 32 | }; 33 | 34 | pip = { 35 | requirementsList = 36 | pyproject.build-system.requires 37 | or [] 38 | ++ pyproject.project.dependencies; 39 | flattenDependencies = true; 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /modules/flake-parts/apps.update-caches.nix: -------------------------------------------------------------------------------- 1 | # custom app to update the eval-cache of each exported package. 2 | { 3 | self, 4 | lib, 5 | inputs, 6 | ... 7 | }: { 8 | perSystem = { 9 | config, 10 | self', 11 | inputs', 12 | pkgs, 13 | system, 14 | ... 15 | }: let 16 | l = lib // builtins; 17 | 18 | scripts = 19 | l.flatten 20 | (l.mapAttrsToList 21 | (name: pkg: pkg.config.eval-cache.refresh or []) 22 | self'.packages); 23 | 24 | update-caches = 25 | config.writers.writePureShellScript 26 | (with pkgs; [ 27 | coreutils 28 | git 29 | nix 30 | ]) 31 | ( 32 | "set -x\n" 33 | + (l.concatStringsSep "\n" scripts) 34 | ); 35 | 36 | toApp = script: { 37 | type = "app"; 38 | program = "${script}"; 39 | }; 40 | in { 41 | apps = l.mapAttrs (_: toApp) { 42 | inherit 43 | update-caches 44 | ; 45 | }; 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /scripts/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "My flake with dream2nix packages"; 3 | 4 | inputs = { 5 | dream2nix.url = "github:nix-community/dream2nix"; 6 | nixpkgs.follows = "dream2nix/nixpkgs"; 7 | }; 8 | 9 | outputs = inputs @ { 10 | self, 11 | dream2nix, 12 | nixpkgs, 13 | ... 14 | }: let 15 | system = "x86_64-linux"; 16 | in { 17 | # All packages defined in ./packages/ are automatically added to the flake outputs 18 | # e.g., 'packages/hello/default.nix' becomes '.#packages.hello' 19 | packages.${system}.default = dream2nix.lib.evalModules { 20 | packageSets.nixpkgs = inputs.dream2nix.inputs.nixpkgs.legacyPackages.${system}; 21 | modules = [ 22 | ./default.nix 23 | { 24 | paths.projectRoot = ./.; 25 | # can be changed to ".git" or "flake.nix" to get rid of .project-root 26 | paths.projectRootFile = "flake.nix"; 27 | paths.package = ./.; 28 | } 29 | ]; 30 | }; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /docs/src/v1-api/summary.md: -------------------------------------------------------------------------------- 1 | # dream2nix v1 API 2 | 3 | !!! This document does not resemble the current API of dream2nix. It is only a draft and the real implementation differs. More docs will follow. 4 | 5 | - [problems of the current dream2nix](../v1-api/problems.md) 6 | - [users of dream2nix](../v1-api/users.md) 7 | - v1 API examples: 8 | - package maintainers: 9 | - [project initialization](../v1-api/packaging/nodejs-init-project.md) 10 | - [workspaces](../v1-api/packaging/nodejs-workspaces.md) 11 | - [multiple repos](../v1-api/packaging/nodejs-multiple-repos.md) 12 | - [monorepo](../v1-api/packaging/monorepo.md) 13 | - consumers: 14 | - [inspect package options](../v1-api/consuming/inspect-options.md) 15 | - [override packages](../v1-api/consuming/override.md) 16 | - integration maintainers: 17 | - [integrate lang2nix tool (pure)](../v1-api/integrating/integrate-lang2nix-pure.md) 18 | - [integrate lang2nix tool (code-gen/impure)](../v1-api/integrating/integrate-lang2nix-impure.md) 19 | -------------------------------------------------------------------------------- /examples/packages/basics/mkDerivation/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | dream2nix, 4 | lib, 5 | ... 6 | }: { 7 | # select mkDerivation as a backend for this package 8 | imports = [ 9 | dream2nix.modules.dream2nix.mkDerivation 10 | dream2nix.modules.dream2nix.flags 11 | ]; 12 | 13 | deps = {nixpkgs, ...}: { 14 | inherit 15 | (nixpkgs) 16 | fetchurl 17 | stdenv 18 | ; 19 | }; 20 | 21 | flagsOffered = { 22 | enableFoo = "build with foo"; 23 | }; 24 | 25 | name = 26 | if config.flags.enableFoo 27 | then "hello-with-foo" 28 | else "hello"; 29 | 30 | version = "2.12.1"; 31 | 32 | env = lib.optionalAttrs config.deps.stdenv.hostPlatform.isDarwin { 33 | NIX_LDFLAGS = "-liconv"; 34 | }; 35 | 36 | mkDerivation = { 37 | src = config.deps.fetchurl { 38 | url = "mirror://gnu/hello/${config.name}-${config.version}.tar.gz"; 39 | sha256 = "sha256-jZkUKv2SV28wsM18tCqNxoCZmLxdYH2Idh9RLibH2yA="; 40 | }; 41 | doCheck = true; 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-granular/buildPhase.nix: -------------------------------------------------------------------------------- 1 | { 2 | jq, 3 | moreutils, 4 | }: '' 5 | echo "executing buildPhaseNodejs" 6 | 7 | # execute install command 8 | if [ -n "$buildScript" ]; then 9 | if [ -f "$buildScript" ]; then 10 | $buildScript 11 | else 12 | eval "$buildScript" 13 | fi 14 | 15 | # by default, only for top level packages, `npm run build` is executed 16 | elif [ -n "$runBuild" ] && [ "$(jq '.scripts.build' ./package.json)" != "null" ]; then 17 | npm run build 18 | 19 | else 20 | if [ "$(jq '.scripts.preinstall' ./package.json)" != "null" ]; then 21 | npm --production --offline --nodedir=$nodeSources run preinstall 22 | fi 23 | if [ "$(jq '.scripts.install' ./package.json)" != "null" ]; then 24 | npm --production --offline --nodedir=$nodeSources run install 25 | fi 26 | if [ "$(jq '.scripts.postinstall' ./package.json)" != "null" ]; then 27 | npm --production --offline --nodedir=$nodeSources run postinstall 28 | fi 29 | fi 30 | '' 31 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-granular-v3/buildPhase.nix: -------------------------------------------------------------------------------- 1 | { 2 | jq, 3 | moreutils, 4 | }: '' 5 | echo "executing buildPhaseNodejs" 6 | 7 | # execute install command 8 | if [ -n "$buildScript" ]; then 9 | if [ -f "$buildScript" ]; then 10 | $buildScript 11 | else 12 | eval "$buildScript" 13 | fi 14 | 15 | # by default, only for top level packages, `npm run build` is executed 16 | elif [ -n "$runBuild" ] && [ "$(jq '.scripts.build' ./package.json)" != "null" ]; then 17 | npm run build 18 | 19 | else 20 | if [ "$(jq '.scripts.preinstall' ./package.json)" != "null" ]; then 21 | npm --production --offline --nodedir=$nodeSources run preinstall 22 | fi 23 | if [ "$(jq '.scripts.install' ./package.json)" != "null" ]; then 24 | npm --production --offline --nodedir=$nodeSources run install 25 | fi 26 | if [ "$(jq '.scripts.postinstall' ./package.json)" != "null" ]; then 27 | npm --production --offline --nodedir=$nodeSources run postinstall 28 | fi 29 | fi 30 | '' 31 | -------------------------------------------------------------------------------- /lib/internal/fetchers/crates-io/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | runCommandLocal, 3 | fetchurl, 4 | hashFile, 5 | ... 6 | }: { 7 | inputs = ["pname" "version"]; 8 | 9 | versionField = "version"; 10 | 11 | outputs = { 12 | pname, 13 | version, 14 | ... 15 | }: let 16 | b = builtins; 17 | # See https://github.com/rust-lang/crates.io-index/blob/master/config.json#L2 18 | url = "https://crates.io/api/v1/crates/${pname}/${version}/download"; 19 | in { 20 | calcHash = algo: 21 | hashFile algo (b.fetchurl { 22 | inherit url; 23 | }); 24 | 25 | fetched = hash: let 26 | fetched = fetchurl { 27 | inherit url; 28 | sha256 = hash; 29 | name = "download-${pname}-${version}"; 30 | }; 31 | in 32 | runCommandLocal "unpack-${pname}-${version}" {} 33 | '' 34 | mkdir -p $out 35 | tar --strip-components 1 -xzf ${fetched} -C $out 36 | echo '{"package":"${hash}","files":{}}' > $out/.cargo-checksum.json 37 | ''; 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /lib/types/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | dream2nix, 4 | specialArgs, 5 | ... 6 | }: let 7 | t = lib.types; 8 | in rec { 9 | derivation = t.oneOf [t.str t.path t.package]; 10 | 11 | # A stricter submodule type that prevents derivations from being 12 | # detected as modules by accident. (derivations are attrs as well as modules) 13 | drvPart = let 14 | type = t.submoduleWith { 15 | modules = [dream2nix.modules.dream2nix.core]; 16 | inherit specialArgs; 17 | }; 18 | in 19 | type 20 | // { 21 | # Ensure that derivations are never detected as modules by accident. 22 | check = val: type.check val && (val.type or null != "derivation"); 23 | }; 24 | 25 | # polymorphic type, that can either represent a derivation or a drv-part. 26 | # The stricter`drvPart` type is needed to prevent derivations being 27 | # classified as modules by accident. 28 | # This is important because derivations cannot be merged with drv-parts. 29 | drvPartOrPackage = t.either derivation drvPart; 30 | } 31 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/modules/installed.nix: -------------------------------------------------------------------------------- 1 | { 2 | dream2nix, 3 | # _module.args 4 | plent, 5 | packageName, 6 | bins, 7 | nodejs, 8 | jq, 9 | dist, 10 | prepared-prod, 11 | ... 12 | }: { 13 | imports = [ 14 | dream2nix.modules.dream2nix.mkDerivation 15 | ]; 16 | config = { 17 | inherit (plent) version; 18 | name = packageName + "-installed"; 19 | env = { 20 | BINS = builtins.toJSON bins; 21 | }; 22 | mkDerivation = { 23 | src = dist; 24 | nativeBuildInputs = [jq]; 25 | buildInputs = [nodejs]; 26 | configurePhase = '' 27 | cp -r ${prepared-prod}/node_modules node_modules 28 | ''; 29 | installPhase = '' 30 | mkdir -p $out/lib/node_modules/${packageName} 31 | cp -r . $out/lib/node_modules/${packageName} 32 | 33 | mkdir -p $out/bin 34 | echo $BINS | jq 'to_entries | map("ln -s $out/lib/node_modules/${packageName}/\(.value) $out/bin/\(.key); ") | .[]' -r | bash 35 | ''; 36 | }; 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-no-lock-file/lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "package-lock": { 3 | "name": "app", 4 | "version": "1.0.0", 5 | "lockfileVersion": 3, 6 | "requires": true, 7 | "packages": { 8 | "": { 9 | "name": "app", 10 | "version": "1.0.0", 11 | "dependencies": { 12 | "typescript": "^5.1.6" 13 | }, 14 | "bin": { 15 | "app": "app.js" 16 | } 17 | }, 18 | "node_modules/typescript": { 19 | "version": "5.2.2", 20 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", 21 | "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", 22 | "bin": { 23 | "tsc": "bin/tsc", 24 | "tsserver": "bin/tsserver" 25 | }, 26 | "engines": { 27 | "node": ">=14.17" 28 | } 29 | } 30 | } 31 | }, 32 | "invalidationHash": "7ac1f84763ee2385dc2a63fded15a83bb6fb293244eed5c0ff65478fb32fb28a" 33 | } -------------------------------------------------------------------------------- /modules/dream2nix/php-granular/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | dream2nix, 4 | lib, 5 | specialArgs, 6 | ... 7 | }: let 8 | l = lib // builtins; 9 | t = l.types; 10 | cfg = config.php-granular; 11 | mkSubmodule = import ../../../lib/internal/mkSubmodule.nix {inherit lib specialArgs;}; 12 | in { 13 | options.php-granular = mkSubmodule { 14 | imports = [ 15 | ../overrides 16 | ]; 17 | config.overrideType = { 18 | imports = [ 19 | dream2nix.modules.dream2nix.mkDerivation 20 | ]; 21 | }; 22 | options = l.mapAttrs (_: l.mkOption) { 23 | deps = { 24 | internal = true; 25 | visible = "shallow"; 26 | type = t.lazyAttrsOf (t.lazyAttrsOf (t.submoduleWith { 27 | modules = [ 28 | dream2nix.modules.dream2nix.core 29 | cfg.overrideType 30 | ]; 31 | inherit specialArgs; 32 | })); 33 | }; 34 | composerInstallFlags = { 35 | type = t.listOf t.str; 36 | default = []; 37 | }; 38 | }; 39 | }; 40 | } 41 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-nextjs/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "My flake with dream2nix packages"; 3 | 4 | inputs = { 5 | dream2nix.url = "github:nix-community/dream2nix"; 6 | nixpkgs.follows = "dream2nix/nixpkgs"; 7 | }; 8 | 9 | outputs = inputs @ { 10 | self, 11 | dream2nix, 12 | nixpkgs, 13 | ... 14 | }: let 15 | system = "x86_64-linux"; 16 | in { 17 | # All packages defined in ./packages/ are automatically added to the flake outputs 18 | # e.g., 'packages/hello/default.nix' becomes '.#packages.hello' 19 | packages.${system}.default = dream2nix.lib.evalModules { 20 | packageSets.nixpkgs = inputs.dream2nix.inputs.nixpkgs.legacyPackages.${system}; 21 | modules = [ 22 | ./default.nix 23 | { 24 | paths.projectRoot = ./.; 25 | # can be changed to ".git" or "flake.nix" to get rid of .project-root 26 | paths.projectRootFile = "flake.nix"; 27 | paths.package = ./.; 28 | } 29 | ]; 30 | }; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /modules/dream2nix/python-pdm/tests/packages/python-local-development/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "My flake with dream2nix packages"; 3 | 4 | inputs = { 5 | dream2nix.url = "github:nix-community/dream2nix"; 6 | nixpkgs.follows = "dream2nix/nixpkgs"; 7 | }; 8 | 9 | outputs = inputs @ { 10 | self, 11 | dream2nix, 12 | nixpkgs, 13 | ... 14 | }: let 15 | system = "x86_64-linux"; 16 | in { 17 | # All packages defined in ./packages/ are automatically added to the flake outputs 18 | # e.g., 'packages/hello/default.nix' becomes '.#packages.hello' 19 | packages.${system}.default = dream2nix.lib.evalModules { 20 | packageSets.nixpkgs = inputs.dream2nix.inputs.nixpkgs.legacyPackages.${system}; 21 | modules = [ 22 | ./default.nix 23 | { 24 | paths.projectRoot = ./.; 25 | # can be changed to ".git" or "flake.nix" to get rid of .project-root 26 | paths.projectRootFile = "flake.nix"; 27 | paths.package = ./.; 28 | } 29 | ]; 30 | }; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /lib/internal/fetchers/http/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | utils ? null, 3 | fetchurl, 4 | lib, 5 | hashFile ? utils.hashFile, 6 | mkDerivation, 7 | extractSource ? 8 | import ../extractSource.nix { 9 | inherit lib mkDerivation; 10 | }, 11 | ... 12 | }: { 13 | inputs = [ 14 | "url" 15 | ]; 16 | 17 | outputs = {url, ...}: let 18 | b = builtins; 19 | in { 20 | calcHash = algo: 21 | hashFile algo (b.fetchurl { 22 | inherit url; 23 | }); 24 | 25 | fetched = hash: let 26 | drv = 27 | if hash != null && lib.stringLength hash == 40 28 | then 29 | fetchurl { 30 | inherit url; 31 | sha1 = hash; 32 | } 33 | else 34 | fetchurl { 35 | inherit url hash; 36 | }; 37 | 38 | drvSanitized = drv.overrideAttrs (old: { 39 | name = lib.strings.sanitizeDerivationName old.name; 40 | }); 41 | 42 | extracted = extractSource { 43 | source = drvSanitized; 44 | }; 45 | in 46 | extracted; 47 | }; 48 | } 49 | -------------------------------------------------------------------------------- /modules/dream2nix/rust-cargo-lock/findAllCrates.nix: -------------------------------------------------------------------------------- 1 | {lib, ...}: let 2 | discoverCrates = { 3 | tree, 4 | workspaceVersion, 5 | }: let 6 | cargoToml = tree.files."Cargo.toml".tomlContent or {}; 7 | 8 | subdirCrates = 9 | lib.flatten 10 | (lib.mapAttrsToList 11 | (dirName: dir: 12 | discoverCrates { 13 | inherit workspaceVersion; 14 | tree = dir; 15 | }) 16 | (tree.directories or {})); 17 | in 18 | if cargoToml ? package.name 19 | then 20 | [ 21 | { 22 | inherit (cargoToml.package) name; 23 | inherit (tree) relPath; 24 | 25 | version = 26 | if cargoToml.package.version.workspace or false 27 | then workspaceVersion 28 | else cargoToml.package.version; 29 | } 30 | ] 31 | ++ subdirCrates 32 | else subdirCrates; 33 | in 34 | {tree}: 35 | discoverCrates { 36 | inherit tree; 37 | workspaceVersion = tree.files."Cargo.toml".tomlContent.workspace.package.version or null; 38 | } 39 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-packaging-package-lock-v1/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "My flake with dream2nix packages"; 3 | 4 | inputs = { 5 | dream2nix.url = "github:nix-community/dream2nix"; 6 | nixpkgs.follows = "dream2nix/nixpkgs"; 7 | }; 8 | 9 | outputs = inputs @ { 10 | self, 11 | dream2nix, 12 | nixpkgs, 13 | ... 14 | }: let 15 | system = "x86_64-linux"; 16 | in { 17 | # All packages defined in ./packages/ are automatically added to the flake outputs 18 | # e.g., 'packages/hello/default.nix' becomes '.#packages.hello' 19 | packages.${system}.default = dream2nix.lib.evalModules { 20 | packageSets.nixpkgs = inputs.dream2nix.inputs.nixpkgs.legacyPackages.${system}; 21 | modules = [ 22 | ./default.nix 23 | { 24 | paths.projectRoot = ./.; 25 | # can be changed to ".git" or "flake.nix" to get rid of .project-root 26 | paths.projectRootFile = "flake.nix"; 27 | paths.package = ./.; 28 | } 29 | ]; 30 | }; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-packaging-package-lock/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "My flake with dream2nix packages"; 3 | 4 | inputs = { 5 | dream2nix.url = "github:nix-community/dream2nix"; 6 | nixpkgs.follows = "dream2nix/nixpkgs"; 7 | }; 8 | 9 | outputs = inputs @ { 10 | self, 11 | dream2nix, 12 | nixpkgs, 13 | ... 14 | }: let 15 | system = "x86_64-linux"; 16 | in { 17 | # All packages defined in ./packages/ are automatically added to the flake outputs 18 | # e.g., 'packages/hello/default.nix' becomes '.#packages.hello' 19 | packages.${system}.default = dream2nix.lib.evalModules { 20 | packageSets.nixpkgs = inputs.dream2nix.inputs.nixpkgs.legacyPackages.${system}; 21 | modules = [ 22 | ./default.nix 23 | { 24 | paths.projectRoot = ./.; 25 | # can be changed to ".git" or "flake.nix" to get rid of .project-root 26 | paths.projectRootFile = "flake.nix"; 27 | paths.package = ./.; 28 | } 29 | ]; 30 | }; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-node-modules/tests/packages/nodejs-packaging-node-modules-only/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "My flake with dream2nix packages"; 3 | 4 | inputs = { 5 | dream2nix.url = "github:nix-community/dream2nix"; 6 | nixpkgs.follows = "dream2nix/nixpkgs"; 7 | }; 8 | 9 | outputs = inputs @ { 10 | self, 11 | dream2nix, 12 | nixpkgs, 13 | ... 14 | }: let 15 | system = "x86_64-linux"; 16 | in { 17 | # All packages defined in ./packages/ are automatically added to the flake outputs 18 | # e.g., 'packages/hello/default.nix' becomes '.#packages.hello' 19 | packages.${system}.default = dream2nix.lib.evalModules { 20 | packageSets.nixpkgs = inputs.dream2nix.inputs.nixpkgs.legacyPackages.${system}; 21 | modules = [ 22 | ./default.nix 23 | { 24 | paths.projectRoot = ./.; 25 | # can be changed to ".git" or "flake.nix" to get rid of .project-root 26 | paths.projectRootFile = "flake.nix"; 27 | paths.package = ./.; 28 | } 29 | ]; 30 | }; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /modules/dream2nix/pip/tests/packages/python-nodejs/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "My flake with dream2nix packages"; 3 | 4 | inputs = { 5 | dream2nix.url = "github:nix-community/dream2nix"; 6 | nixpkgs.follows = "dream2nix/nixpkgs"; 7 | }; 8 | 9 | outputs = inputs @ { 10 | self, 11 | dream2nix, 12 | nixpkgs, 13 | ... 14 | }: let 15 | # A helper that helps us define the attributes below for 16 | # all systems we care about. 17 | eachSystem = nixpkgs.lib.genAttrs [ 18 | "x86_64-linux" 19 | ]; 20 | in { 21 | packages = eachSystem (system: { 22 | default = dream2nix.lib.evalModules { 23 | packageSets.nixpkgs = inputs.dream2nix.inputs.nixpkgs.legacyPackages.${system}; 24 | modules = [ 25 | ./default.nix 26 | { 27 | paths.projectRoot = ./.; 28 | # can be changed to ".git" or "flake.nix" to get rid of .project-root 29 | paths.projectRootFile = "flake.nix"; 30 | paths.package = ./.; 31 | } 32 | ]; 33 | }; 34 | }); 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /modules/dream2nix/core/public/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: let 6 | l = lib // builtins; 7 | t = l.types; 8 | 9 | opts = let 10 | optsPackage = import ./optsPackage.nix { 11 | inherit lib; 12 | inherit (config) outputs; 13 | }; 14 | optsPackageCompat = import ./optsPackageCompat.nix {inherit lib;}; 15 | optsPackageDrvParts = import ./optsPackageDrvParts.nix {inherit lib;}; 16 | in 17 | optsPackage // optsPackageCompat // optsPackageDrvParts; 18 | 19 | opts' = l.flip l.mapAttrs opts (name: opt: opt // {internal = true;}); 20 | in { 21 | # this will contain the resulting derivation 22 | options.public = l.mkOption { 23 | type = t.submodule { 24 | freeformType = t.lazyAttrsOf t.anything; 25 | options = opts'; 26 | }; 27 | description = '' 28 | The final result of the evaluated package. 29 | Contains everything that nix expects from a derivation. 30 | Contains fields like name, outputs, drvPath, outPath, etc. 31 | Can be build with nix-build or `nix build`. 32 | ''; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /modules/dream2nix/pip/tests/packages/can-build-setuptools/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "My flake with dream2nix packages"; 3 | 4 | inputs = { 5 | dream2nix.url = "github:nix-community/dream2nix"; 6 | nixpkgs.follows = "dream2nix/nixpkgs"; 7 | }; 8 | 9 | outputs = inputs @ { 10 | self, 11 | dream2nix, 12 | nixpkgs, 13 | ... 14 | }: let 15 | # A helper that helps us define the attributes below for 16 | # all systems we care about. 17 | eachSystem = nixpkgs.lib.genAttrs [ 18 | "x86_64-linux" 19 | ]; 20 | in { 21 | packages = eachSystem (system: { 22 | default = dream2nix.lib.evalModules { 23 | packageSets.nixpkgs = inputs.dream2nix.inputs.nixpkgs.legacyPackages.${system}; 24 | modules = [ 25 | ./default.nix 26 | { 27 | paths.projectRoot = ./.; 28 | # can be changed to ".git" or "flake.nix" to get rid of .project-root 29 | paths.projectRootFile = "flake.nix"; 30 | paths.package = ./.; 31 | } 32 | ]; 33 | }; 34 | }); 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /modules/dream2nix/core/paths/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: { 6 | imports = [ 7 | ./interface.nix 8 | ../deps 9 | ]; 10 | deps = {nixpkgs, ...}: 11 | lib.mapAttrs (_: opt: lib.mkOverride 1003 opt) { 12 | python3 = nixpkgs.python3; 13 | replaceVarsWith = nixpkgs.replaceVarsWith; 14 | }; 15 | paths = { 16 | lockFileAbs = 17 | config.paths.projectRoot + "/${config.paths.package}/${config.paths.lockFile}"; 18 | cacheFileAbs = 19 | config.paths.projectRoot + "/${config.paths.package}/${config.paths.cacheFile}"; 20 | 21 | # - identify the root by searching for the marker config.paths.projectRootFile in the current dir and parents 22 | # - if the marker file is not found, raise an error 23 | findRoot = let 24 | program = config.deps.replaceVarsWith { 25 | replacements = { 26 | projectRootFile = config.paths.projectRootFile; 27 | python3 = config.deps.python3; 28 | }; 29 | isExecutable = true; 30 | src = ./find-root.py; 31 | }; 32 | in "${program}"; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /modules/dream2nix/pip/tests/packages/can-handle-setuptools-runtime-dep/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "My flake with dream2nix packages"; 3 | 4 | inputs = { 5 | dream2nix.url = "github:nix-community/dream2nix"; 6 | nixpkgs.follows = "dream2nix/nixpkgs"; 7 | }; 8 | 9 | outputs = inputs @ { 10 | self, 11 | dream2nix, 12 | nixpkgs, 13 | ... 14 | }: let 15 | # A helper that helps us define the attributes below for 16 | # all systems we care about. 17 | eachSystem = nixpkgs.lib.genAttrs [ 18 | "x86_64-linux" 19 | ]; 20 | in { 21 | packages = eachSystem (system: { 22 | default = dream2nix.lib.evalModules { 23 | packageSets.nixpkgs = inputs.dream2nix.inputs.nixpkgs.legacyPackages.${system}; 24 | modules = [ 25 | ./default.nix 26 | { 27 | paths.projectRoot = ./.; 28 | # can be changed to ".git" or "flake.nix" to get rid of .project-root 29 | paths.projectRootFile = "flake.nix"; 30 | paths.package = ./.; 31 | } 32 | ]; 33 | }; 34 | }); 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /pkgs/fetchPipMetadata/src/tests/test_evaluate_extras.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from packaging.requirements import Requirement 3 | 4 | import lock_file_from_report as l 5 | 6 | 7 | @pytest.fixture 8 | def env(): 9 | return dict(python_version="3.10") 10 | 11 | 12 | def test_marker_match(env): 13 | env = dict(python_version="3.10") 14 | requirement = Requirement("requests; python_version == '3.10'") 15 | assert l.evaluate_extras(requirement, None, env) == True 16 | 17 | 18 | def test_marker_mismatch(env): 19 | env = dict(python_version="3.10") 20 | requirement = Requirement("requests; python_version == '3.11'") 21 | assert l.evaluate_extras(requirement, None, env) == False 22 | 23 | 24 | def test_marker_extra_match(env): 25 | requirement = Requirement("requests; extra == 'security'") 26 | extras = ["security"] 27 | assert l.evaluate_extras(requirement, extras, {}) == True 28 | 29 | 30 | def test_marker_extra_mismatch(env): 31 | requirement = Requirement("requests; extra == 'security'") 32 | extras = [] 33 | assert l.evaluate_extras(requirement, extras, {}) == False 34 | -------------------------------------------------------------------------------- /examples/packages/languages/python-packaging-pillow/default.nix: -------------------------------------------------------------------------------- 1 | # Build Pillow from source, without a wheel, and rather 2 | # minimal features - only zlib and libjpeg as dependencies. 3 | { 4 | config, 5 | lib, 6 | dream2nix, 7 | ... 8 | }: { 9 | imports = [ 10 | dream2nix.modules.dream2nix.pip 11 | ]; 12 | 13 | deps = {nixpkgs, ...}: { 14 | python = nixpkgs.python313; 15 | inherit 16 | (nixpkgs) 17 | pkg-config 18 | zlib 19 | libjpeg 20 | ; 21 | }; 22 | 23 | name = "pillow"; 24 | version = "10.4.0"; 25 | 26 | mkDerivation = { 27 | nativeBuildInputs = [ 28 | config.deps.pkg-config 29 | ]; 30 | propagatedBuildInputs = [ 31 | config.deps.zlib 32 | config.deps.libjpeg 33 | ]; 34 | }; 35 | 36 | buildPythonPackage = { 37 | pythonImportsCheck = [ 38 | "PIL" 39 | ]; 40 | }; 41 | 42 | paths.lockFile = "lock.${config.deps.stdenv.system}.json"; 43 | pip = { 44 | requirementsList = ["${config.name}==${config.version}"]; 45 | pipFlags = [ 46 | "--no-binary" 47 | ":all:" 48 | ]; 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /modules/dream2nix/python-pdm/tests/packages/jupyter-lab/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "My flake with dream2nix packages"; 3 | 4 | inputs = { 5 | dream2nix.url = "github:nix-community/dream2nix"; 6 | nixpkgs.follows = "dream2nix/nixpkgs"; 7 | }; 8 | 9 | outputs = inputs @ { 10 | self, 11 | dream2nix, 12 | nixpkgs, 13 | ... 14 | }: let 15 | system = "x86_64-linux"; 16 | in { 17 | # All packages defined in ./packages/ are automatically added to the flake outputs 18 | # e.g., 'packages/hello/default.nix' becomes '.#packages.hello' 19 | packages.${system}.default = dream2nix.lib.evalModules { 20 | packageSets.nixpkgs = inputs.dream2nix.inputs.nixpkgs.legacyPackages.${system}; 21 | modules = [ 22 | ./default.nix 23 | { 24 | paths.projectRoot = ./.; 25 | # can be changed to ".git" or "flake.nix" to get rid of .project-root 26 | paths.projectRootFile = "flake.nix"; 27 | paths.package = ./.; 28 | } 29 | ]; 30 | }; 31 | devShell.${system} = self.packages.${system}.default.devShell; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /examples/packages/languages/python-local-development-multiple-packages/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | dream2nix, 5 | ... 6 | }: let 7 | pyproject = lib.importTOML ./subpkg1/pyproject.toml; 8 | buildWithSetuptools = { 9 | buildPythonPackage.pyproject = true; 10 | mkDerivation.buildInputs = [config.deps.python.pkgs.setuptools]; 11 | }; 12 | in { 13 | imports = [ 14 | dream2nix.modules.dream2nix.pip 15 | buildWithSetuptools 16 | ]; 17 | 18 | deps = {nixpkgs, ...}: { 19 | python = nixpkgs.python310; 20 | }; 21 | 22 | inherit (pyproject.project) name version; 23 | 24 | mkDerivation.src = lib.concatStringsSep "/" [ 25 | config.paths.projectRoot 26 | config.paths.package 27 | "subpkg1" 28 | ]; 29 | 30 | buildPythonPackage.pythonImportsCheck = [ 31 | "subpkg1" 32 | "subpkg2" 33 | ]; 34 | 35 | paths.lockFile = "lock.${config.deps.stdenv.system}.json"; 36 | pip = { 37 | requirementsList = [ 38 | "${config.paths.package}/subpkg1" 39 | "${config.paths.package}/subpkg2" 40 | ]; 41 | overrides.subpkg2 = buildWithSetuptools; 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /modules/dream2nix/pip/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "pip" 3 | state: released 4 | maintainers: 5 | - phaer 6 | --- 7 | 8 | A module to package python projects via [pip](https://pip.pypa.io/). 9 | 10 | Under the hood, it uses [./pkgs/fetchPipMetadata](https://github.com/nix-community/dream2nix/tree/main/pkgs/fetchPipMetadata) to 11 | run `pip install --dry-run --report [...]` with reproducible inputs and converts the resulting installation report into a dream2nix 12 | lock file. 13 | 14 | !!! note 15 | 16 | Due to limitations in `pip`s cross-platform support, the resulting 17 | lock-files are platform-specific! 18 | We therefore recommend setting `paths.lockFile` to `lock.${system}.json` 19 | for all projects where you use the pip module. 20 | 21 | Check out the [pdm module](../WIP-python-pdm/index.md) if you need a solution that 22 | allows locking for multiple platforms at once! 23 | 24 | During building, it uses this lock file to build each dependency as well as the top-level package in separate derivations 25 | while allowing overrides and further customization via [dream2nix module system](../../modules.md). 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 DavHau 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /modules/dream2nix/core/assertions.nix: -------------------------------------------------------------------------------- 1 | {lib, ...}: 2 | with lib; { 3 | options = { 4 | assertions = mkOption { 5 | type = types.listOf types.unspecified; 6 | internal = true; 7 | default = []; 8 | example = [ 9 | { 10 | assertion = false; 11 | message = "you can't enable this for that reason"; 12 | } 13 | ]; 14 | description = lib.mdDoc '' 15 | This option allows modules to express conditions that must 16 | hold for the evaluation of the system configuration to 17 | succeed, along with associated error messages for the user. 18 | ''; 19 | }; 20 | 21 | warnings = mkOption { 22 | internal = true; 23 | default = []; 24 | type = types.listOf types.str; 25 | example = ["The `foo' service is deprecated and will go away soon!"]; 26 | description = lib.mdDoc '' 27 | This option allows modules to show warnings to users during 28 | the evaluation of the system configuration. 29 | ''; 30 | }; 31 | }; 32 | # impl of assertions is in 33 | } 34 | -------------------------------------------------------------------------------- /examples/packages/README.md: -------------------------------------------------------------------------------- 1 | # package examples 2 | 3 | This directory contains examples for modules defining packages. 4 | All modules can be used as templates to create new packages. 5 | 6 | Each package module is defined by a directory containing a `default.nix`. 7 | 8 | ## How to use 9 | 10 | All examples are self contained via their own `flake.nix`. 11 | 12 | To use multiple packages in a repository, keep only each packages' `default.nix` and put them under a top-level `flake.nix` instead, as shown in the `repo examples` in [/examples](../../examples). 13 | 14 | ## Usage example 15 | 16 | For example, in order to initialize a php-package from `packages/languages/php-packaging/`: 17 | 18 | ```shellSession 19 | # create new single package repo for php 20 | $ mkdir my-dream2nix-package 21 | $ cd my-dream2nix-package 22 | $ nix flake init -t github:nix-community/dream2nix#templates.php-packaging 23 | wrote: /tmp/my-dream2nix-package/flake.nix 24 | wrote: /tmp/my-dream2nix-package/default.nix 25 | 26 | # git add (in case git is used) 27 | git add . 28 | 29 | # interact with the package 30 | $ nix flake show 31 | [...] 32 | $ nix build 33 | [...] 34 | ``` 35 | -------------------------------------------------------------------------------- /modules/flake-parts/core-modules.nix: -------------------------------------------------------------------------------- 1 | # Automatically exports modules from the `/**/modules` directory to: 2 | # `flake.modules..` 3 | # Automatically imports all flake-parts modules from `/**/modules/flake-parts` 4 | { 5 | config, 6 | lib, 7 | self, 8 | ... 9 | }: let 10 | # inherit all lib functions used below 11 | inherit 12 | (builtins) 13 | readDir 14 | ; 15 | inherit 16 | (lib) 17 | filterAttrs 18 | hasSuffix 19 | mapAttrs' 20 | nameValuePair 21 | removeSuffix 22 | ; 23 | 24 | path = ../dream2nix/core; 25 | 26 | isModule = fname: type: 27 | (fname != "default.nix") 28 | && (fname != "test") 29 | && (fname != "tests") 30 | && (fname != "_template") 31 | && ( 32 | (type == "regular" && hasSuffix ".nix" fname) || type == "directory" 33 | ); 34 | 35 | modules = 36 | mapAttrs' 37 | (fn: _: 38 | nameValuePair 39 | (removeSuffix ".nix" fn) 40 | (path + "/${fn}")) 41 | (filterAttrs isModule (readDir path)); 42 | in { 43 | # generates future flake outputs: `modules..` 44 | config.flake.modules.dream2nix = modules; 45 | } 46 | -------------------------------------------------------------------------------- /modules/flake-parts/website-options.nix: -------------------------------------------------------------------------------- 1 | {self, ...}: { 2 | perSystem = { 3 | pkgs, 4 | inputs', 5 | lib, 6 | ... 7 | }: let 8 | inherit 9 | (lib) 10 | elem 11 | filterAttrs 12 | mapAttrsToList 13 | hasPrefix 14 | ; 15 | isWip = hasPrefix "WIP-"; 16 | doRender = name: ! elem name ignore; 17 | wipModules = filterAttrs (name: _: isWip name && doRender name) self.modules.dream2nix; 18 | normalModules = filterAttrs (name: _: ! isWip name && doRender name) self.modules.dream2nix; 19 | ignore = [ 20 | "assertions" 21 | ]; 22 | mkScope = name: module: { 23 | inherit name; 24 | modules = [module]; 25 | urlPrefix = "https://github.com/nix-community/dream2nix/blob/main/"; 26 | specialArgs = { 27 | dream2nix.modules = self.modules; 28 | }; 29 | }; 30 | in { 31 | packages.website-options = inputs'.nuschtos.packages.mkMultiSearch { 32 | baseHref = "/options/"; 33 | title = "dream2nix modules"; 34 | scopes = 35 | mapAttrsToList mkScope normalModules 36 | ++ mapAttrsToList mkScope wipModules; 37 | }; 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-devshell/tests/packages/basic/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "app", 9 | "version": "1.0.0", 10 | "dependencies": { 11 | "typescript": "^5.1.6" 12 | }, 13 | "bin": { 14 | "app": "app.js" 15 | } 16 | }, 17 | "node_modules/typescript": { 18 | "version": "5.2.2", 19 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", 20 | "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", 21 | "bin": { 22 | "tsc": "bin/tsc", 23 | "tsserver": "bin/tsserver" 24 | }, 25 | "engines": { 26 | "node": ">=14.17" 27 | } 28 | } 29 | }, 30 | "dependencies": { 31 | "typescript": { 32 | "version": "5.2.2", 33 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", 34 | "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==" 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-node-modules/tests/packages/basic/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "app", 9 | "version": "1.0.0", 10 | "dependencies": { 11 | "typescript": "^5.1.6" 12 | }, 13 | "bin": { 14 | "app": "app.js" 15 | } 16 | }, 17 | "node_modules/typescript": { 18 | "version": "5.2.2", 19 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", 20 | "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", 21 | "bin": { 22 | "tsc": "bin/tsc", 23 | "tsserver": "bin/tsserver" 24 | }, 25 | "engines": { 26 | "node": ">=14.17" 27 | } 28 | } 29 | }, 30 | "dependencies": { 31 | "typescript": { 32 | "version": "5.2.2", 33 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", 34 | "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==" 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/internal/nodejsLockUtils.nix: -------------------------------------------------------------------------------- 1 | {lib, ...}: let 2 | # path = node_modules/@org/lib/node_modules/bar 3 | parentPath = path: let 4 | # noPackages = lib.removePrefix "packages/" path; 5 | packages = lib.splitString "node_modules/" path; # = [ "@org/lib" "bar" ] 6 | nextPath = lib.concatStringsSep "node_modules/" (lib.init packages); 7 | in 8 | lib.removeSuffix "/" ( 9 | if path == nextPath 10 | then "" 11 | else nextPath 12 | ); 13 | 14 | findEntry = 15 | # = "attrs" 16 | packageLock: 17 | # = "my-package/node_modules/@foo/bar" 18 | currentPath: 19 | # = "kitty" 20 | search: let 21 | searchPath = lib.removePrefix "/" "${currentPath}/node_modules/${search}"; # = "my-package/node_modules/@foo/bar/node_modules/kitty" 22 | in 23 | if packageLock.packages ? ${searchPath} 24 | then 25 | # attribute found in plock 26 | searchPath 27 | else if currentPath == "" 28 | then throw "${search} not found in package-lock.json." 29 | # if the package cannot be found as a sub-dependency, check the parent 30 | else findEntry packageLock (parentPath currentPath) search; 31 | in { 32 | inherit findEntry parentPath; 33 | } 34 | -------------------------------------------------------------------------------- /pkgs/fetchPipMetadata/src/tests/test_lock_info_from_fod.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import lock_file_from_report as l 3 | 4 | 5 | @pytest.fixture 6 | def store_path(): 7 | return "blablub" 8 | 9 | 10 | @pytest.fixture 11 | def drv_json(store_path): 12 | return dict( 13 | env=dict( 14 | urls="https://example.com", 15 | ), 16 | outputs=dict( 17 | out=dict( 18 | hash="xxx", 19 | hashAlgo="r:sha256", 20 | path=store_path, 21 | ) 22 | ), 23 | ) 24 | 25 | 26 | def test_mismatching_store_path(drv_json): 27 | with pytest.raises(AssertionError): 28 | store_path = "" 29 | l.lock_info_from_fod(store_path, drv_json) 30 | 31 | 32 | def test_matching_store_path(store_path, drv_json): 33 | l.lock_info_from_fod(store_path, drv_json) 34 | 35 | 36 | def test_no_fod(store_path, drv_json): 37 | drv_json["env"]["urls"] = "" 38 | drv_json["outputs"]["out"]["hash"] = "" 39 | with pytest.raises(Exception): 40 | l.lock_info_from_fod(store_path, drv_json) 41 | 42 | 43 | def test_invalid_drv(store_path): 44 | with pytest.raises(AssertionError): 45 | l.lock_info_from_fod(store_path, {}) 46 | -------------------------------------------------------------------------------- /examples/packages/languages/rust-packaging/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.rust-cargo-lock 9 | dream2nix.modules.dream2nix.rust-cargo-vendor 10 | dream2nix.modules.dream2nix.rust-crane 11 | ]; 12 | 13 | deps = {nixpkgs, ...}: { 14 | inherit (nixpkgs) fetchFromGitHub iconv; 15 | }; 16 | 17 | name = lib.mkForce "ripgrep"; 18 | version = lib.mkForce "13.0.0"; 19 | 20 | # options defined on top-level will be applied to the main derivation (the derivation that is exposed) 21 | mkDerivation = { 22 | # define the source root that contains the package we want to build. 23 | src = config.deps.fetchFromGitHub { 24 | owner = "BurntSushi"; 25 | repo = "ripgrep"; 26 | rev = config.version; 27 | sha256 = "sha256-udEh+Re2PeO3DnX4fQThsaT1Y3MBHFfrX5Q5EN2XrF0="; 28 | }; 29 | buildInputs = lib.optionals config.deps.stdenv.isDarwin [config.deps.iconv]; 30 | }; 31 | 32 | rust-crane = { 33 | buildProfile = "dev"; 34 | buildFlags = ["--verbose"]; 35 | runTests = false; 36 | depsDrv = { 37 | # options defined here will be applied to the dependencies derivation 38 | }; 39 | }; 40 | } 41 | -------------------------------------------------------------------------------- /modules/dream2nix/rust-cargo-vendor/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: let 6 | l = lib // builtins; 7 | t = l.types; 8 | in { 9 | options.rust-cargo-vendor = l.mapAttrs (_: l.mkOption) { 10 | vendoredSources = { 11 | type = t.package; 12 | description = "Path to vendored sources"; 13 | }; 14 | copyVendorDir = { 15 | type = t.functionTo (t.functionTo t.str); 16 | internal = true; 17 | description = "Makes shell command(s) that copies the vendored sources correctly in a rust derivation"; 18 | }; 19 | getRootSource = { 20 | type = t.functionTo (t.functionTo t.path); 21 | internal = true; 22 | description = "Gets root source for a given package"; 23 | }; 24 | writeGitVendorEntries = { 25 | type = t.functionTo t.str; 26 | internal = true; 27 | description = "Makes shell command(s) that writes vendored git sources to .cargo/config so cargo uses the sources we vendored"; 28 | }; 29 | replaceRelativePathsWithAbsolute = { 30 | type = t.functionTo t.str; 31 | internal = true; 32 | description = "Makes shell commands that will replace relative dependency paths with absolute paths in Cargo.toml"; 33 | }; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /docs/theme/reference_options.html: -------------------------------------------------------------------------------- 1 | ## Options 2 | {%- for name, option in options.items() recursive %} 3 | 4 | ##{{"##"}} {{ ((option.loc | join (".")) or name).replace("<", "<").replace(">", ">") }} 5 | 6 | {% if (option.description or '') != "This option has no description." -%} 7 | {{ option.description or '' }} 8 | {%- endif %} 9 | 10 | {% if "type" in option %} 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | {%- if option.default -%} 21 | 22 | 23 | 24 | 25 | {%- endif -%} 26 | {%- if option.example -%} 27 | 28 | 29 | 32 | 33 | {%- endif -%} 34 | 35 |
    type{{ option.type}} {{ "(read only)" if option.readOnly else "" }}
    source{%- for d in option.declarations -%}{{d.name}}{{ ", " if not loop.last else "" }}{%- endfor -%}
    default{{(option.default | default({})).text | pygments("nix")}}
    example 30 | {{(option.example | default({})).text | pygments("nix")}} 31 |
    36 | {% endif %} 37 | {%- if option.children -%} 38 | {{ loop(option.children.items()) }} 39 | {%- endif %} 40 | {%- endfor %} 41 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-granular-v3/configurePhase.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | nodeDeps, 4 | }: '' 5 | runHook preConfigure 6 | 7 | # symlink sub dependencies as well as this imitates npm better 8 | python $installDeps 9 | 10 | echo "Symlinking transitive executables to $nodeModules/.bin" 11 | for dep in ${toString nodeDeps}; do 12 | binDir=$dep/lib/node_modules/.bin 13 | if [ -e $binDir ]; then 14 | for bin in $(ls $binDir/); do\ 15 | if [ ! -e $nodeModules/.bin ]; then 16 | mkdir -p $nodeModules/.bin 17 | fi 18 | 19 | # symlink might have been already created by install-deps.py 20 | # if installMethod=copy was selected 21 | if [ ! -L $nodeModules/.bin/$bin ]; then 22 | ln -s $binDir/$bin $nodeModules/.bin/$bin 23 | else 24 | echo "won't overwrite existing symlink $nodeModules/.bin/$bin. current target: $(readlink $nodeModules/.bin/$bin)" 25 | fi 26 | done 27 | fi 28 | done 29 | 30 | # add bin path entries collected by python script 31 | export PATH="$PATH:$nodeModules/.bin" 32 | 33 | # add dependencies to NODE_PATH 34 | export NODE_PATH="$NODE_PATH:$nodeModules/$packageName/node_modules" 35 | 36 | export HOME=$TMPDIR 37 | 38 | runHook postConfigure 39 | '' 40 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-granular/configurePhase.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | nodeDeps, 4 | }: '' 5 | runHook preConfigure 6 | 7 | # symlink sub dependencies as well as this imitates npm better 8 | python $installDeps 9 | 10 | echo "Symlinking transitive executables to $nodeModules/.bin" 11 | for dep in ${toString nodeDeps}; do 12 | binDir=$dep/lib/node_modules/.bin 13 | if [ -e $binDir ]; then 14 | for bin in $(ls $binDir/); do\ 15 | if [ ! -e $nodeModules/.bin ]; then 16 | mkdir -p $nodeModules/.bin 17 | fi 18 | 19 | # symlink might have been already created by install-deps.py 20 | # if installMethod=copy was selected 21 | if [ ! -L $nodeModules/.bin/$bin ]; then 22 | ln -s $binDir/$bin $nodeModules/.bin/$bin 23 | else 24 | echo "won't overwrite existing symlink $nodeModules/.bin/$bin. current target: $(readlink $nodeModules/.bin/$bin)" 25 | fi 26 | done 27 | fi 28 | done 29 | 30 | # add bin path entries collected by python script 31 | export PATH="$PATH:$nodeModules/.bin" 32 | 33 | # add dependencies to NODE_PATH 34 | export NODE_PATH="$NODE_PATH:$nodeModules/$packageName/node_modules" 35 | 36 | export HOME=$TMPDIR 37 | 38 | runHook postConfigure 39 | '' 40 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-granular/unpackPhase.nix: -------------------------------------------------------------------------------- 1 | {}: let 2 | in '' 3 | runHook preUnpack 4 | 5 | nodeModules=$(realpath ./package) 6 | 7 | export sourceRoot="$nodeModules/$packageName" 8 | 9 | # sometimes tarballs do not end with .tar.?? 10 | unpackFallback(){ 11 | local fn="$1" 12 | tar xf "$fn" 13 | } 14 | 15 | unpackCmdHooks+=(unpackFallback) 16 | 17 | unpackFile $src 18 | 19 | # Make the base dir in which the target dependency resides in first 20 | mkdir -p "$(dirname "$sourceRoot")" 21 | 22 | # install source 23 | if [ -f "$src" ] 24 | then 25 | # Figure out what directory has been unpacked 26 | packageDir="$(find . -maxdepth 1 -type d | tail -1)" 27 | 28 | # Restore write permissions 29 | find "$packageDir" -type d -exec chmod u+x {} \; 30 | chmod -R u+w -- "$packageDir" 31 | 32 | # Move the extracted tarball into the output folder 33 | mv -- "$packageDir" "$sourceRoot" 34 | elif [ -d "$src" ] 35 | then 36 | strippedName="$(stripHash $src)" 37 | 38 | # Restore write permissions 39 | chmod -R u+w -- "$strippedName" 40 | 41 | # Move the extracted directory into the output folder 42 | mv -- "$strippedName" "$sourceRoot" 43 | fi 44 | 45 | runHook postUnpack 46 | '' 47 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-granular-v3/unpackPhase.nix: -------------------------------------------------------------------------------- 1 | {}: let 2 | in '' 3 | runHook preUnpack 4 | 5 | nodeModules=$(realpath ./package) 6 | 7 | export sourceRoot="$nodeModules/$packageName" 8 | 9 | # sometimes tarballs do not end with .tar.?? 10 | unpackFallback(){ 11 | local fn="$1" 12 | tar xf "$fn" 13 | } 14 | 15 | unpackCmdHooks+=(unpackFallback) 16 | 17 | unpackFile $src 18 | 19 | # Make the base dir in which the target dependency resides in first 20 | mkdir -p "$(dirname "$sourceRoot")" 21 | 22 | # install source 23 | if [ -f "$src" ] 24 | then 25 | # Figure out what directory has been unpacked 26 | packageDir="$(find . -maxdepth 1 -type d | tail -1)" 27 | 28 | # Restore write permissions 29 | find "$packageDir" -type d -exec chmod u+x {} \; 30 | chmod -R u+w -- "$packageDir" 31 | 32 | # Move the extracted tarball into the output folder 33 | mv -- "$packageDir" "$sourceRoot" 34 | elif [ -d "$src" ] 35 | then 36 | strippedName="$(stripHash $src)" 37 | 38 | # Restore write permissions 39 | chmod -R u+w -- "$strippedName" 40 | 41 | # Move the extracted directory into the output folder 42 | mv -- "$strippedName" "$sourceRoot" 43 | fi 44 | 45 | runHook postUnpack 46 | '' 47 | -------------------------------------------------------------------------------- /modules/flake-parts/checks.nix-unit.nix: -------------------------------------------------------------------------------- 1 | # evaluate packages from `/**/modules/drvs` and export them via `flake.packages` 2 | {self, ...}: { 3 | perSystem = { 4 | pkgs, 5 | inputs', 6 | lib, 7 | system, 8 | ... 9 | }: let 10 | dream2nixFlake = import ../../. {}; 11 | inputs = lib.mapAttrs (name: input: "${input.outPath}") dream2nixFlake.inputs; 12 | inputsFile = builtins.toFile "inputs.json" (builtins.toJSON inputs); 13 | in 14 | lib.optionalAttrs (system == "x86_64-linux") { 15 | # map all modules in /examples to a package output in the flake. 16 | checks.nix-unit = 17 | pkgs.runCommand "nix-unit-tests" { 18 | nativeBuildInputs = [ 19 | pkgs.nix 20 | ]; 21 | } '' 22 | export NIX_PATH=nixpkgs=${pkgs.path} 23 | export HOME=$(realpath .) 24 | for test in ${../..}/tests/nix-unit/*; do 25 | if [ -f "$test" ]; then 26 | continue 27 | fi 28 | echo -e "Executing tests from file $test" 29 | ${pkgs.nix-unit}/bin/nix-unit \ 30 | "$test" \ 31 | --eval-store $(realpath .) \ 32 | --arg inputs 'builtins.fromJSON (builtins.readFile ${inputsFile})' 33 | done 34 | touch $out 35 | ''; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-package-json/tests/packages/basic/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | config, 4 | dream2nix, 5 | ... 6 | }: { 7 | imports = [ 8 | dream2nix.modules.dream2nix.nodejs-package-json 9 | dream2nix.modules.dream2nix.nodejs-granular 10 | ]; 11 | 12 | nodejs-package-lock = { 13 | source = ./.; 14 | }; 15 | 16 | paths.projectRootFile = "package.json"; 17 | 18 | deps = {nixpkgs, ...}: { 19 | inherit 20 | (nixpkgs) 21 | fetchFromGitHub 22 | stdenv 23 | ; 24 | npm = nixpkgs.nodejs.pkgs.npm.override rec { 25 | version = "8.19.4"; 26 | src = nixpkgs.fetchurl { 27 | url = "https://registry.npmjs.org/npm/-/npm-${version}.tgz"; 28 | hash = "sha256-JmehuDAPMV0iPkPDB/vpRuuLl3kq85lCTvZ+qcsKcvY="; 29 | }; 30 | }; 31 | }; 32 | 33 | name = lib.mkForce "app"; 34 | version = lib.mkForce "1.0.0"; 35 | 36 | nodejs-granular = { 37 | buildScript = '' 38 | tsc ./app.ts 39 | mv app.js app.js.tmp 40 | echo "#!${config.deps.nodejs}/bin/node" > app.js 41 | cat app.js.tmp >> app.js 42 | chmod +x ./app.js 43 | patchShebangs . 44 | ''; 45 | }; 46 | 47 | mkDerivation = { 48 | src = ./.; 49 | checkPhase = '' 50 | [[ "Hello, World!" =~ "$(./app.js)" ]] 51 | ''; 52 | doCheck = true; 53 | }; 54 | } 55 | -------------------------------------------------------------------------------- /modules/dream2nix/nodejs-package-json/tests/packages/basic/lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "package-lock": { 3 | "name": "app", 4 | "version": "1.0.0", 5 | "lockfileVersion": 2, 6 | "requires": true, 7 | "packages": { 8 | "": { 9 | "name": "app", 10 | "version": "1.0.0", 11 | "dependencies": { 12 | "typescript": "^5.1.6" 13 | }, 14 | "bin": { 15 | "app": "app.js" 16 | } 17 | }, 18 | "node_modules/typescript": { 19 | "version": "5.2.2", 20 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", 21 | "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", 22 | "bin": { 23 | "tsc": "bin/tsc", 24 | "tsserver": "bin/tsserver" 25 | }, 26 | "engines": { 27 | "node": ">=14.17" 28 | } 29 | } 30 | }, 31 | "dependencies": { 32 | "typescript": { 33 | "version": "5.2.2", 34 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", 35 | "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==" 36 | } 37 | } 38 | }, 39 | "invalidationHash": "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a" 40 | } -------------------------------------------------------------------------------- /modules/dream2nix/python-pdm/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | specialArgs, 5 | ... 6 | }: let 7 | l = lib // builtins; 8 | t = l.types; 9 | mkSubmodule = import ../../../lib/internal/mkSubmodule.nix {inherit lib specialArgs;}; 10 | in { 11 | options.pdm = mkSubmodule { 12 | imports = [ 13 | ../overrides 14 | ../python-editables 15 | ]; 16 | options = { 17 | lockfile = l.mkOption { 18 | type = t.path; 19 | }; 20 | pyproject = l.mkOption { 21 | type = t.path; 22 | }; 23 | useUvResolver = l.mkOption { 24 | type = t.bool; 25 | default = false; 26 | }; 27 | group = l.mkOption { 28 | type = t.str; 29 | default = "default"; 30 | description = '' 31 | PDM supports multiple groups by specifying [project.optional-dependencies], [tool.pdm.dev-dependencies] or [dependency-groups] (pep 735). 32 | All of these groups will get locked in the pdm.lock file and the user can specify which group name to use. 33 | ''; 34 | }; 35 | 36 | sourceSelector = import ./sourceSelectorOption.nix {inherit lib;}; 37 | }; 38 | }; 39 | options.groups = 40 | (import ../WIP-groups/groups-option.nix {inherit config lib specialArgs;}) 41 | // { 42 | internal = true; 43 | visible = "shallow"; 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-spago/lock.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import json 3 | import os 4 | import multiprocessing 5 | from multiprocessing.pool import ThreadPool 6 | 7 | with open("spago.json", "r") as spagoFile, open("packages.json", "r") as packagesFile: 8 | spago = json.load(spagoFile) 9 | packagesSet = json.load(packagesFile) 10 | 11 | dependencies = spago["package"]["dependencies"] 12 | checked = set() 13 | 14 | closure = set(dependencies) 15 | 16 | 17 | def getDeps(deps): 18 | for dep in deps.copy(): 19 | if dep in checked: 20 | continue 21 | checked.add(dep) 22 | closure.update(getDeps(set(packagesSet[dep]["dependencies"]))) 23 | return deps 24 | 25 | 26 | getDeps(set(dependencies)) 27 | 28 | lock = {} 29 | 30 | 31 | def getSource(depName): 32 | dep = packagesSet[depName] 33 | repo = dep["repo"] 34 | version = dep["version"] 35 | rev = subprocess.run( 36 | ["git", "ls-remote", repo, version], text=True, capture_output=True 37 | ).stdout.split()[0] 38 | print(f"{repo}/{version}: {rev}") 39 | lock[depName] = dep 40 | lock[depName]["rev"] = rev 41 | 42 | 43 | with ThreadPool(processes=multiprocessing.cpu_count() * 2) as pool: 44 | pool.map_async(getSource, closure) 45 | pool.close() 46 | pool.join() 47 | 48 | with open(os.environ.get("out"), "w") as f: 49 | json.dump(lock, f) 50 | -------------------------------------------------------------------------------- /modules/dream2nix/builtins-derivation/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: let 6 | l = lib // builtins; 7 | t = l.types; 8 | 9 | cfg = config.builtins-derivation; 10 | 11 | outputs = l.unique cfg.outputs; 12 | 13 | keepArg = key: val: val != null; 14 | 15 | finalArgs = l.filterAttrs keepArg cfg; 16 | 17 | # ensure that none of the env variables collide with the top-level options 18 | envChecked = 19 | l.mapAttrs 20 | (key: val: 21 | if config.builtins-derivation.${key} or false 22 | then throw (envCollisionError key) 23 | else val) 24 | config.env; 25 | 26 | # generates error message for env variable collision 27 | envCollisionError = key: '' 28 | Error while evaluating definitions for derivation ${config.name} 29 | The environment variable defined via `env.${key}' collides with the option builtins-derivation.`${key}'. 30 | Specify the top-level option instead, or rename the environment variable. 31 | ''; 32 | in { 33 | imports = [ 34 | ./interface.nix 35 | ../core 36 | ../package-func 37 | ]; 38 | 39 | config.package-func.outputs = cfg.outputs; 40 | 41 | config.package-func.func = lib.mkDefault builtins.derivation; 42 | 43 | config.package-func.args = 44 | envChecked 45 | // finalArgs 46 | // { 47 | inherit outputs; 48 | inherit (config.public) name; 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /modules/dream2nix/nixpkgs-overrides/interface.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: let 6 | l = lib // builtins; 7 | t = l.types; 8 | in { 9 | options.nixpkgs-overrides = { 10 | enable = 11 | (l.mkEnableOption "copying derivation attributes from a similar package in nixpkgs") 12 | // { 13 | default = true; 14 | }; 15 | 16 | exclude = l.mkOption { 17 | type = t.listOf t.str; 18 | description = "Attribute names excluded from copying"; 19 | }; 20 | 21 | from = l.mkOption { 22 | type = t.nullOr t.package; 23 | description = "package from which to extract the attributes"; 24 | default = config.deps.python.pkgs.${config.name} or null; 25 | defaultText = "config.deps.python.pkgs.\${config.name} or null"; 26 | }; 27 | 28 | lib.extractOverrideAttrs = l.mkOption { 29 | type = t.functionTo t.attrs; 30 | description = '' 31 | Helper function to extract attrs from nixpkgs to be re-used as overrides. 32 | ''; 33 | readOnly = true; 34 | }; 35 | 36 | # Extracts derivation args from a nixpkgs python package. 37 | lib.extractPythonAttrs = l.mkOption { 38 | type = t.functionTo t.attrs; 39 | description = '' 40 | Helper function to extract python attrs from nixpkgs to be re-used as overrides. 41 | ''; 42 | readOnly = true; 43 | }; 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /lib/internal/fetchers/extractSource.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | mkDerivation, 4 | ... 5 | }: let 6 | l = builtins // lib; 7 | 8 | # TODO is this really needed? Seems to make builds slower, why not unpack + build? 9 | extractSource = { 10 | source, 11 | dir ? "", 12 | name ? null, 13 | } @ args: 14 | mkDerivation { 15 | name = "${(args.name or source.name or "")}-extracted"; 16 | src = source; 17 | inherit dir; 18 | phases = ["unpackPhase"]; 19 | dontInstall = true; 20 | dontFixup = true; 21 | # Allow to access the original output of the FOD. 22 | # Some builders like python require the original archive. 23 | passthru.original = source; 24 | unpackCmd = 25 | if l.hasSuffix ".tgz" (source.name or "${source}") 26 | then '' 27 | tar --delay-directory-restore -xf $src 28 | 29 | # set executable flag only on directories 30 | chmod -R +X . 31 | '' 32 | else null; 33 | # sometimes tarballs do not end with .tar.?? 34 | preUnpack = '' 35 | unpackFallback(){ 36 | local fn="$1" 37 | tar xf "$fn" 38 | } 39 | 40 | unpackCmdHooks+=(unpackFallback) 41 | ''; 42 | postUnpack = '' 43 | echo postUnpack 44 | mv "$sourceRoot/$dir" $out 45 | exit 46 | ''; 47 | }; 48 | in 49 | extractSource 50 | -------------------------------------------------------------------------------- /examples/packages/languages/nodejs-local-development-nextjs/nextjs-app/public/next.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /modules/flake-parts/reference-website/frontmatter.nix: -------------------------------------------------------------------------------- 1 | {lib}: rec { 2 | getReadme = modulepath: modulename: let 3 | readme = modulepath + "/README.md"; 4 | readmeContents = 5 | if (builtins.pathExists readme) 6 | then (builtins.readFile readme) 7 | else throw "No README.md found for module ${modulename} (expected at ${readme})"; 8 | in 9 | readmeContents; 10 | 11 | getFrontmatterString = modulepath: modulename: let 12 | content = getReadme modulepath modulename; 13 | parts = lib.splitString "---" content; 14 | # Partition the parts into the first part (the readme content) and the rest (the metadata) 15 | parsed = builtins.partition ({index, ...}: 16 | if index >= 2 17 | then false 18 | else true) ( 19 | lib.filter ({index, ...}: index != 0) (lib.imap0 (index: part: {inherit index part;}) parts) 20 | ); 21 | meta = (builtins.head parsed.right).part; 22 | in 23 | if (builtins.length parts >= 3) 24 | then meta 25 | else 26 | throw '' 27 | TOML Frontmatter not found in README.md for module ${modulename} 28 | 29 | Please add the following to the top of your README.md: 30 | 31 | --- 32 | description = "Your description here" 33 | categories = [ "Your categories here" ] 34 | features = [ "inventory" ] 35 | --- 36 | ...rest of your README.md... 37 | ''; 38 | } 39 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/tests/packages/nodejs-nextjs/nextjs-app/public/next.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /modules/dream2nix/WIP-nodejs-builder-v3/modules/dist.nix: -------------------------------------------------------------------------------- 1 | { 2 | # default args 3 | # lib 4 | dream2nix, 5 | # _module.args 6 | packageName, 7 | plent, 8 | prepared-dev, 9 | packageLockFile, 10 | trustedDeps, 11 | nodejs, 12 | jq, 13 | ... 14 | }: let 15 | installTrusted = ../scripts/install-trusted-modules.mjs; 16 | in { 17 | imports = [ 18 | dream2nix.modules.dream2nix.mkDerivation 19 | ]; 20 | 21 | inherit (plent) version; 22 | name = packageName + "-dist"; 23 | env = { 24 | TRUSTED = builtins.toJSON trustedDeps; 25 | }; 26 | mkDerivation = { 27 | # inherit (entry) version; 28 | src = builtins.dirOf packageLockFile; 29 | buildInputs = [nodejs jq]; 30 | configurePhase = '' 31 | cp -r ${prepared-dev}/node_modules node_modules 32 | chmod -R +w node_modules 33 | node ${installTrusted} 34 | ''; 35 | buildPhase = '' 36 | echo "BUILDING... $name" 37 | 38 | if [ "$(jq -e '.scripts.build' ./package.json)" != "null" ]; then 39 | echo "BUILDING... $name" 40 | export HOME=.virt-home 41 | npm run build 42 | else 43 | echo "$(jq -e '.scripts.build' ./package.json)" 44 | echo "No build script"; 45 | fi; 46 | ''; 47 | installPhase = '' 48 | echo "Removing (dev)node_modules from dist output." 49 | rm -rf node_modules 50 | # TODO: filter files 51 | cp -r . $out 52 | ''; 53 | }; 54 | } 55 | -------------------------------------------------------------------------------- /modules/dream2nix/builtins-derivation/derivation-common/options.nix: -------------------------------------------------------------------------------- 1 | {lib}: let 2 | l = lib // builtins; 3 | t = l.types; 4 | optNullOrBool = l.mkOption { 5 | type = t.nullOr t.bool; 6 | default = null; 7 | }; 8 | optListOfStr = l.mkOption { 9 | type = t.nullOr (t.listOf t.str); 10 | default = null; 11 | }; 12 | optNullOrStr = l.mkOption { 13 | type = t.nullOr t.str; 14 | default = null; 15 | }; 16 | in { 17 | # basic arguments 18 | args = l.mkOption { 19 | type = t.nullOr (t.listOf (t.oneOf [t.str t.path])); 20 | default = null; 21 | }; 22 | outputs = l.mkOption { 23 | type = t.nullOr (t.listOf t.str); 24 | default = ["out"]; 25 | }; 26 | __contentAddressed = optNullOrBool; 27 | __structuredAttrs = lib.mkOption { 28 | type = t.nullOr t.bool; 29 | default = null; 30 | }; 31 | 32 | # advanced attributes 33 | allowedReferences = optListOfStr; 34 | allowedRequisites = optListOfStr; 35 | disallowedReferences = optListOfStr; 36 | disallowedRequisites = optListOfStr; 37 | exportReferenceGraph = lib.mkOption { 38 | # TODO: make type stricter 39 | type = t.nullOr (t.listOf (t.either t.str t.package)); 40 | default = null; 41 | }; 42 | impureEnvVars = optListOfStr; 43 | outputHash = optNullOrStr; 44 | outputHashAlgo = optNullOrStr; 45 | outputHashMode = optNullOrStr; 46 | passAsFile = optListOfStr; 47 | preferLocalBuild = optListOfStr; 48 | allowSubstitutes = optNullOrBool; 49 | } 50 | -------------------------------------------------------------------------------- /pkgs/fetchPipMetadata/src/tests/test_lock_info_from_path.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from pathlib import Path 3 | 4 | import lock_file_from_report as l 5 | 6 | 7 | def test_path_in_repo_root(git_repo_path): 8 | assert l.lock_info_from_path(git_repo_path / "foo", git_repo_path) == { 9 | "type": "local", 10 | "path": "foo", 11 | } 12 | 13 | 14 | def test_path_not_in_store_or_repo(): 15 | with pytest.raises(Exception) as exc_info: 16 | l.lock_info_from_path(Path("/foo/bar"), Path("/beer")) 17 | assert "refers to something outside /nix/store" in str(exc_info.value) 18 | 19 | 20 | def test_path_is_fod_output(monkeypatch): 21 | fod_store_path = "/nix/store/test" 22 | 23 | def nix_show_derivation(store_path): 24 | return dict( 25 | env=dict( 26 | urls="https://example.com", 27 | ), 28 | outputs=dict( 29 | out=dict( 30 | hash="3a3f9b030dcb0974ef85969c37f570349df9d74fb8abf34ed86fc5aae0bef42b", 31 | hashAlgo="r:sha256", 32 | path=fod_store_path, 33 | ) 34 | ), 35 | ) 36 | 37 | monkeypatch.setattr(l, "nix_show_derivation", nix_show_derivation) 38 | assert l.lock_info_from_path(Path(fod_store_path), Path("foo")) == { 39 | "type": "url", 40 | "url": "https://example.com", 41 | "sha256": "3a3f9b030dcb0974ef85969c37f570349df9d74fb8abf34ed86fc5aae0bef42b", 42 | } 43 | -------------------------------------------------------------------------------- /dev-flake/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Flake containing inputs/outputs not intended for overriding by the end-user"; 3 | 4 | nixConfig = { 5 | extra-trusted-public-keys = "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="; 6 | extra-substituters = "https://nix-community.cachix.org"; 7 | }; 8 | 9 | inputs = { 10 | nixpkgs.url = "nixpkgs/nixpkgs-unstable"; 11 | 12 | flake-parts.url = "github:hercules-ci/flake-parts"; 13 | flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; 14 | 15 | flake-compat.url = "github:nix-community/flake-compat/pull/4/head"; 16 | flake-compat.flake = false; 17 | 18 | pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; 19 | pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs"; 20 | 21 | devshell = { 22 | url = "github:numtide/devshell"; 23 | flake = false; 24 | }; 25 | 26 | nuschtos.url = "github:NuschtOS/search"; 27 | nuschtos.inputs.nixpkgs.follows = "nixpkgs"; 28 | }; 29 | 30 | outputs = { 31 | self, 32 | devshell, 33 | flake-parts, 34 | nixpkgs, 35 | pre-commit-hooks, 36 | ... 37 | } @ inputs: 38 | flake-parts.lib.mkFlake {inherit inputs;} { 39 | imports = [ 40 | ../modules/flake-parts/all-modules.nix 41 | ../pkgs/fetchPipMetadata/flake-module.nix 42 | ]; 43 | systems = [ 44 | "x86_64-linux" 45 | "aarch64-linux" 46 | "x86_64-darwin" 47 | "aarch64-darwin" 48 | ]; 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /modules/dream2nix/pip/pip-hotfixes/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | config, 3 | lib, 4 | ... 5 | }: let 6 | l = lib // builtins; 7 | cfg = config.pip; 8 | metadata = config.lock.content.fetchPipMetadata; 9 | 10 | ignored = l.genAttrs cfg.ignoredDependencies (name: true); 11 | 12 | filterTarget = target: 13 | l.filterAttrs (name: target: ! ignored ? ${name}) target; 14 | 15 | # filter out ignored dependencies 16 | targets = l.flip l.mapAttrs metadata.targets ( 17 | targetName: target: 18 | l.flip l.mapAttrs (filterTarget target) ( 19 | packageName: deps: 20 | l.filter (dep: ! ignored ? ${dep}) deps 21 | ) 22 | ); 23 | rootDependencies = 24 | if cfg.flattenDependencies 25 | then 26 | if targets.default ? ${config.name} 27 | then 28 | throw '' 29 | Top-level package ${config.name} is listed in the lockfile. 30 | Set `pip.flattenDependencies` to false to use only the top-level dependencies. 31 | '' 32 | else l.attrNames (targets.default) 33 | else if ! targets.default ? ${config.name} 34 | then 35 | throw '' 36 | Top-level package ${config.name} is not listed in the lockfile. 37 | Set `pip.flattenDependencies` to true to use all dependencies for the top-level package. 38 | '' 39 | else targets.default.${config.name}; 40 | in { 41 | imports = [ 42 | ./interface.nix 43 | ]; 44 | pip.targets = targets; 45 | pip.rootDependencies = lib.genAttrs rootDependencies (_: true); 46 | } 47 | -------------------------------------------------------------------------------- /examples/repo-with-packages-flake/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | # This example flake.nix is pretty generic and the same for all 3 | # examples, except when they define devShells or extra packages. 4 | description = "Dream2nix example flake"; 5 | 6 | # We import the latest commit of dream2nix main branch and instruct nix to 7 | # re-use the nixpkgs revision referenced by dream2nix. 8 | # This is what we test in CI with, but you can generally refer to any 9 | # recent nixpkgs commit here. 10 | inputs = { 11 | dream2nix.url = "github:nix-community/dream2nix"; 12 | nixpkgs.follows = "dream2nix/nixpkgs"; 13 | }; 14 | 15 | outputs = { 16 | self, 17 | dream2nix, 18 | nixpkgs, 19 | }: let 20 | # A helper that helps us define the attributes below for 21 | # all systems we care about. 22 | eachSystem = nixpkgs.lib.genAttrs [ 23 | "aarch64-darwin" 24 | "aarch64-linux" 25 | "x86_64-darwin" 26 | "x86_64-linux" 27 | ]; 28 | in { 29 | packages = eachSystem (system: 30 | dream2nix.lib.importPackages { 31 | # All packages defined in ./packages/ are automatically added to the flake outputs 32 | # e.g., 'packages/hello/default.nix' becomes '.#packages.hello' 33 | projectRoot = ./.; 34 | # can be changed to ".git" or "flake.nix" to get rid of .project-root 35 | projectRootFile = "flake.nix"; 36 | packagesDir = ./packages; 37 | packageSets.nixpkgs = nixpkgs.legacyPackages.${system}; 38 | }); 39 | }; 40 | } 41 | -------------------------------------------------------------------------------- /docs/src/v1-api/problems.md: -------------------------------------------------------------------------------- 1 | # Problems of the current dream2nix 2 | 3 | ## Integration of existing lang2nix tools 4 | Until now, integrating existing 2nix solutions into dream2nix was hard because dream2nix imposed standards which are not met by most existing tools. 5 | With v1 we want to lift most of these restrictions to make integration a no-brainer 6 | 7 | (see sections [integrate lang2nix tool (pure)](../v1-api/integrating/integrate-lang2nix-pure.md) and [integrate lang2ix tool (impure)](../v1-api/integrating/integrate-lang2nix-impure.md). 8 | 9 | ## Tied to flakes 10 | The current api is tied to flakes. The v1 API should not depend on flakes anymore. 11 | 12 | ## Composability 13 | Composability with the current `makeFlakeOutputs` is bad. Flakes itself aren't nicely composable. Filtering and merging of nested attrsets isn't user friendly. 14 | 15 | The v1 api will focus on delivering individual derivations, not flakes. 16 | While we might provide templates, recommendations, and tools for composition, we should not enforce a specific solution onto the user. 17 | 18 | ## Overridability 19 | The experience of overriding package- and dependency builds was a bit bumpy so far, as the overriding mechanism was built ontop of override functions provided by nixpkgs' `mkDerivation`. The v1 API will make use of the nixos module system instead to handle derivation attributes. 20 | 21 | ## Discoverability of package options 22 | We want users to be able to inspect the API of an individual package. This will also be made possible by the nixos module system. 23 | --------------------------------------------------------------------------------