Skip to content

DevInsideYou/scala-seed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is this?

This is an opinionated Nix flake for getting started with the Scala programming language. It creates a development subshell with the following Scala tools on the path:

As well as the following Scala.js dependencies:

As well as the following Scala Native dependencies:

In fact it can create alternative subshells with these instead:

The first time you use this subshell these tools will be downloaded and cached. Once you exit the subshell they will no longer be on your path. The second run is instantaneous.

Installation

  1. Install the Nix package manager by selecting your OS in the official guide. Don't forget to reopen the terminal!

  2. Enable the flakes feature:

    mkdir -p ~/.config/nix
    echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf

    If the Nix installation is in multi-user mode, don’t forget to restart the nix-daemon by running:

    sudo systemctl restart nix-daemon

Alternative unofficial installation

Taken from https://zero-to-nix.com/start/install

curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install

Usage

Use the default subshell (there is NO need to clone this repo) by running:

nix develop github:devinsideyou/scala-seed

For direnv/nix-direnv users put the following into your .envrc:

use flake github:devinsideyou/scala-seed

Pro tip: I will keep updating this flake so you might want to pin it to a specific commit:

nix develop github:devinsideyou/scala-seed/0c3b8c657b37eae320b073724d74390cf3162edf
use flake github:devinsideyou/scala-seed/0c3b8c657b37eae320b073724d74390cf3162edf

Alternative shells can be used as follows:

nix develop github:devinsideyou/scala-seed#java25 # the same as the default
nix develop github:devinsideyou/scala-seed#java21
nix develop github:devinsideyou/scala-seed#java17
nix develop github:devinsideyou/scala-seed#java11
nix develop github:devinsideyou/scala-seed#java8

Here is how you can see the metadata of the flake:

nix flake metadata github:devinsideyou/scala-seed

And here is how you can see everything the flake has to offer:

nix flake show github:devinsideyou/scala-seed --all-systems

Here is a useful incantation to pretty print a filtered list of what's on the path:

echo -e ${buildInputs// /\\n} | cut -d - -f 2- | sort

And here is another one that also shows the locations:

echo -e ${buildInputs// /\\n} | sort -t- -k2,2 -k3,3

And here is yet another one that shows everything Nix put on the path:

echo $PATH | sed 's/:/\n/g' | grep /nix/store | sort --unique -t- -k2,2 -k3,3

Just like any other subshell this one can be exited by typing exit or pressing Ctrl+D.

Watch on YouTube

Scala first steps

You can create your first Scala project straight from this flake — no dev shell required:

nix run github:devinsideyou/scala-seed # for Scala 3 (default)
nix run github:devinsideyou/scala-seed -- devinsideyou/scala-seed # for Scala 2

Important

If all you did so far was installing nix, enabling flakes and executing nix run from above, then for the following cd step to work you will need to run nix develop from the beginning of this doc after you cd into your newly created directory or even better use direnv (also described in this doc). In fact if you already had direnv installed and configured you will notice that the template you just used already comes with a preconfigured .envrc file that uses this flake as you will be prompted to run the direnv allow command.

Caution

Always check the .envrc before running direnv allow since it can run potentially destructive commands.

Now cd into your newly created project and launch sbt by typing sbt. The template you just used to create a project will display a couple of useful aliases for you to try. For instance r to run the program or t to run the tests. Type exit or press Ctrl+D when you are done to exit sbt. Don't forget that you are still inside of the Nix subshell so type exit or press Ctrl+D again to end up back in your regular shell.

Here is a Scala Crash Course and here is a Functional Programming Crash Course.

Ask questions on discord!

Welcome to Scala!

PS

Most Scala devs either use Intellij IDEA or the editors supported by Metals - a Scala language server.

This flake was tested in WSL 2 on Ubuntu-20.04 LTS and on an m2 Mac. Eventually I will set up CI to test on other systems. Please report issues until then. Thank you!

About

A Nix flake for getting started with Scala.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

 
 
 

Contributors

Languages