├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE ├── README.md ├── flake.lock ├── flake.nix ├── pkgs.nix └── resources └── thumbnail_youtube.jpg /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [devinsideyou] 4 | patreon: devinsideyou 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .direnv/ 2 | .env 3 | .envrc 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 DevInsideYou 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # What is this? 2 | This is an opinionated [Nix](https://nixos.org/) [flake](https://nixos.wiki/wiki/Flakes) for getting started with the [Scala](https://scala-lang.org/) programming language. It creates a development subshell with the following Scala tools on the path: 3 | 4 | * [Ammonite](https://ammonite.io/) 5 | * [Bloop](https://scalacenter.github.io/bloop/) 6 | * [Coursier](https://get-coursier.io/) 7 | * [GraalVM CE](https://www.graalvm.org/) based on [OpenJDK](https://openjdk.org/) 21 8 | * [Mill](https://com-lihaoyi.github.io/mill/mill/Intro_to_Mill.html) 9 | * [sbt](https://www.scala-sbt.org/) 10 | * [Scala CLI](https://scala-cli.virtuslab.org/) 11 | * [Scalafmt CLI](https://scalameta.org/scalafmt/) 12 | 13 | In fact it can create alternative subshells with these instead: 14 | * [Temurin](https://adoptium.net/temurin/releases/) 17 15 | * [Temurin](https://adoptium.net/temurin/releases/) 11 16 | * [OpenJDK](https://openjdk.org/) 8 17 | 18 | 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. 19 | 20 | # Installation 21 | 1. Install the Nix package manager by selecting your OS in the [official guide](https://nixos.org/download.html). Don't forget to reopen the terminal! 22 | 23 | 1. Enable the flakes feature: 24 | 25 | ```bash 26 | mkdir -p ~/.config/nix 27 | echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf 28 | ``` 29 | If the Nix installation is in multi-user mode, don’t forget to restart the `nix-daemon` by running: 30 | ```bash 31 | sudo systemctl restart nix-daemon 32 | ``` 33 | # Alternative unofficial installation 34 | Taken from https://zero-to-nix.com/start/install 35 | ```bash 36 | curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install 37 | ``` 38 | 39 | # Usage 40 | Use the default subshell (there is **NO** need to clone this repo) by running: 41 | ```bash 42 | nix develop github:devinsideyou/scala-seed 43 | ``` 44 | For [direnv](https://direnv.net/)/[nix-direnv](https://github.com/nix-community/nix-direnv) users put the following into your `.envrc`: 45 | ```bash 46 | use flake github:devinsideyou/scala-seed 47 | ``` 48 | **Pro tip**: I will keep updating this flake so you might want to pin it to a [specific commit](https://github.com/DevInsideYou/scala-seed/commits/main): 49 | ```bash 50 | nix develop github:devinsideyou/scala-seed/0c3b8c657b37eae320b073724d74390cf3162edf 51 | ``` 52 | ```bash 53 | use flake github:devinsideyou/scala-seed/0c3b8c657b37eae320b073724d74390cf3162edf 54 | ``` 55 | Alternative shells can be used as follows: 56 | ```bash 57 | nix develop github:devinsideyou/scala-seed#java21 # the same as the default 58 | ``` 59 | ```bash 60 | nix develop github:devinsideyou/scala-seed#java17 61 | ``` 62 | ```bash 63 | nix develop github:devinsideyou/scala-seed#java11 64 | ``` 65 | ```bash 66 | nix develop github:devinsideyou/scala-seed#java8 67 | ``` 68 | Here is how you can see the metadata of the flake: 69 | ```bash 70 | nix flake metadata github:devinsideyou/scala-seed 71 | ``` 72 | And here is how you can see everything the flake has to offer: 73 | ```bash 74 | nix flake show github:devinsideyou/scala-seed --all-systems 75 | ``` 76 | Here is a useful incantation to pretty print a filtered list of what's on the path: 77 | ```bash 78 | echo -e ${buildInputs// /\\n} | cut -d - -f 2- | sort 79 | ``` 80 | And here is another one that also shows the locations: 81 | ```bash 82 | echo -e ${buildInputs// /\\n} | sort -t- -k2,2 -k3,3 83 | ``` 84 | And here is yet another one that shows **everything** Nix put on the path: 85 | ```bash 86 | echo $PATH | sed 's/:/\n/g' | grep /nix/store | sort --unique -t- -k2,2 -k3,3 87 | ``` 88 | Just like any other subshell this one can be exited by typing `exit` or pressing `Ctrl+D`. 89 | 90 | [![Watch on YouTube](resources/thumbnail_youtube.jpg)](https://youtu.be/HnoP7JZn2MQ "Watch a Demo on YouTube!") 91 | 92 | # Scala first steps 93 | Now that you have a working dev environment you can create your first Scala project like this: 94 | 95 | ```bash 96 | cs launch giter8 -- devinsideyou/scala-seed # Scala 2 97 | ``` 98 | ```bash 99 | cs launch giter8 -- devinsideyou/scala3-seed # Scala 3 100 | ``` 101 | Now `cd` into your newly created project and launch [sbt](https://www.scala-sbt.org/) 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. 102 | 103 | Here is a [Scala Crash Course](https://www.youtube.com/watch?v=-xRfJcwhy7A) and here is a [Functional Programming Crash Course](https://www.youtube.com/watch?v=XXkYBncbz0c). 104 | 105 | Ask questions on [discord](http://discord.devinsideyou.com)! 106 | 107 | Welcome to Scala! 108 | 109 | PS 110 | 111 | Most Scala devs either use [Intellij IDEA](https://www.jetbrains.com/help/idea/discover-intellij-idea-for-scala.html) or the editors supported by [Metals](https://scalameta.org/metals/) - a Scala language server. 112 | 113 | This flake was tested in WSL 2 on Ubuntu-20.04 LTS, but it should work on Macs as well. I don't have a Mac, but I will set up CI eventually to test on them. Please report issues until then. Thank you! 114 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "flake-utils": { 4 | "inputs": { 5 | "systems": "systems" 6 | }, 7 | "locked": { 8 | "lastModified": 1731533236, 9 | "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", 10 | "owner": "numtide", 11 | "repo": "flake-utils", 12 | "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", 13 | "type": "github" 14 | }, 15 | "original": { 16 | "owner": "numtide", 17 | "repo": "flake-utils", 18 | "type": "github" 19 | } 20 | }, 21 | "nixpkgs": { 22 | "locked": { 23 | "lastModified": 1748980609, 24 | "narHash": "sha256-WGDbFDQDQtLZJG7AQ4e08qVJsZkqbA5pLuHSB/waZAs=", 25 | "owner": "nixos", 26 | "repo": "nixpkgs", 27 | "rev": "3d140585521cc2865583a8fe917ef58694a4a877", 28 | "type": "github" 29 | }, 30 | "original": { 31 | "owner": "nixos", 32 | "repo": "nixpkgs", 33 | "type": "github" 34 | } 35 | }, 36 | "nixpkgsForGraal": { 37 | "locked": { 38 | "lastModified": 1708457099, 39 | "narHash": "sha256-mwfR9G5JS5jhd7UUD1/MHLY3HKSSCmJY1t5sW/BRBx8=", 40 | "owner": "nixos", 41 | "repo": "nixpkgs", 42 | "rev": "1939434b4ae04cb855edec936573c778a9ddeab0", 43 | "type": "github" 44 | }, 45 | "original": { 46 | "owner": "nixos", 47 | "repo": "nixpkgs", 48 | "rev": "1939434b4ae04cb855edec936573c778a9ddeab0", 49 | "type": "github" 50 | } 51 | }, 52 | "root": { 53 | "inputs": { 54 | "flake-utils": "flake-utils", 55 | "nixpkgs": "nixpkgs", 56 | "nixpkgsForGraal": "nixpkgsForGraal" 57 | } 58 | }, 59 | "systems": { 60 | "locked": { 61 | "lastModified": 1681028828, 62 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 63 | "owner": "nix-systems", 64 | "repo": "default", 65 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 66 | "type": "github" 67 | }, 68 | "original": { 69 | "owner": "nix-systems", 70 | "repo": "default", 71 | "type": "github" 72 | } 73 | } 74 | }, 75 | "root": "root", 76 | "version": 7 77 | } 78 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "A flake for getting started with Scala."; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:nixos/nixpkgs"; 6 | nixpkgsForGraal.url = "github:nixos/nixpkgs?rev=1939434b4ae04cb855edec936573c778a9ddeab0"; 7 | flake-utils.url = "github:numtide/flake-utils"; 8 | }; 9 | 10 | outputs = { 11 | self, 12 | nixpkgs, 13 | nixpkgsForGraal, 14 | flake-utils, 15 | }: let 16 | supportedSystems = [ 17 | "aarch64-darwin" 18 | "aarch64-linux" 19 | "x86_64-linux" 20 | "x86_64-darwin" 21 | ]; 22 | in 23 | flake-utils.lib.eachSystem supportedSystems ( 24 | system: let 25 | pkgs = import ./pkgs.nix nixpkgs nixpkgsForGraal system; 26 | 27 | makeShell = p: 28 | p.mkShell { 29 | buildInputs = with p; [ 30 | ammonite 31 | bloop 32 | coursier 33 | jdk 34 | mill 35 | sbt 36 | scala-cli 37 | scalafmt 38 | ]; 39 | }; 40 | in { 41 | devShells = { 42 | default = makeShell pkgs.default; 43 | java21 = makeShell pkgs.pkgs21; 44 | java17 = makeShell pkgs.pkgs17; 45 | java11 = makeShell pkgs.pkgs11; 46 | java8 = makeShell pkgs.pkgs8; 47 | }; 48 | 49 | formatter = pkgs.default.alejandra; 50 | } 51 | ); 52 | } 53 | -------------------------------------------------------------------------------- /pkgs.nix: -------------------------------------------------------------------------------- 1 | nixpkgs: nixpkgsForGraal: system: let 2 | makeOverlays = java: graal: let 3 | ammoniteOverlay = final: prev: let 4 | pkgsForGraal = import nixpkgsForGraal { 5 | inherit system; 6 | }; 7 | in { 8 | ammonite = prev.ammonite.override { 9 | jre = 10 | if graal 11 | then pkgsForGraal.${java} 12 | else final.${java}; 13 | }; 14 | }; 15 | 16 | bloopOverlay = final: prev: { 17 | bloop = prev.bloop.override { 18 | jre = final.jre; 19 | }; 20 | }; 21 | 22 | millOverlay = final: prev: { 23 | mill = prev.mill.override { 24 | jre = final.jre; 25 | }; 26 | }; 27 | 28 | javaOverlay = final: _: let 29 | pkgsForGraal = import nixpkgsForGraal { 30 | inherit system; 31 | }; 32 | in { 33 | jdk = 34 | if graal 35 | then pkgsForGraal.${java} 36 | else final.${java}; 37 | 38 | jre = 39 | if graal 40 | then pkgsForGraal.${java} 41 | else final.${java}; 42 | }; 43 | 44 | scalaCliOverlay = _: prev: let 45 | pkgsForGraal = import nixpkgsForGraal { 46 | inherit system; 47 | }; 48 | in { 49 | scala-cli = prev.scala-cli.override { 50 | # hardcoded because scala-cli requires 17 or above 51 | jre = pkgsForGraal.graalvm-ce; 52 | }; 53 | }; 54 | in [ 55 | javaOverlay 56 | bloopOverlay 57 | scalaCliOverlay 58 | ammoniteOverlay 59 | millOverlay 60 | ]; 61 | 62 | makePackages = java: graal: let 63 | overlays = makeOverlays java graal; 64 | in 65 | import nixpkgs { 66 | inherit system overlays; 67 | }; 68 | 69 | default = pkgs21; 70 | pkgs21 = makePackages "graalvm-ce" true; 71 | pkgs17 = makePackages "temurin-bin-17" false; 72 | pkgs11 = makePackages "temurin-bin-11" false; 73 | pkgs8 = makePackages "openjdk8" false; 74 | in { 75 | inherit default pkgs21 pkgs17 pkgs11 pkgs8; 76 | } 77 | -------------------------------------------------------------------------------- /resources/thumbnail_youtube.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevInsideYou/scala-seed/4369286195f6a46e3e497518fb2f3748827ea680/resources/thumbnail_youtube.jpg --------------------------------------------------------------------------------