diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..3550a30f --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 6068420a..aa10c085 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,8 @@ test*.sh flamegraph.svg # MacOS -**/.DS_Store \ No newline at end of file +**/.DS_Store + +# Nixos +.direnv +result diff --git a/README.md b/README.md index 0035c15c..ff944765 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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.defaultPackage."${pkgs.system}"; + + # 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. diff --git a/default.nix b/default.nix new file mode 100644 index 00000000..39bacff6 --- /dev/null +++ b/default.nix @@ -0,0 +1,7 @@ +(import ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } +) { + src = ./.; +}).defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..74bbcf03 --- /dev/null +++ b/flake.lock @@ -0,0 +1,95 @@ +{ + "nodes": { + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1713520724, + "narHash": "sha256-CO8MmVDmqZX2FovL75pu5BvwhW+Vugc7Q6ze7Hj8heI=", + "owner": "nix-community", + "repo": "naersk", + "rev": "c5037590290c6c7dae2e42e7da1e247e54ed2d49", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "master", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1716619601, + "narHash": "sha256-9dUxZf8MOqJH3vjbhrz7LH4qTcnRsPSBU1Q50T7q/X8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "47e03a624662ce399e55c45a5f6da698fc72c797", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1716619601, + "narHash": "sha256-9dUxZf8MOqJH3vjbhrz7LH4qTcnRsPSBU1Q50T7q/X8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "47e03a624662ce399e55c45a5f6da698fc72c797", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..32252b1d --- /dev/null +++ b/flake.nix @@ -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; + }; + } + ); +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 00000000..77db547f --- /dev/null +++ b/shell.nix @@ -0,0 +1,7 @@ +(import ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } +) { + src = ./.; +}).shellNix diff --git a/src/compiler.rs b/src/compiler.rs index 0bb5afd6..50ed9419 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -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)] @@ -137,4 +137,4 @@ impl AmberCompiler { include_str!("std/main.ab") ].join("\n") } -} \ No newline at end of file +}