Skip to content

Commit

Permalink
Merge pull request #32 from SnO2WMaN/nix-flake
Browse files Browse the repository at this point in the history
Add Nix support for reproducible build and develop
  • Loading branch information
mtshiba authored Aug 17, 2022
2 parents a039f7f + f0805f7 commit 34a2529
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

use flake
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Auto detect text files and perform LF normalization
* text=auto

flake.lock linguist-generated=true
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk
Expand All @@ -15,4 +15,8 @@ Cargo.lock
/.DS_Store
/*/.DS_Store
/.idea/
/timeit.dat
/timeit.dat

# Nix
.direnv
result
31 changes: 31 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,24 @@ Building from source code requires the Rust toolchain.
git clone https://github.com/erg-lang/erg.git
cd erg
cargo build --release
```

### Building by Nix

If you've been installed [Nix](https://nixos.org/), the following command will be generate binary into `result/bin/erg` under the project.

```sh
git clone https://github.com/erg-lang/erg.git
cd erg
nix-build
```

If you've been enabled [Nix Flakes](https://nixos.wiki/wiki/Flakes).

```sh
git clone https://github.com/erg-lang/erg.git
cd erg
nix build
```

## Contribution
Expand Down
18 changes: 18 additions & 0 deletions README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,24 @@ cd erg
cargo build --release
```

### Nixによるビルド

[Nix](https://nixos.org/)をインストールしているなら,次のコマンドでプロジェクト直下の`result/bin/erg`にバイナリが生成されます.

```sh
git clone https://github.com/erg-lang/erg.git
cd erg
nix-build
```

[Nix Flakes](https://nixos.wiki/wiki/Flakes)を有効化している場合は次のコマンドでも良いです.

```sh
git clone https://github.com/erg-lang/erg.git
cd erg
nix build
```

## コントリビューション

コントリビューション(プロジェクトへの貢献、協力)はいつでも歓迎しています!
Expand Down
12 changes: 12 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(
import
(
fetchTarball
(with (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.flake-compat.locked; {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
})
)
{src = ./.;}
)
.defaultNix
111 changes: 111 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
description = "Nix Flake for Erg Programming Language";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

# develop
devshell.url = "github:numtide/devshell";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = {
self,
nixpkgs,
devshell,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [
devshell.overlay
];
};
cargoToml = with builtins; (fromTOML (readFile ./Cargo.toml));

inherit (pkgs) lib;
in {
packages.erg = pkgs.rustPlatform.buildRustPackage {
inherit (cargoToml.package) name version;
src = builtins.path {
path = ./.;
filter = name: type:
(name == toString ./Cargo.toml)
|| (name == toString ./Cargo.lock)
|| (lib.hasPrefix (toString ./compiler) name)
|| (lib.hasPrefix (toString ./src) name);
};
cargoLock.lockFile = ./Cargo.lock;
};
packages.default = self.packages.${system}.erg;

devShells.default = pkgs.devshell.mkShell {
packages = with pkgs; [
gcc
rustc
cargo
# Dev
python3
treefmt # cli to run all formatters
alejandra # Nix formatter
# rustfmt # Rust Formatter
# taplo-cli # TOML formatter
];
};

checks = {
erg = self.packages.${system}.erg;
};
}
);
}
12 changes: 12 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(
import
(
fetchTarball
(with (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.flake-compat.locked; {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
})
)
{src = ./.;}
)
.shellNix
12 changes: 12 additions & 0 deletions treefmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[formatter.alejandra]
command = "alejandra"
includes = ["*.nix"]

# [formatter.taplo]
# command = "taplo"
# options = ["format"]
# includes = ["*.toml"]

# [formatter.rustfmt]
# command = "rustfmt"
# includes = ["*.rs"]

0 comments on commit 34a2529

Please sign in to comment.