Skip to content

Commit

Permalink
Add flake for supporting NixOs and nix systems
Browse files Browse the repository at this point in the history
  • Loading branch information
brumik committed May 25, 2024
1 parent dced16f commit 863621d
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 3 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ test*.sh
flamegraph.svg

# MacOS
**/.DS_Store
**/.DS_Store

# Nixos
.direnv
result
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Programming language that compiles to Bash. It's a high level programming langua
Amber compiler currently works on:
- Linux x86 and ARM
- macOS x86 and ARM (Apple Silicon)
- Nix (NixOs)

### macOS / Linux
Make sure that the operating system meets the following prerequisites
Expand All @@ -37,6 +38,27 @@ Amber is packaged in the following distros:

Arch (AUR) - `amber-bash-bin`

#### Nix

The package is already containing all the required install scripts and dependencies. You can use the flake as:

```nix
{
inputs = {
# ...
amber.url = "github:brumik/ytsum";
};
# outputs somewhere
amber = inputs.amber.packages."${pkgs.system}".default;
# then later with home manager for example
home.packages = [ amber ];
}
```

While developing on Nixos the flake also defines all dependencies for `nix develop` (or `direnv` if used).

### Windows support
As windows does not come with bash installed it makes no sense to support it. Please install WSL 2 on your windows machine and install Linux version of Amber compiler inside.

Expand Down
7 changes: 7 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(import (
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }
) {
src = ./.;
}).defaultNix
95 changes: 95 additions & 0 deletions flake.lock

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

30 changes: 30 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
inputs = {
naersk.url = "github:nix-community/naersk/master";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, utils, naersk }:
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
naersk-lib = pkgs.callPackage naersk { };
in
{
defaultPackage = naersk-lib.buildPackage {
src = ./.;
postInsall = ''
wrapProgram "$out/bin/amber" --set PATH ${nixpkgs.lib.makeBinPath [
pkgs.bash
pkgs.bc
]}
'';
};
devShell = with pkgs; mkShell {
buildInputs = [ bc bash cargo rustc rustfmt pre-commit rustPackages.clippy ];
RUST_SRC_PATH = rustPlatform.rustLibSrc;
};
}
);
}
7 changes: 7 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(import (
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }
) {
src = ./.;
}).shellNix
4 changes: 2 additions & 2 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl AmberCompiler {

pub fn execute(code: String, flags: &[String]) {
let code = format!("set -- {};\n\n{}", flags.join(" "), code);
Command::new("/bin/bash").arg("-c").arg(code).spawn().unwrap().wait().unwrap();
Command::new("/usr/bin/env").arg("bash").arg("-c").arg(code).spawn().unwrap().wait().unwrap();
}

#[allow(dead_code)]
Expand All @@ -137,4 +137,4 @@ impl AmberCompiler {
include_str!("std/main.ab")
].join("\n")
}
}
}

0 comments on commit 863621d

Please sign in to comment.