From 590f40139ff88e469597ef5c47fc4985da605dc6 Mon Sep 17 00:00:00 2001 From: Micah Kendall Date: Sat, 7 Jan 2023 22:05:49 +1100 Subject: [PATCH] Add support for Nix flakes. This relies on Cargo2Nix, and because we don't want to be maintaining that file by hand, we introduce a new continuous workflow to automatically update the generated Cargo.nix and submit a PR whenever something is merged into master. This should make the process of supporting Nix bearable. We'll re-assess in a while. Co-authored-by: KtorZ --- .gitattributes | 3 + .github/workflows/nix.yml | 38 +++++++++ README.md | 4 +- flake.lock | 164 ++++++++++++++++++++++++++++++++++++++ flake.nix | 54 +++++++++++++ 5 files changed, 261 insertions(+), 2 deletions(-) create mode 100644 .gitattributes create mode 100644 .github/workflows/nix.yml create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..e701a2b1 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +Cargo.lock linguist-generated=true merge=binary linguist-vendored +Cargo.nix linguist-generated=true merge=binary linguist-vendored +flake.lock linguist-generated=true merge=binary linguist-vendored diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 00000000..556cd515 --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,38 @@ +name: Nix + +on: + push: + branches: [ "main" ] + +jobs: + update-cargo-nix: + runs-on: ubuntu-latest + + permissions: + pull-requests: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Nix + uses: cachix/install-nix-action@v18 + + - name: Setup Cachix + uses: cachix/cachix-action@v12 + with: + name: aiken-lang + authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} + + - name: Run cargo2nix + shell: bash + run: | + nix run github:cargo2nix/cargo2nix -- -s > Cargo.nix + + - name: Create PR + uses: peter-evans/create-pull-request@v4 + with: + branch: patch/cargo.nix + delete-branch: true + title: Update Cargo.nix + add-paths: Cargo.nix diff --git a/README.md b/README.md index cef3e19b..dda9cba7 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,7 @@ For now you'll need rust installed, see [rustup](https://rustup.rs). In case you have fresh installation of `rustup` you might need to do: ```console - rustup install stable - ``` ```console @@ -33,6 +31,8 @@ $ cargo install --git https://github.com/aiken-lang/aiken.git $ aiken --help ``` +Alternatively nix builds are available via [flakes](https://aiken-lang.org/getting-started#from-nix-flakes). + ### How to use For more information please see the [user manual](https://aiken-lang.org). diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..eab2e2fc --- /dev/null +++ b/flake.lock @@ -0,0 +1,164 @@ +{ + "nodes": { + "cargo2nix": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1655189312, + "narHash": "sha256-gpJ57OgIebUpO+7F00VltxSEy6dz2x6HeJ5BcRM8rDA=", + "owner": "cargo2nix", + "repo": "cargo2nix", + "rev": "c149357cc3d17f2849c73eb7a09d07a307cdcfe8", + "type": "github" + }, + "original": { + "owner": "cargo2nix", + "ref": "release-0.11.0", + "repo": "cargo2nix", + "type": "github" + } + }, + "devshell": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1671489820, + "narHash": "sha256-qoei5HDJ8psd1YUPD7DhbHdhLIT9L2nadscp4Qk37uk=", + "owner": "numtide", + "repo": "devshell", + "rev": "5aa3a8039c68b4bf869327446590f4cdf90bb634", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1653893745, + "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1642700792, + "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1654275867, + "narHash": "sha256-pt14ZE4jVPGvfB2NynGsl34pgXfOqum5YJNpDK4+b9E=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "7a20c208aacf4964c19186dcad51f89165dc7ed0", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "release-22.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1643381941, + "narHash": "sha256-pHTwvnN4tTsEKkWlXQ8JMY423epos8wUOhthpwJjtpc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5efc8ca954272c4376ac929f4c5ffefcc20551d5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "cargo2nix": "cargo2nix", + "devshell": "devshell", + "flake-utils": [ + "cargo2nix", + "flake-utils" + ], + "nixpkgs": [ + "cargo2nix", + "nixpkgs" + ] + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "cargo2nix", + "flake-utils" + ], + "nixpkgs": [ + "cargo2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1653878966, + "narHash": "sha256-T51Gck/vrJZi1m+uTbhEFTRgZmE59sydVONadADv358=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "8526d618af012a923ca116be9603e818b502a8db", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..7ac6f52b --- /dev/null +++ b/flake.nix @@ -0,0 +1,54 @@ +# This setup relies on 'Cargo.nix' to be up-to-date. +# +# It can be re-generated using: +# +# nix run github:cargo2nix/cargo2nix +# +{ + inputs = { + cargo2nix.url = "github:cargo2nix/cargo2nix/release-0.11.0"; + flake-utils.follows = "cargo2nix/flake-utils"; + nixpkgs.follows = "cargo2nix/nixpkgs"; + devshell.url = "github:numtide/devshell"; + }; + + outputs = { self, cargo2nix, nixpkgs, flake-utils, devshell }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ cargo2nix.overlays.default devshell.overlay ]; + }; + + rustPkgs = pkgs.rustBuilder.makePackageSet { + rustVersion = "1.61.0"; + packageFun = import ./Cargo.nix; + }; + + commonCategory = y: builtins.map (x: x // { category = y; }); + + packages = { + aiken = (rustPkgs.workspace.aiken { }).bin; + default = packages.aiken; + }; + + aikenCmds = commonCategory "Aiken Development" [ + { + name = "aiken"; + help = "Aiken toolchain"; + package = packages.aiken; + } + ]; + + in rec { + inherit packages; + devShell = pkgs.devshell.mkShell { + name = "aiken"; + motd = ''Aiken + $(type -p menu &>/dev/null && menu)''; + commands = aikenCmds; + }; + devShells.aiken = devShell; + } + ); +}