Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flake for supporting NixOs and nix systems #110

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
brumik marked this conversation as resolved.
Show resolved Hide resolved
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)
brumik marked this conversation as resolved.
Show resolved Hide resolved

### 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:
brumik marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grammar: package is not "is already containing", it "contains"


```nix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is all that info really necessary? if thats just a package, you should mention it with one line under the "Via package manager" header:

Nix - amber-lang

if you really need this info, you could wrap it in a dropdown box so it doesnt take up much space

like this
<details>
<summary>Title</summary>

### Put stuff here
</details>

im just saying that not every amber user is a nix user. they don't need this information.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also nothing is preventing you from creating a NIX.md file near README.md with the necessary instructions

{
inputs = {
# ...
amber.url = "github:brumik/ytsum";
brumik marked this conversation as resolved.
Show resolved Hide resolved
};

# outputs somewhere
amber = inputs.amber.defaultPackage."${pkgs.system}";

# then later with home manager for example
home.packages = [ amber ];
brumik marked this conversation as resolved.
Show resolved Hide resolved
}
```

While developing on Nixos the flake also defines all dependencies for `nix develop` (or `direnv` if used).
brumik marked this conversation as resolved.
Show resolved Hide resolved

### 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
brumik marked this conversation as resolved.
Show resolved Hide resolved
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could add an overlay above the nixpkgs package amber-lang

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";
Comment on lines +3 to +5

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see much point in adding flake-utils or naersk. But it's fine, we can certainly add them.

};

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
brumik marked this conversation as resolved.
Show resolved Hide resolved
pkgs.bc
]}
'';
};
brumik marked this conversation as resolved.
Show resolved Hide resolved
devShell = with pkgs; mkShell {
brumik marked this conversation as resolved.
Show resolved Hide resolved
buildInputs = [ bc bash cargo rustc rustfmt pre-commit rustPackages.clippy ];
RUST_SRC_PATH = rustPlatform.rustLibSrc;
};
}
);
}
7 changes: 7 additions & 0 deletions shell.nix
brumik marked this conversation as resolved.
Show resolved Hide resolved
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();
brumik marked this conversation as resolved.
Show resolved Hide resolved
}

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