From 1ff7eabedaed1ae2e4b0bd4e1791bbc48885e7d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20L=C3=A9tourneau?= Date: Thu, 29 Aug 2024 16:06:16 -0400 Subject: [PATCH] feat: improved dependency installation * install .NET framework locally * local recipes with https://just.systems/ * simplified installation instructions for macOS users --- README.md | 114 ++++++++++++++++++++++++----------------- template/.envrc | 4 ++ template/.gitignore | 1 + template/flake.lock | 6 +-- template/flake.nix | 4 +- template/global.json | 7 +++ template/justfile | 39 ++++++++++++++ template/start-code.sh | 14 ----- 8 files changed, 125 insertions(+), 64 deletions(-) create mode 100644 template/global.json create mode 100644 template/justfile delete mode 100755 template/start-code.sh diff --git a/README.md b/README.md index 1229aff..cc1884b 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 @@ -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. @@ -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). \ No newline at end of file +Be mindful of our [Code of Conduct](CODE_OF_CONDUCT.md). diff --git a/template/.envrc b/template/.envrc index 3550a30..b2578e4 100644 --- a/template/.envrc +++ b/template/.envrc @@ -1 +1,5 @@ use flake +export DOTNET_ROOT=$PWD/.dotnet +PATH_add .dotnet +PATH_add .dotnet/tools +just checkdotnet diff --git a/template/.gitignore b/template/.gitignore index 92b2793..a0b4522 100644 --- a/template/.gitignore +++ b/template/.gitignore @@ -1 +1,2 @@ .direnv +.dotnet diff --git a/template/flake.lock b/template/flake.lock index f48ca0b..fa59981 100644 --- a/template/flake.lock +++ b/template/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1724114134, - "narHash": "sha256-V/w5MIQy4jTG/L7/V/AL2BF5gSEWCfxHVDQdzLBCV18=", + "lastModified": 1724748588, + "narHash": "sha256-NlpGA4+AIf1dKNq76ps90rxowlFXUsV9x7vK/mN37JM=", "owner": "nixos", "repo": "nixpkgs", - "rev": "f02fa2f654c7bcc45f0e815c29d093da7f1245b4", + "rev": "a6292e34000dc93d43bccf78338770c1c5ec8a99", "type": "github" }, "original": { diff --git a/template/flake.nix b/template/flake.nix index c2103a9..1c28c2e 100644 --- a/template/flake.nix +++ b/template/flake.nix @@ -35,8 +35,9 @@ azure-cli.extensions.containerapp ]) coreutils - dotnet-sdk_8 + curl fd + just nil nixpkgs-fmt node2nix @@ -45,6 +46,7 @@ rnm sd terraform + wget yarn ]; }; diff --git a/template/global.json b/template/global.json new file mode 100644 index 0000000..68d4dad --- /dev/null +++ b/template/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "8.0.401", + "rollForward": "disable", + "workloadVersion": "8.0.401" + } +} diff --git a/template/justfile b/template/justfile new file mode 100644 index 0000000..6ad757f --- /dev/null +++ b/template/justfile @@ -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 diff --git a/template/start-code.sh b/template/start-code.sh deleted file mode 100755 index aea3bf6..0000000 --- a/template/start-code.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -# Ensure we start at the right place -cd "$( dirname "${BASH_SOURCE[0]}" )" - -# Eliminate environment variables introduced by the nix shell that interfere -# with Aspire debugging in VS Code. -export -n PYTHONPATH -export -n name -export -n shell - -export DOTNET_ROOT=`which dotnet | sed "s:/bin/dotnet$::"` - -code .