Skip to content

Commit

Permalink
feat: improved dependency installation
Browse files Browse the repository at this point in the history
* install .NET framework locally
* local recipes with https://just.systems/
* simplified installation instructions for macOS users
  • Loading branch information
GabrielLetourneau committed Sep 4, 2024
1 parent d8b2021 commit 1ff7eab
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 64 deletions.
114 changes: 68 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
This repository contains a template to seed a repository for an Open Source
project.

## How to use this template

1. Check out this repository
2. Delete the `.git` folder
3. Git init this repository and start working on your project!
4. Prior to submitting your request for publication, make sure to review the
Prior to submitting your request for publication, make sure to review the
[Open Source guidelines for publications](https://nventive.visualstudio.com/Internal/_wiki/wikis/Internal_wiki?wikiVersion=GBwikiMaster&pagePath=%2FOpen%20Source%2FPublishing&pageId=7120).

## Features (to keep as-is, configure or remove)
Expand All @@ -31,56 +26,83 @@ The following is the template for the final README.md file:
The main prerequisites for a developer setup are:
- either Linux (including WSL) or macOS as OS;
- the Nix package manager with flakes enabled;
- [direnv](https://direnv.net/) and [nix-direnv](https://github.com/nix-community/nix-direnv);
- direnv and nix-direnv;
- Docker;
- Visual Studio Code with the C# DevKit extension for debugging;
- an Azure account to deploy and run in the cloud.

> ### For WSL Users
> - If you’re using Docker Desktop, remember to [enable it in your WSL distro](https://docs.docker.com/desktop/wsl/#enabling-docker-support-in-wsl-2-distros)
> - VS Code extensions must be activated in WSL.
> - The ASP.NET Core developement certificate installed in WSL must be trusted in your Windows browser.
Precise installations instructions are as follow:

> ### Steps to trust the ASP.NET Core development certificate used in WSL
> 1. Install the .NET SDK in Windows [whichever way you want](https://learn.microsoft.com/en-us/dotnet/core/install/windows).
> 1. Install and activate the ASP.NET Core development certificate (`[password]` being any password you’ll remember in the next minute). In Windows:
> ```console
> dotnet dev-certs https --clean
> dotnet dev-certs https --trust
> dotnet dev-certs https -ep https.pfx -p [password]
> ```
> 3. Restart your browser to make sure it trusts the new certificate.
> 3. Import the certificate in WSL and trust it for inter-service communications (`[path]` being the path to the windows directory you executed the previous commands, and `[password]` being the password entered previously):
> ```console
> sudo apt install dotnet-sdk-8.0
> dotnet dev-certs https --clean --import /mnt/c/[path]/https.pfx --password [password]
> sudo -E dotnet dev-certs https -ep /usr/local/share/ca-certificates/aspnet/https.crt --format PEM
> sudo update-ca-certificates
>```
### For WSL Users
- If you’re using Docker Desktop, remember to [enable it in your WSL distro](https://docs.docker.com/desktop/wsl/#enabling-docker-support-in-wsl-2-distros)
- VS Code extensions must be activated in WSL.
- The ASP.NET Core developement certificate installed in WSL must be trusted in your Windows browser.

Then you need to trust the ASP.NET Core development certificate.

1. Install the .NET SDK in Windows [whichever way you want](https://learn.microsoft.com/en-us/dotnet/core/install/windows).
1. Install and activate the ASP.NET Core development certificate (`[password]` being any password you’ll remember in the next minute). In Windows:
```console
dotnet dev-certs https --clean
dotnet dev-certs https --trust
dotnet dev-certs https -ep https.pfx -p [password]
```
3. Restart your browser to make sure it trusts the new certificate.
3. Import the certificate in WSL and trust it for inter-service communications (`[path]` being the path to the windows directory you executed the previous commands, and `[password]` being the password entered previously):
```console
sudo apt install dotnet-sdk-8.0
dotnet dev-certs https --clean --import /mnt/c/[path]/https.pfx --password [password]
sudo -E dotnet dev-certs https -ep /usr/local/share/ca-certificates/aspnet/https.crt --format PEM
sudo update-ca-certificates
```

### For macOS and straight Linux users

ASP.NET Core development certificate is more simple.

1. [Install a .NET SDK](https://learn.microsoft.com/en-us/dotnet/core/install/).
2. Install and activate the ASP.NET Core development certificate
```console
dotnet dev-certs https --clean
dotnet dev-certs https --trust
```

### Steps to install Nix, direnv
### For all OSes: install Nix, direnv

Use the [Determinate Nix installer](https://github.com/DeterminateSystems/nix-installer):
```console
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
```

For direnv, the best way would be [via home-manager](https://github.com/nix-community/nix-direnv?tab=readme-ov-file#via-home-manager), if you have [home-manager](https://nix-community.github.io/home-manager/).
Follow any instructions, including those necessary to get nix in path.

> ### WSL Method
> 1. Install direnv (tested with Ubuntu 24.04 in WSL).
> ```console
> sudo apt install direnv
> ```
> 2. [Hook direnv into your shell](https://direnv.net/docs/hook.html). For bash this means adding the following line in your `~/.bashrc`:
1. Install direnv.
```console
nix profile install nixpkgs#nix-direnv
```
2. [Hook direnv into your shell](https://direnv.net/docs/hook.html).

> For bash this means adding the following line in your `~/.bashrc`:
> ```bash
> eval "$(direnv hook bash)"
> ```
> Don’t forget to reload your bash.
> For zsh (macOS), the file is `~/.zshrc` and the line is
> ```zsh
> eval "$(direnv hook zsh)"
> ```
3. Don’t forget to reload your shell
> ```console
> source ~/.bashrc
> ```
> 4. Install nix-direnv in your user Nix profile and hook it up to direnv.
>
> or
> ```console
> source ~/.zshrc
> ```
4. Install nix-direnv in your user Nix profile and hook it up to direnv.
> ```console
> nix profile install nixpkgs#nix-direnv
> source $HOME/.nix-profile/share/nix-direnv/direnvrc
Expand All @@ -93,27 +115,27 @@ For direnv, the best way would be [via home-manager](https://github.com/nix-comm
git checkout https://github.com/nventive/cloud-template.git
```
2. Copy the template to wherever you want to have it and enable the development shell. **Warning:** the last step may take a while, as it’s downloading/building all tools and dependencies.
2. Copy the template to wherever you want to have it and enable the development shell (you can replace `MyProject` with whatever you want). **Warning:** the last step may take a while, as it’s downloading/building all tools and dependencies.
```console
cp -r cloud-template/template MyProject
cd MyProject
direnv allow
```

3. Install the Aspire .NET workload. *TODO: [use local install](https://discourse.nixos.org/t/dotnet-maui-workload/20370/13) as soon as .NET SDK 8.0.40x is in nixpkgs*
3. Rename the project according to your inspirations (`Placeholder` is the actual string to be replaced; `MyProject` can be whatever you want).
```console
$ sudo `which dotnet` workload install aspire
fd Placeholder | tac | xargs rnm -rs '/Placeholder/MyProject/g' -y
fd --hidden --type file --exec sd Placeholder MyProject
```

4. Rename the project according to your inspirations (`Placeholder` is the actual string to be replaced).
4. Start VS Code. NB: it has to be started this way to ensure the correct .NET frawework is found and debugging works.
```console
fd Placeholder | tac | xargs rnm -rs '/Placeholder/MyProject/g' -y
fd --hidden --type file --exec sd Placeholder MyProject
just code
```

5. Start VS Code. NB: it has to be started this way to ensure the correct .NET frawework is found and debugging works.
To get a list of other recipes:
```console
./start-code.sh
just --list
```

Further instructions are in the `README` of your new project.
Expand All @@ -137,4 +159,4 @@ This project is licensed under the Apache 2.0 license - see the
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the process for
contributing to this project.

Be mindful of our [Code of Conduct](CODE_OF_CONDUCT.md).
Be mindful of our [Code of Conduct](CODE_OF_CONDUCT.md).
4 changes: 4 additions & 0 deletions template/.envrc
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
use flake
export DOTNET_ROOT=$PWD/.dotnet
PATH_add .dotnet
PATH_add .dotnet/tools
just checkdotnet
1 change: 1 addition & 0 deletions template/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.direnv
.dotnet
6 changes: 3 additions & 3 deletions template/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion template/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
azure-cli.extensions.containerapp
])
coreutils
dotnet-sdk_8
curl
fd
just
nil
nixpkgs-fmt
node2nix
Expand All @@ -45,6 +46,7 @@
rnm
sd
terraform
wget
yarn
];
};
Expand Down
7 changes: 7 additions & 0 deletions template/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "8.0.401",
"rollForward": "disable",
"workloadVersion": "8.0.401"
}
}
39 changes: 39 additions & 0 deletions template/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env just --justfile

dotnet_version := "8.0.401"

set shell := ["bash", "-c"]

# run the project locally (same as "run")
default: run

# starts VS Code with appropriate environment variables to allow for debugging
code: checkdotnet
#!/usr/bin/env bash
# Eliminate environment variables introduced by the nix shell that interfere
# with Aspire debugging in VS Code. See https://github.com/dotnet/aspire/issues/5389 and
# https://github.com/dotnet/aspire/issues/5475
export -n DIRENV_DIFF
export -n NIX_CFLAGS_COMPILE
export -n NIX_LDFLAGS
export -n PYTHONPATH
export -n name
export -n shell
code .
# install .NET locally if it’s not there
checkdotnet:
[ -d .dotnet ] && [[ "$(dotnet --version)" == "{{dotnet_version}}" ]] || just installdotnet

# install the appropriate .NET version locally
installdotnet:
[ ! -d .dotnet ] || rm -r .dotnet
wget https://dot.net/v1/dotnet-install.sh
chmod +x dotnet-install.sh
./dotnet-install.sh --version {{dotnet_version}} --install-dir .dotnet --no-path
rm dotnet-install.sh
dotnet workload install aspire

# run the project locally
run: checkdotnet
dotnet run --project src/Placeholder.AppHost
14 changes: 0 additions & 14 deletions template/start-code.sh

This file was deleted.

0 comments on commit 1ff7eab

Please sign in to comment.