Skip to content

Commit

Permalink
Document channel introductions
Browse files Browse the repository at this point in the history
TODOs

Fix func names

Remove data folder

add ci

move channel to subdirectory

fix ci

Fix ci

rustup from toolchain file

Fix README

fix channel directory
  • Loading branch information
declantsien committed May 22, 2024
1 parent 325d3e2 commit 7dfcde2
Show file tree
Hide file tree
Showing 59 changed files with 220 additions and 499 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use guix

export GUILE_LOAD_PATH="$(pwd):$HOME/.config/guix/current/share/guile/site/3.0"
export GUILE_LOAD_PATH="$(pwd)/guix:$HOME/.config/guix/current/share/guile/site/3.0"
export RUSTUP_DIST_SERVER="https://mirrors.ustc.edu.cn/rust-static"
64 changes: 64 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: build
on:
push:
paths-ignore:
- 'README.org'
- '.guix-authorizations'
- '.guix-channel'
pull_request:
schedule:
# weekly builds, making sure everything still works with guix-proper
- cron: '39 3 * * 0'
jobs:
build:
name: Build package
runs-on: ubuntu-latest
strategy:
# building independent packages, don’t abort entire build if one fails
fail-fast: false
matrix:
package:
- rust-bin
steps:
- name: Guix cache
uses: actions/cache@v2
with:
path: ~/.cache/guix
# use a key that (almost) never matches
key: guix-cache-${{ github.sha }}
restore-keys: |
guix-cache-
- name: Install Guix
uses: PromyLOPh/guix-install-action@v1
with:
channels: |-
(list (channel
(name 'guix)
(url "https://github.com/declantsien/guix")
(branch "master")
(introduction
(make-channel-introduction
"9edb3f66fd807b096b48283debdcddccfea34bad"
(openpgp-fingerprint
"BBB0 2DDF 2CEA F6A8 0D1D E643 A2A0 6DF2 A33A 54FA"))))
(channel
(name 'nonguix)
(url "https://gitlab.com/nonguix/nonguix")
(branch "master")
(introduction
(make-channel-introduction
"897c1a470da759236cc11798f4e0a5f7d4d59fbc"
(openpgp-fingerprint
"2A39 3FFF 68F4 EF7A 3D29 12AF 6F51 20A0 22FB B2D5")))))
- name: Checkout
uses: actions/checkout@v2
- name: Lint package
run: |
GUIX_PROFILE="/home/runner/.config/guix/current"
. "$GUIX_PROFILE/etc/profile"
guix lint -L ./channel ${{ matrix.package }} |& sed -nre 's#(.*):([0-9]+):([0-9]+): (.*)$#::warning file=\1,line=\2,col=\3::\4#gp'
- name: Build package
run: |
GUIX_PROFILE="/home/runner/.config/guix/current"
. "$GUIX_PROFILE/etc/profile"
guix build -L ./channel ${{ matrix.package }}
47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: test
on: [push]
jobs:
build-with-channels:
name: Test as Guix channel
runs-on: ubuntu-latest
strategy:
# building independent packages, don’t abort entire build if one fails
fail-fast: false
steps:
- name: Guix cache
uses: actions/cache@v3
with:
path: ~/.cache/guix
# use a key that (almost) never matches
key: guix-cache-${{ github.sha }}
restore-keys: |
guix-cache-
# Cannot use a cache for /gnu/store, since restore fails
- name: Install Guix
id: install-guix
uses: PromyLOPh/guix-install-action@v1
with:
channels: |-
(list (channel
(name 'guix)
(url "https://github.com/declantsien/guix")
(branch "master")
(introduction
(make-channel-introduction
"9edb3f66fd807b096b48283debdcddccfea34bad"
(openpgp-fingerprint
"BBB0 2DDF 2CEA F6A8 0D1D E643 A2A0 6DF2 A33A 54FA"))))
(channel
(name 'rustup)
(url "https://github.com/declantsien/guix-rustup")
(introduction
(make-channel-introduction
"325d3e2859d482c16da21eb07f2c6ff9c6c72a80"
(openpgp-fingerprint
"F695 F39E C625 E081 33B5 759F 0FC6 8703 75EF E2F5")))))
- name: Build
run: guix build rust-bin
- name: Build
run: guix build -e '((@@ (rustup build toolchain) rustup) "1.78.0")'
- name: Build
run: guix build -e '((@@ (rustup build toolchain) rustup) "nightly-2024-05-13")'
2 changes: 1 addition & 1 deletion .guix-channel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

(channel
(version 0)
(directory ".")
(directory "guix")
(url "https://github.com/declantsien/guix-rustup")
(dependencies
(channel
Expand Down
30 changes: 30 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#+TITLE: Guix Rustup
#+OPTIONS: d:nil
#+EXPORT_FILE_NAME: guix-rustup.texi
#+TEXINFO_DIR_CATEGORY: Guix Channels
#+TEXINFO_DIR_TITLE: Guix Rustup: (guix-rustup).
#+TEXINFO_DIR_DESC: Rust binary toolchain channel for Guix

https://forge.rust-lang.org/infra/channel-layout.html
https://forge.rust-lang.org/infra/other-installation-methods.html

* Overview

Guix Rustup

** Channel introduction
In case you want to use this channel, add the following code to
your ~~/.config/guix/channels.scm~, and call ~guix pull~.
#+begin_src scheme
(cons*
(channel
(name 'rustup)
(url "https://github.com/declantsien/guix-rustup")
(introduction
(make-channel-introduction
"325d3e2859d482c16da21eb07f2c6ff9c6c72a80"
(openpgp-fingerprint
"F695 F39E C625 E081 33B5 759F 0FC6 8703 75EF E2F5"))))
%default-channels)
#+end_src

1 change: 1 addition & 0 deletions TODO.org
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* TODO Add Github action to automaticlly update channels
1 change: 0 additions & 1 deletion data/aliases

This file was deleted.

1 change: 0 additions & 1 deletion data/channels

This file was deleted.

26 changes: 10 additions & 16 deletions rustup/build/manifest.scm → guix/rustup/build/manifest.scm
Original file line number Diff line number Diff line change
Expand Up @@ -493,24 +493,18 @@
(define channel-hash-file-hash
(let* ((content (http-fetch/guarded sha256-url)))
(if content
(base32-from-sha256 (car (string-split
content
#\ )))
(car (string-split
content
#\ ))
(begin
(format #t "Failed to download manifest sha256 ~a ~a~%" sha256-url str)
#f))))
(if channel-hash-file-hash
(let* ((%store (open-connection))
(drv (url-fetch* %store url 'sha256 (nix-base32-string->bytevector channel-hash-file-hash)))
(out-path (derivation->output-path drv)))
(and (build-derivations %store (list drv))
(file-exists? out-path)
(valid-path? %store out-path)
(call-with-input-file out-path
(lambda (port)
(let* ((content (get-string-all port)))
(parse-toml content))))))
#f))
(let* ((content (http-fetch/guarded url channel-hash-file-hash)))
(if content
(parse-toml content)
(begin
(format #t "Failed to download manifest toml ~a ~a~%" url str)
#f))))

(define* (compact-manifest str #:optional manifest)
(define c (channel->from-str str))
Expand Down Expand Up @@ -581,7 +575,7 @@
component-hashed-binaries
components)))

(let* ((manifest (or manifest (download-channel-manifest str))))
(let* ((manifest (or manifest (download-manifest str))))
(compact-manifest manifest)))

(define* (validate-url-pattern component-name-index triplet-index compression-kind-index hash uri-triplet-index channel-name date url)
Expand Down
File renamed without changes.
93 changes: 58 additions & 35 deletions rustup/build/toolchain.scm → guix/rustup/build/toolchain.scm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.

(define-module (rustup build toolchain)
#:use-module (guix ui)
#:use-module (rnrs enums)
#:use-module (guix http-client)
#:use-module (web uri)
Expand Down Expand Up @@ -111,9 +112,9 @@
(default #f)))

(define* (toolchain->new channel-str
#:optional
#:key
(components (list ))
(triplets (list ))
(targets (list ))
(profile 'default))
(define _ (channel-str? channel-str))
(toolchain-profile? profile)
Expand All @@ -122,11 +123,11 @@
(G_ "components should be a list, was given: ~a")
components)))
(for-each %toolchain-components? components)
(unless (list? triplets)
(unless (list? targets)
(raise (formatted-message
(G_ "targets should be a list, was given: ~a")
triplets)))
(for-each %rustc-target-triplets? triplets)
targets)))
(for-each %rustc-target-triplets? targets)
(define alias (find (lambda (alias)
(string= (channel-str-normalize channel-str) (symbol->string (car alias))))
(module-ref (resolve-module '(rustup dist)) 'aliases)))
Expand Down Expand Up @@ -180,7 +181,7 @@
channel-str
(map %rustc-target-triplets->get available-cross-triplets)
triplet))))
(for-each cross-target-available? triplets)
(for-each cross-target-available? targets)

(define profile-components
(case profile
Expand Down Expand Up @@ -215,7 +216,7 @@
(define cross-sources (filter
(lambda (target)
(member (car target)
(map %rustc-target-triplets->position triplets)))
(map %rustc-target-triplets->position targets)))
available-cross-targets))

(define all-sources (delete-duplicates
Expand Down Expand Up @@ -245,7 +246,7 @@

`(,version . ,hashed-binary-urls))

(define* (toolchain->from-file file)
(define* (parse-rust-toolchain-file file)
(let* ((content (call-with-input-file file get-string-all))
(toml (catch #t
(lambda () (parse-toml content))
Expand All @@ -263,8 +264,11 @@
(profile (recursive-assoc-ref
toml
`("toolchain" "profile"))))
(toolchain->new channel components targets profile))
(toolchain->new (string-trim-right content #\newline)))))
(list channel
#:components components
#:targets targets
#:profile profile))
(list (string-trim-right content #\newline)))))

(define* (toolchain->version t)
(let ((manifest (toolchain->manifest t)))
Expand All @@ -276,25 +280,28 @@
#\ ))
(toolchain->channel t))))

(define* (rustup channel
(define* (rustup #:optional (channel-or-toolchain-file #f)
#:key
(components (list ))
(targets (list ))
(profile 'default))

(let* ((t (toolchain->new channel components targets profile))
(version (car t))
(sources (cdr t))
(source (car sources))
(other-sources (cdr sources)))
(let ((args (match (and channel-or-toolchain-file (basename channel-or-toolchain-file))
((or "rust-toolchain" "rust-toolchain.toml" #f)
(args-from-default-toolchain-file channel-or-toolchain-file))
(_ (list channel-or-toolchain-file
#:components components
#:targets targets
#:profile profile)))))
(display args)
(make-rust-bin (apply toolchain->new args))))

(define* (make-rust-bin aggregated)
(let ((version (car aggregated))
(sources (cdr aggregated)))
(package
(name "rust-bin")
(version version)
(source (origin
(method url-fetch)
(uri (car source))
(sha256
(base32 (cdr source)))))
(source #f)
(build-system binary-build-system)
(inputs
(append
Expand All @@ -307,15 +314,15 @@
(uri (car source))
(sha256
(base32 (cdr source))))))
other-sources)))
sources)))
(native-inputs (list `(,gcc "lib")))
(arguments
(list
#:strip-binaries? #t
#:validate-runpath? #f
#:phases
#~(modify-phases %standard-phases
(add-after 'unpack 'copy-dist
(replace 'unpack
(lambda* (#:key inputs #:allow-other-keys)
(for-each
(lambda (input)
Expand Down Expand Up @@ -394,17 +401,33 @@ safety and thread safety guarantees.")
(license (list license:asl2.0 license:expat)))
))

(define* (rust-from-toolchain channel
#:optional
(components (list ))
(targets (list ))
(profile "default"))
(let ((toolchain (toolchain->new channel components targets profile)))
(rustup toolchain)))

(define* (rust-from-toolchain-file file)
(let ((toolchain (toolchain->from-file file)))
(rustup toolchain)))
;; Copied (guix scripts shell)
(define (find-file-in-parent-directories candidates)
"Find one of CANDIDATES in the current directory or one of its ancestors."
(define start (getcwd))
(define device (stat:dev (stat start)))

(let loop ((directory start))
(let ((stat (stat directory)))
(and (= (stat:uid stat) (getuid))
(= (stat:dev stat) device)
(or (any (lambda (candidate)
(let ((candidate (string-append directory "/" candidate)))
(and (file-exists? candidate) candidate)))
candidates)
(and (not (string=? directory "/"))
(loop (dirname directory)))))))) ;lexical ".." resolution

(define* (args-from-default-toolchain-file #:optional (file #f))
(let ((file (or file (find-file-in-parent-directories '("rust-toolchain.toml" "rust-toolchain")))))
(match file
(#f
(warning (G_ "no toolchain specified; using stable channel~%"))
(list "stable"))
(file
(begin
(info (G_ "loading toolchain from '~a'...~%") file)
(parse-rust-toolchain-file file))))))

(define* (select-latest-nightly-with file)
;; Select the latest nightly toolchain which have specific components or profile available.This helps nightly users in case of latest nightly may not contains all components they want.
Expand Down
Loading

0 comments on commit 7dfcde2

Please sign in to comment.