diff --git a/Northwind.DataContext.Sqlite/NorthwindContext.cs b/Northwind.DataContext.Sqlite/NorthwindContext.cs index 5e708aa..ae1aa7c 100644 --- a/Northwind.DataContext.Sqlite/NorthwindContext.cs +++ b/Northwind.DataContext.Sqlite/NorthwindContext.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; @@ -39,9 +39,9 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) string dir = Environment.CurrentDirectory; string path = string.Empty; - if (dir.EndsWith("net8.0")) + if (dir.EndsWith("net9.0")) { - // In the /bin//net8.0 directory. + // In the /bin//net9.0 directory. path = Path.Combine("..", "..", "..", "..", database); } else diff --git a/Northwind.DataContext.Sqlite/package.nix b/Northwind.DataContext.Sqlite/package.nix new file mode 100644 index 0000000..dc355ed --- /dev/null +++ b/Northwind.DataContext.Sqlite/package.nix @@ -0,0 +1,20 @@ +{ + pkgs, + dotnet-sdk, + dotnet-runtime, +}: +pkgs.buildDotnetModule { + name = "northwind-data-context"; + src = ./.; + nugetDeps = ../deps.json; + buildType = "Release"; + packNupkg = true; + inherit dotnet-sdk dotnet-runtime; + projectReferences = [ + import + ../northwind.entitymodels.sqlite + { + inherit pkgs dotnet-sdk dotnet-runtime; + } + ]; +} diff --git a/Northwind.EntityModels.Sqlite/package.nix b/Northwind.EntityModels.Sqlite/package.nix new file mode 100644 index 0000000..0a0250c --- /dev/null +++ b/Northwind.EntityModels.Sqlite/package.nix @@ -0,0 +1,13 @@ +{ + pkgs, + dotnet-sdk, + dotnet-runtime, +}: +pkgs.buildDotnetModule { + name = "northwind-entity-models"; + src = ./.; + nugetDeps = ../deps.json; + inherit dotnet-sdk dotnet-runtime; + buildType = "Release"; + packNupkg = true; +} diff --git a/Northwind.Mvc/package.nix b/Northwind.Mvc/package.nix new file mode 100644 index 0000000..f3411b7 --- /dev/null +++ b/Northwind.Mvc/package.nix @@ -0,0 +1,21 @@ +{ + pkgs, + dotnet-sdk, + dotnet-runtime, +}: +pkgs.buildDotnetModule { + name = "northwind-mvc"; + src = ./.; + nugetDeps = ../deps.json; + buildType = "Release"; + executables = [ "Northwind.Mvc" ]; + inherit dotnet-sdk dotnet-runtime; + projectReferences = [ + import + ../northwind.data-context.sqlite + { inherit pkgs dotnet-sdk dotnet-runtime; } + import + ../northwind.entitymodels.sqlite + { inherit pkgs dotnet-sdk dotnet-runtime; } + ]; +} diff --git a/Northwind.UnitTests/package.nix b/Northwind.UnitTests/package.nix new file mode 100644 index 0000000..48423af --- /dev/null +++ b/Northwind.UnitTests/package.nix @@ -0,0 +1,21 @@ +{ + pkgs, + dotnet-sdk, + dotnet-runtime, +}: +pkgs.buildDotnetModule { + name = "northwind-unittests"; + src = ./.; + nugetDeps = ../deps.json; + buildType = "Release"; + doCheck = true; + inherit dotnet-sdk dotnet-runtime; + projectReferences = [ + import + ../northwind.data-context.sqlite + { inherit pkgs dotnet-sdk dotnet-runtime; } + import + ../northwind.entitymodels.sqlite + { inherit pkgs dotnet-sdk dotnet-runtime; } + ]; +} diff --git a/Northwind.Web/package.nix b/Northwind.Web/package.nix new file mode 100644 index 0000000..6551005 --- /dev/null +++ b/Northwind.Web/package.nix @@ -0,0 +1,21 @@ +{ + pkgs, + dotnet-sdk, + dotnet-runtime, +}: +pkgs.buildDotnetModule { + name = "northwind-web"; + src = ./.; + nugetDeps = ../deps.json; + buildType = "Release"; + executables = [ "Northwind.Web" ]; + inherit dotnet-sdk dotnet-runtime; + projectReferences = [ + import + ../northwind.data-context.sqlite + { inherit pkgs dotnet-sdk dotnet-runtime; } + import + ../northwind.entitymodels.sqlite + { inherit pkgs dotnet-sdk dotnet-runtime; } + ]; +} diff --git a/Northwind.WebApi/package.nix b/Northwind.WebApi/package.nix new file mode 100644 index 0000000..d79fa4f --- /dev/null +++ b/Northwind.WebApi/package.nix @@ -0,0 +1,21 @@ +{ + pkgs, + dotnet-sdk, + dotnet-runtime, +}: +pkgs.buildDotnetModule { + name = "northwind-webapi"; + src = ./.; + nugetDeps = ../deps.json; + buildType = "Release"; + executables = [ "Northwind.WebApi" ]; + inherit dotnet-sdk dotnet-runtime; + projectReferences = [ + import + ../northwind.data-context.sqlite + { inherit pkgs dotnet-sdk dotnet-runtime; } + import + ../northwind.entitymodels.sqlite + { inherit pkgs dotnet-sdk dotnet-runtime; } + ]; +} diff --git a/README.md b/README.md index 8fea240..2465455 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,6 @@ Tools used: - [Nix](https://srid.ca/haskell-nix) + [Flakes](https://serokell.io/blog/practical-nix-flakes) - [devenv](https://devenv.sh/) and [direnv](https://direnv.net/) for development shell - [just](https://just.systems/) as a task runner; run `just` in devshell -- [nuget-packageslock2nix](https://github.com/mdarocha/nuget-packageslock2nix) for generating `nuget` dependency lock files for nix - [csharpier](https://github.com/belav/csharpier) for opinionated code formatting of C# - [treefmt](https://github.com/numtide/treefmt-nix) for formatting of all code on the pipeline (C# and nix) @@ -37,11 +36,11 @@ Simply run the following command from the root of the project: $ nix develop --impure ``` -This will install a .NET SDK in version 8 and all other required dependencies in a completely isolated way (they will not interfere +This will install a .NET SDK in version 9 and all other required dependencies in a completely isolated way (they will not interfere with any system installations of .NET SDK or any other software). -For even better ergonomics, install [direnv](https://direnv.net/) using your favourite package manager. After that, just `cd` into the directory. -(Note that you might have to run `direnv allow` inside the directory once.) +For even better ergonomics, install [direnv](https://direnv.net/) using your favourite package manager. After that, just `cd` into the directory +and run `direnv allow` to enable the automatic shell hook. When using `vscode` or `emacs`, use the corresponding `direnv` extension: - [direnv for VSCode](https://marketplace.visualstudio.com/items?itemName=mkhl.direnv) diff --git a/flake.lock b/flake.lock index e895fce..a234825 100644 --- a/flake.lock +++ b/flake.lock @@ -37,11 +37,11 @@ "nixpkgs": "nixpkgs_3" }, "locked": { - "lastModified": 1744477385, - "narHash": "sha256-2zsUfDPzJG+L30soukmDSKCeCohIVtE820mZOEdXCD8=", + "lastModified": 1744902663, + "narHash": "sha256-rXtUUxfQ34ukTy2OyHwuypnSgK95FRPGwJf69QnWMrc=", "owner": "cachix", "repo": "devenv", - "rev": "2c37aeb5ab035e8e690599c5ea692f8519d42c4a", + "rev": "379980fb42ca804f7c3220d978d9da86360a68fa", "type": "github" }, "original": { @@ -292,11 +292,11 @@ "nixpkgs": "nixpkgs_5" }, "locked": { - "lastModified": 1743748085, - "narHash": "sha256-uhjnlaVTWo5iD3LXics1rp9gaKgDRQj6660+gbUU3cE=", + "lastModified": 1744961264, + "narHash": "sha256-aRmUh0AMwcbdjJHnytg1e5h5ECcaWtIFQa6d9gI85AI=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "815e4121d6a5d504c0f96e5be2dd7f871e4fd99d", + "rev": "8d404a69efe76146368885110f29a2ca3700bee6", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index cfee080..8300cb6 100644 --- a/flake.nix +++ b/flake.nix @@ -35,106 +35,45 @@ system: let pkgs = import nixpkgs { inherit system; }; + dotnet-sdk = pkgs.dotnet-sdk_9; + dotnet-runtime = pkgs.dotnet-runtime_9; + in rec { devenv-up = self.devShells.${system}.default.config.procfileScript; - entity-models = pkgs.buildDotnetModule { - name = "northwind-entity-models"; - src = ./northwind.entitymodels.sqlite; - - nugetDeps = ./deps.json; - - dotnet-sdk = pkgs.dotnet-sdk_9; - dotnet-runtime = pkgs.dotnet-runtime_9; - - packNupkg = true; + web = import ./northwind.web/package.nix { + inherit pkgs dotnet-sdk dotnet-runtime; }; - data-context = pkgs.buildDotnetModule { - name = "northwind-data-context"; - src = ./northwind.datacontext.sqlite; - - nugetDeps = ./deps.json; - - projectReferences = [ entity-models ]; - - dotnet-sdk = pkgs.dotnet-sdk_9; - dotnet-runtime = pkgs.dotnet-runtime_9; - - packNupkg = true; + webapi = import ./northwind.webapi/package.nix { + inherit pkgs dotnet-sdk dotnet-runtime; }; - web = pkgs.buildDotnetModule { - name = "northwind-web"; - src = ./northwind.web; - - nugetDeps = ./deps.json; - - projectReferences = [ - data-context - entity-models - ]; - - dotnet-sdk = pkgs.dotnet-sdk_9; - dotnet-runtime = pkgs.dotnet-runtime_9; - - buildType = "Release"; - - executables = [ "Northwind.Web" ]; + mvc = import ./northwind.mvc/package.nix { + inherit pkgs dotnet-sdk dotnet-runtime; }; - webapi = pkgs.buildDotnetModule { - name = "northwind-webapi"; - src = ./northwind.webapi; - - nugetDeps = ./deps.json; - - projectReferences = [ - data-context - entity-models - ]; - - dotnet-sdk = pkgs.dotnet-sdk_9; - dotnet-runtime = pkgs.dotnet-runtime_9; - - buildType = "Release"; - - executables = [ "Northwind.WebApi" ]; - }; - - mvc = pkgs.buildDotnetModule { - name = "northwind-mvc"; - src = ./northwind.mvc; - - nugetDeps = ./deps.json; - - projectReferences = [ - data-context - entity-models - ]; - - dotnet-sdk = pkgs.dotnet-sdk_9; - dotnet-runtime = pkgs.dotnet-runtime_9; - - buildType = "Release"; - - executables = [ "Northwind.Mvc" ]; - }; } ); apps = forEachSystem (system: { - web = mkApp (self.packages.${system}.web) "Northwind.Web"; - webapi = mkApp (self.packages.${system}.webapi) "Northwind.WebApi"; - mvc = mkApp (self.packages.${system}.mvc) "Northwind.Mvc"; + web = mkApp self.packages.${system}.web "Northwind.Web"; + webapi = mkApp self.packages.${system}.webapi "Northwind.WebApi"; + mvc = mkApp self.packages.${system}.mvc "Northwind.Mvc"; }); devShells = forEachSystem ( system: let pkgs = nixpkgs.legacyPackages.${system}; + dotnet-sdk = + with pkgs.dotnetCorePackages; + combinePackages [ + sdk_9_0-bin + sdk_8_0-bin + ]; in { @@ -150,7 +89,7 @@ just # task runner sqlite # sqlite3 db for now - dotnet-sdk_9 # .NET SDK version 9 + dotnet-sdk nuget-to-json ]; @@ -163,7 +102,7 @@ ''; enterShell = '' - export DOTNET_ROOT=${pkgs.dotnet-sdk_9}/share/dotnet + export DOTNET_ROOT=${dotnet-sdk}/share/dotnet cowsay "Welcome to .NET dev shell" | lolcat ''; } @@ -178,25 +117,14 @@ system: let pkgs = import nixpkgs { inherit system; }; + dotnet-sdk = pkgs.dotnet-sdk_9; + dotnet-runtime = pkgs.dotnet-runtime_9; + in { formatting = treefmtEval.${system}.config.build.check self; - unit-tests = pkgs.stdenv.mkDerivation { - name = "northwind-unittests"; - src = ./.; - nativeBuildInputs = with pkgs; [ dotnet-sdk_9 ]; - buildInputs = with pkgs; [ dotnet-sdk_9 ]; - doCheck = true; - checkPhase = '' - dotnet test - ''; - - buildPhase = '' - # make compile - ''; - installPhase = '' - mkdir -p $out/bin - ''; + unittests = import ./northwind.unittests/package.nix { + inherit pkgs dotnet-sdk dotnet-runtime; }; } );