{"id":14968024,"url":"https://github.com/davidegrayson/nixcrpkgs","last_synced_at":"2025-04-05T03:07:10.648Z","repository":{"id":58734217,"uuid":"78809412","full_name":"DavidEGrayson/nixcrpkgs","owner":"DavidEGrayson","description":"Nice nix expressions for cross-compiling.","archived":false,"fork":false,"pushed_at":"2025-01-15T19:22:24.000Z","size":1285,"stargazers_count":146,"open_issues_count":4,"forks_count":8,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-03T19:14:34.704Z","etag":null,"topics":["cross-compiler","cross-compiler-toolchain","nix","nixpkgs"],"latest_commit_sha":null,"homepage":null,"language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DavidEGrayson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.nixpkgs","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"support/derivations.txt","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-13T02:54:14.000Z","updated_at":"2025-02-18T21:44:30.000Z","dependencies_parsed_at":"2023-02-15T20:45:55.023Z","dependency_job_id":"aaa33544-415d-46fb-b017-1f52156eb094","html_url":"https://github.com/DavidEGrayson/nixcrpkgs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidEGrayson%2Fnixcrpkgs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidEGrayson%2Fnixcrpkgs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidEGrayson%2Fnixcrpkgs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidEGrayson%2Fnixcrpkgs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DavidEGrayson","download_url":"https://codeload.github.com/DavidEGrayson/nixcrpkgs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247280264,"owners_count":20912967,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cross-compiler","cross-compiler-toolchain","nix","nixpkgs"],"created_at":"2024-09-24T13:39:07.558Z","updated_at":"2025-04-05T03:07:10.627Z","avatar_url":"https://github.com/DavidEGrayson.png","language":"Nix","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nixcrpkgs\n\n[www.pololu.com](https://www.pololu.com/)\n\n*nixcrpkgs* is a collection of tools for cross-compiling statically-linked,\nstandalone software applications.  With nixcrpkgs, you can specify what\nplatforms you want to target, what libraries and build tools you depend on, and\nthe commands that build your software.  When you build your software, nixcrpkgs\nwill automatically take care of building or retrieving everything you need,\nincluding cross-compilers and libraries.\n\nnixcrpkgs primarily consists of *Nix expressions*, which are recipes for\nbuilding software with [Nix, the purely functional package\nmanager][nix].  These recipes build on top of the [Nix\nPackages collection (Nixpkgs)][nixpkgs].\n\n## Features\n\n- Supported target platforms:\n  - Windows (i686 or x86_64) using [mingw-w64](https://mingw-w64.org/)\n    and [GCC](https://gcc.gnu.org/) 12.2.0\n  - Linux (i686, x86_64, armv6, aarch64) using [musl](https://www.musl-libc.org/)\n    and [GCC](https://gcc.gnu.org/) 14.1.0\n  - macOS (x86_64 and ARM) using [Clang](https://clang.llvm.org/) 14.0.6\n- Supported languages for cross-compiling:\n  - C\n  - C++\n- Supported build platforms:\n  - Linux\n- Supported build tools:\n  - [CMake](https://cmake.org/)\n  - [GNU Make](https://www.gnu.org/software/make/)\n  - [Ninja](https://ninja-build.org/)\n  - pkg-config (as implemented by [pkgconf](https://github.com/pkgconf/pkgconf))\n  - [GNU Bash](https://www.gnu.org/software/bash/)\n  - [Ruby](https://www.ruby-lang.org/)\n- Notable supported libraries:\n  - [Qt](https://www.qt.io/) 5.12.12 and 6.5.3\n  - [libusb](https://libusb.info/)\n  - [libusbp](https://github.com/pololu/libusbp)\n  - [Windows API](https://en.wikipedia.org/wiki/Windows_API) (thanks to mingw-w64)\n\n\n## Getting started\n\nTo get started, you should first install Nix on a Linux machine by following the\ninstructions on the [Nix website][nix].\n\nNext, run `df -h` to make sure you have enough disk space.\n\n- The filesystem that holds `/nix` should have many gigabytes of free\nspace.  Each cross-compiler can take about 1 GB while each Qt installation\ntakes about 500 MB.\n- The filesystem that holds `/tmp` should have at least 5 GB of free\nspace, which will be needed while building cross-compilers.  If that is not the\ncase on your system, you can set the `TMPDIR` environment variable to tell\n`nix-build` to perform its builds in a different directory on a filesystem with\nmore free space.\n\nNext, clone or download this repository and use `cd` to change into the\ntop-level directory.\n\nTo build a simple \"Hello, World!\" program for Windows, run:\n\n    nix-build -A win32.hello\n\nThe first time you run this command, it will take a while because Nix has to\nbuild a cross-compiling toolchain.  When `nix-build` is done, it will print the\nname of a directory in `/nix/store` that holds the resulting program, and it\nwill create a symbolic link in the current directory named `result` that points\nto that directory.\n\nIf you copy `result/bin/hello.exe` to a Windows machine and run it, you should\nsee a message box appear that says \"Hello, World!\".\n\nIf you run `nix-build -A win32.hello` a second time, Nix will detect that\nnothing about the build recipes has changed, so it will simply print the\ndirectory name and remake the symbolic link.\n\nTo see how the `hello` package is specified in nixcrpkgs, you can look in\n`pkgs.nix` and the `pkgs/hello` directory.  To see how the GCC cross-compiler\nfor Windows was specified, you can look in the `mingw-w64` directory.  If you\nchange any of the build recipes for `hello` or its dependencies and then run the\n`nix-build` command again, Nix will automatically rebuild those dependencies and\nanything that depends on them, ensuring that you always get a consistent build.\n\n\n### Obtaining the macOS SDK\n\nIf you are trying to build software for macOS, you will need to get a\nmacOS SDK tarball and put it in the the right place.  Otherwise, you\nwill get an error like this:\n\n    error: getting attributes of path '/home/yourname/nixcrpkgs/macos/MacOSX.sdk.tar.xz': No such file or directory\n\nTo generate the tarball, follow these steps:\n\n1. On a macOS machine, install [Xcode](https://developer.apple.com/xcode/).\n2. Download this repository to the machine.\n3. In a Terminal window, run the `macos/gen_sdk_package.sh` script from this repository.\n4. After several minutes, the current directory should have a tarball with a name like\n  `MacOSX12.3.sdk.tar.bz2` and a size of about 100 MB.\n5. Copy the SDK tarball file to the machine where you will be building software,\n  and put it in the `macos` directory.\n6. The nixcrpkgs build recipe for the SDK is hardcoded to look for a file named\n  `MacOSX.sdk.tar.xz`, so rename the tarball to that.  (Changing the extension\n   is fine.)\n7. Consider keeping a backup of the tarball so you can always rebuild any software you\n  made with it.\n\nNow you should be able to build your software for macOS.\n\n\n## Integrating nixcrpkgs into your project\n\nThe instructions above show how to cross-compile a \"Hello, World!\" program that\nis included with nixcrpkgs.  Instead of including your project in nixcrpkgs like\nthe hello program, you will probably want to just use nixcrpkgs as a tool in\nyour project.  To get an idea of how to do that, you can look at other projects\nthat have done the same.  In the projects listed below, you should look for a\nfile named `default.nix` in the top-level directory and look for build\ninstructions that explain what `nix-build` commands to run.\n\n* The [Pololu Tic Stepper Motor Controller software](https://github.com/pololu/pololu-tic-software) is a C/C++ project that uses CMake and nixcrpkgs.\n* The [Pololu USB AVR Programmer v2 software](https://github.com/pololu/pololu-usb-avr-programmer-v2) is a C++ project that uses CMake and nixcrpkgs.\n* The [Pololu USB Bootloader Utility (p-load)](https://github.com/pololu/p-load) is a C++ project that uses CMake and nixcrpkgs.\n\n[nix]: http://nixos.org/nix/\n[nixpkgs]: http://nixos.org/nixpkgs/\n\n## Updating package versions\n\nEach build recipe in nixcrpkgs specifies a version number for the software that it builds.  It is relatively easy to update the recipes even if you have not worked with Nix before.  The general procedure is:\n\n1) Find the build recipe you want to update.  For example, if you wanted to update the version of GCC used to build Linux programs, you would update the build recipe in `linux/gcc/default.nix`.\n2) Find the part of the build recipe where the software sources are downloaded from the internet.  It is usually a `fetchurl` command with two parameters: `url` and `sha256`.  The `url` parameter usually refers to a version string defined nearby, so update that version string and/or the `url` parameter as desired.\n3) In a shell, run `nix-prefetch-url URL`, where URL is the new URL specified in your modified build recipe with all version variables fully expanded).  This command will download the URL you specified, store it in the Nix store, and output the hash of it in the proper format for Nix build recipes.\n3) Update the `sha256` hash string in the build recipe by replacing it with the hash that was printed in the output of `nix-prefetch-url`.  Updating the hash in the build recipe is important: Nix uses it to determine whether you already downloaded the right file, so if you don't update the hash then Nix might use the wrong file (e.g. an older version of the software that you downloaded earlier).\n4) Run the usual `nix-build` command that you use to build your software.  For example, you could go to the top-level directory of nixcrpkgs and run `nix-build -A rpi.hello` to build a \"Hello world\" program for the Raspberry Pi, or you could run `nix-build -A rpi.gcc` to just build the cross-compiler.\n5) Fix any error messages that happen, one at a time.  (Tip: to make a `.patch` file, run `diff -ur old new` where `old` and `new` are directories that contain the unpatched and patched versions of the source code, respectively.)\n6) Once things are working, consider publishing your work on Github so others can benefit from what you figured out.\n\n\n## Freeing disk space\n\nYou should occasionally run `nix-collect-garbage` to remove items that are no\nlonger needed and reclaim your disk space.  However, note that Nix will\ntypically remove all of your cross compilers and libraries when you run this\ncommand, which could require you to do a lengthy mass rebuild the next time you\nwant to build your software.\n\nThere is a method you can use to prevent Nix from garbage collecting the most\nimportant items used by nixcrpkgs.  First of all, edit or create your [nix.conf]\nfile and add this line to it:\n\n    keep-outputs = true\n\nNow run this command from the nixcrpkgs directory (you'll need Ruby installed):\n\n    ./manage gcroots\n\nThis makes a symbolic link in the nixcrpkgs directory called `gcroots.drv`,\nwhich points to a derivation (a compiled recipe for building some software) in\nthe Nix store which depends on all the derivations that are most\nimportant for nixcrpkgs.  As long as `gcroots.drv` remains in place, those\nderivations and their outputs cannot be garbage collected.\n\nIn the future, if you update nixcrpkgs and then run the command to update\n`gcroots.drv`, then items used by the old version of nixcrpkgs that are no\nlonger needed can be garbage collected.  You can also simply delete\n`gcroots.drv` if you want to garbage collect everything needed by nixcrpkgs.\n\nThe Nix manual has more\ninformation about [Nix garbage\ncollection](http://nixos.org/nix/manual/#sec-garbage-collection).\n\n\n## Updating recipes\n\nYou should occasionally run `nix-channel --update` to update to the latest\nversion of Nixpkgs.  However, when doing this, be aware that the new version of\nNixpkgs might require you to do a mass rebuild.\n\nYou should occasionally update your checkout of the nixcrpkgs repository to get\nthe latest versions of build tools, new features, and bug fixes.  Once again,\nthis might require a mass rebuild.\n\nIf you want your builds to be very stable and reliable, you could make forks of\nnixcrpkgs and/or Nixpkgs and update them at your own pace, carefully considering\nany changes made by others before merging them in.  That's one of the beauties\nof Nix when compared to other package management systems: you will never be\nforced to upgrade your build tools, and using old tools is just as easy as using\nnew ones.  You can use the `NIX_PATH` environment variable to tell `nix-build`\nto use your forked versions.\n\n\n## Related projects\n\n* [osxcross]: Cross-compiling toolchain targeting macOS.\n* [musl-cross-make]: Makefile-based build tool for creating cross-compilers targeting musl.\n* [musl_nix_arm]: A fork of nixcrpkgs with a focus on building Docker images for ARM Linux.\n\n[osxcross]: https://github.com/tpoechtrager/osxcross\n[musl-cross-make]: https://github.com/richfelker/musl-cross-make\n[musl_nix_arm]: https://github.com/filleduchaos/musl_nix_arm\n[nix.conf]: https://nixos.org/nix/manual/#sec-conf-file\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidegrayson%2Fnixcrpkgs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidegrayson%2Fnixcrpkgs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidegrayson%2Fnixcrpkgs/lists"}