Skip to content

Commit

Permalink
Merge pull request #6281 from JRMurr/nix-template-setup
Browse files Browse the repository at this point in the history
Add install docs for nix + fix `nix run` for using the roc cli
  • Loading branch information
Anton-4 authored Dec 15, 2023
2 parents 9ba7f0f + 7aa01fa commit 786dfe9
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 6 deletions.
22 changes: 17 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@
};

outputs = { self, nixpkgs, rust-overlay, flake-utils, nixgl, ... }@inputs:
let supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ];
in flake-utils.lib.eachSystem supportedSystems (system:
let
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ];

templates = import ./nix/templates { };
in
{ inherit templates; } //
flake-utils.lib.eachSystem supportedSystems (system:
let
overlays = [ (import rust-overlay) ]
++ (if system == "x86_64-linux" then [ nixgl.overlay ] else [ ]);
++ (if system == "x86_64-linux" then [ nixgl.overlay ] else [ ]);
pkgs = import nixpkgs { inherit system overlays; };

rocBuild = import ./nix { inherit pkgs; };
Expand Down Expand Up @@ -105,7 +110,7 @@

devShell = pkgs.mkShell {
buildInputs = sharedInputs ++ sharedDevInputs ++ darwinInputs ++ darwinDevInputs ++ linuxDevInputs
++ (if system == "x86_64-linux" then
++ (if system == "x86_64-linux" then
[ pkgs.nixgl.nixVulkanIntel ]
else
[ ]);
Expand All @@ -121,7 +126,7 @@
LD_LIBRARY_PATH = with pkgs;
lib.makeLibraryPath
([ pkg-config stdenv.cc.cc.lib libffi ncurses zlib ]
++ linuxDevInputs);
++ linuxDevInputs);
NIXPKGS_ALLOW_UNFREE =
1; # to run the GUI examples with NVIDIA's closed source drivers

Expand All @@ -143,5 +148,12 @@
cli = rocBuild.roc-cli;
lang-server = rocBuild.roc-lang-server;
};

apps = {
default = {
type = "app";
program = "${rocBuild.roc-cli}/bin/roc";
};
};
});
}
1 change: 1 addition & 0 deletions getting_started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ If you have a specific question, the [FAQ](../FAQ.md) might have an answer, alth
## Installation

- [🐧 Linux x86_64](linux_x86_64.md)
- [❄️ Nix Linux/MacOS](nix.md)
- [🍏 MacOS Apple Silicon](macos_apple_silicon.md)
- [🍏 MacOS x86_64](macos_x86_64.md)
- [🟦 Windows](windows.md)
Expand Down
48 changes: 48 additions & 0 deletions getting_started/nix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Try out

To quickly try out roc without installing, use `nix run`:
```shell
nix run roc-lang/roc -- <roc args>
# examples:
# - nix run roc-lang/roc -- repl
# - nix run roc-lang/roc -- dev main.roc
```

## Use with Flakes


### Start your project with our template

```shell
# use the template in the current directory
nix flake init --template github:roc-lang/roc#simple --refresh
```

### Add roc to existing flake
```nix
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
roc.url = "github:roc-lang/roc";
};
outputs = {nixpkgs, roc, flake-utils, ...}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
rocPkgs = roc.packages.${system};
in
{
devShells = {
default = pkgs.mkShell {
buildInputs = with pkgs;
[
rocPkgs.cli
];
};
};
}
);
}
```
9 changes: 9 additions & 0 deletions nix/builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ let
inherit (compile-deps) zigPkg llvmPkgs llvmVersion llvmMajorMinorStr glibcPath libGccSPath;

subPackagePath = if subPackage != null then "crates/${subPackage}" else null;

mainBin = if subPackage == "lang_srv" then "roc_ls" else "roc";
in
rustPlatform.buildRustPackage {
pname = "roc" + lib.optionalString (subPackage != null) "_${subPackage}";
Expand Down Expand Up @@ -84,4 +86,11 @@ rustPlatform.buildRustPackage {
${wrapRoc}
fi
'';

# https://ryantm.github.io/nixpkgs/stdenv/meta/
meta = {
homepage = "https://www.roc-lang.org/";
license = lib.licenses.upl;
mainProgram = mainBin;
};
}
7 changes: 7 additions & 0 deletions nix/templates/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ ... }: rec {
default = simple;
simple = {
description = "Basic flake with roc cli + lsp";
path = ./simple;
};
}
38 changes: 38 additions & 0 deletions nix/templates/simple/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
description = "Roc flake template";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
roc.url = "github:roc-lang/roc";
};

outputs = { self, nixpkgs, flake-utils, roc, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };

# see "packages =" in https://github.com/roc-lang/roc/blob/main/flake.nix
rocPkgs = roc.packages.${system};

rocFull = rocPkgs.full;

in
{
formatter = pkgs.nixpkgs-fmt;

devShells = {
default = pkgs.mkShell {
buildInputs = with pkgs;
[
rocFull # includes CLI
];

# For vscode plugin https://github.com/ivan-demchenko/roc-vscode-unofficial
shellHook = ''
export ROC_LSP_PATH=${rocFull}/bin/roc_ls
'';
};
};
});
}
3 changes: 2 additions & 1 deletion www/content/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Roc is a very young language with many incomplete features and known bugs. It do
There are currently a few known OS-specific issues:
* **macOS:** There are no known compatibility issues, but the compiler doesn't run as fast as it does on Linux or Windows, because we don't (yet) do our own linking like we do on those targets. (Linking works similarly on Linux and Windows, but the way macOS does it is both different and significantly more complicated.)
* **Windows:** There are some known Windows-specific compiler bugs, and probably some other unknown ones because more people have tried out Roc on Mac and Linux than on Windows.
* **Linux:** The nightlies are built with glibc, so they aren't usable on distros that don't use (dynamically linked) glibc, like Alpine or NixOS. In the future we plan to build Linux releases with [musl libc](https://wiki.musl-libc.org/) to address this, but this requires [building LLVM from source with musl](https://wiki.musl-libc.org/building-llvm.html).
* **Linux:** The nightlies are built with glibc, so they aren't usable on distros that don't use glibc, like Alpine. In the future we plan to build Linux releases with [musl libc](https://wiki.musl-libc.org/) to address this, but this requires [building LLVM from source with musl](https://wiki.musl-libc.org/building-llvm.html).
* **Other operating systems:** Roc has not been built on any other operating systems. [Building from source](https://github.com/roc-lang/roc/blob/main/BUILDING_FROM_SOURCE.md) on another OS might work, but you might very well be the first person ever to try it!

### [Getting Started](#getting-started) {#getting-started}
Expand All @@ -14,6 +14,7 @@ Here are some Getting Started guides for different operating systems:
<!-- TODO detect current OS with browser and only show link for that, provide other button for others -->

- [Linux x86-64](https://github.com/roc-lang/roc/blob/main/getting_started/linux_x86_64.md)
- [Nix Linux/MacOS](https://github.com/roc-lang/roc/blob/main/getting_started/nix.md)
- [MacOS Apple Silicon](https://github.com/roc-lang/roc/blob/main/getting_started/macos_apple_silicon.md)
- [MacOS x86-64](https://github.com/roc-lang/roc/blob/main/getting_started/macos_x86_64.md)
- [Windows](https://github.com/roc-lang/roc/blob/main/getting_started/windows.md)
Expand Down

0 comments on commit 786dfe9

Please sign in to comment.