From c0c9ab15d1f9edccabb61444b8114469ea3337b1 Mon Sep 17 00:00:00 2001 From: Jaculabilis Date: Fri, 11 Feb 2022 23:44:40 -0800 Subject: [PATCH] Add dev shell configs --- README.md | 35 +++++++++++++++++++++++++++++++++++ flake.lock | 41 +++++++++++++++++++++++++++++++++++++++++ flake.nix | 18 +++++++++++------- 3 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 flake.lock diff --git a/README.md b/README.md index 370b41e..a5aca8a 100644 --- a/README.md +++ b/README.md @@ -30,4 +30,39 @@ $ git add flake.nix README.md $ git commit -m "Initial commit" $ git remote add origin gitea@git.alogoulogoi.com:Jaculabilis/5dplomacy.git $ git push -u origin master +``` + +We're doing this in .NET, so we need the .NET SDK. To do that, we're going to delcare a development environment in the flake config. + +``` + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in rec { + devShell = pkgs.mkShell { + packages = [ pkgs.dotnet-sdk ]; + }; + } + ); +``` + +Declaring `inputs.flake-utils` adds the `flake-utils` package as a dependency, which just gives us Nix helper functions. What's important here is that the `packages.x86_64-linux.hello` above has been abstracted away behind the `eachDefaultSystem` function: now we define our outputs with the `system` input as context, and flake-utils will define our outputs for each default system. + +Basically, stripping the boilerplate, we're just doing this: + +``` +rec { + devShell = pkgs.mkShell { + packages = [ pkgs.dotnet-sdk ]; + }; +} +``` + +`pkgs.mkShell` is the derivation builder that creates shell environments. It takes `packages` as a list of input packages that will be made available in the shell environment it creates. We add `dotnet-sdk` to this, commit the changes to git, and enter our new shell with `nix develop`: + +``` +$ which dotnet +/nix/store/87s452c8wj2zmy21q8q394f6rzf5y1br-dotnet-sdk-6.0.100/bin/dotnet ``` \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..118806a --- /dev/null +++ b/flake.lock @@ -0,0 +1,41 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1644486793, + "narHash": "sha256-EeijR4guVHgVv+JpOX3cQO+1XdrkJfGmiJ9XVsVU530=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1882c6b7368fd284ad01b0a5b5601ef136321292", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index 94f2327..2e569ff 100644 --- a/flake.nix +++ b/flake.nix @@ -1,11 +1,15 @@ { - description = "A very basic flake"; + description = "5D Diplomacy With Multiversal Time Travel"; - outputs = { self, nixpkgs }: { + inputs.flake-utils.url = "github:numtide/flake-utils"; - packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello; - - defaultPackage.x86_64-linux = self.packages.x86_64-linux.hello; - - }; + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in rec { + devShell = pkgs.mkShell { + packages = [ pkgs.dotnet-sdk ]; + }; + } + ); }