Skip to content

Instantly share code, notes, and snippets.

@berkowski
Created June 21, 2022 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berkowski/c496b796e0956fcb3a213940045e8ebd to your computer and use it in GitHub Desktop.
Save berkowski/c496b796e0956fcb3a213940045e8ebd to your computer and use it in GitHub Desktop.
guix shell manifest with custom environment variables
;;; GUIX manifest for rust firmware development targeting cortex-m0+ (armv6m)
;; GUIX doesn't provide alternative targets for core/std in their rust ecosystem (yet)
;; so we need to use the more conventional rustup install. This works fine (after
;; sourcing ~/.cargo/env) but we need to let cargo/rustc know where gcc is installed.
;; For this particular firmware we need to set the environment variables:
;; - CC (used by the rust package 'built')
;; - CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER (see https://doc.rust-lang.org/cargo/reference/config.html#targettriplelinker)
;; With these set one can simply:
;; - `guix shell` form this directory to load an environment with gcc-toolchain and the above
;; environment variables defined
;; - `sources ~/.cargo/env` to bring cargo into the environment
(use-modules (gnu packages)
(gnu packages commencement)
(guix packages)
(guix profiles))
;; Define a simple wrapper around the existing gcc-toolchain variable and extend the
;; search paths with our custom environment variables.
(define gcc-toolchain-with-rust-environment-variables
(package
(inherit gcc-toolchain)
(native-search-paths
(append (package-native-search-paths gcc-toolchain)
(list (search-path-specification ;based on the definition for the curl package
(variable "CC") ;in gnu/packages/curl.scm
(file-type 'regular)
(separator #f) ;single entry
(files '("bin/gcc")))
(search-path-specification
(variable "CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER")
(file-type 'regular)
(separator #f)
(files '("bin/gcc"))))))))
;; Use this modified gcc-toolchain variable in our manifest
(packages->manifest (list gcc-toolchain-with-rust-environment-variables))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment