From a4368b5ddcba4823e792c68f51e8372ba170015e Mon Sep 17 00:00:00 2001 From: Artur Manuel Date: Wed, 26 Mar 2025 16:14:46 +0000 Subject: [PATCH] meta: refactor c and dotnet --- templates/c/flake.nix | 37 ++++------ templates/c/flake/default.nix | 12 +-- templates/c/flake/formatter.nix | 20 ++--- .../CHANGE_NAME.csproj} | 0 .../Program.cs | 2 +- ...JSchlattVideoGame.csproj.nuget.dgspec.json | 68 ----------------- .../JSchlattVideoGame.csproj.nuget.g.props | 15 ---- .../JSchlattVideoGame.csproj.nuget.g.targets | 2 - .../DotnetApplication/obj/project.assets.json | 73 ------------------- .../DotnetApplication/obj/project.nuget.cache | 8 -- templates/dotnet/flake.lock | 2 +- templates/dotnet/flake.nix | 51 +++++-------- .../{nix/derivation.nix => flake/package.nix} | 8 +- templates/dotnet/{nix => flake}/shell.nix | 7 ++ 14 files changed, 53 insertions(+), 252 deletions(-) rename templates/dotnet/{DotnetApplication/DotnetApplication.csproj => CHANGE_NAME/CHANGE_NAME.csproj} (100%) rename templates/dotnet/{DotnetApplication => CHANGE_NAME}/Program.cs (82%) delete mode 100644 templates/dotnet/DotnetApplication/obj/JSchlattVideoGame.csproj.nuget.dgspec.json delete mode 100644 templates/dotnet/DotnetApplication/obj/JSchlattVideoGame.csproj.nuget.g.props delete mode 100644 templates/dotnet/DotnetApplication/obj/JSchlattVideoGame.csproj.nuget.g.targets delete mode 100644 templates/dotnet/DotnetApplication/obj/project.assets.json delete mode 100644 templates/dotnet/DotnetApplication/obj/project.nuget.cache rename templates/dotnet/{nix/derivation.nix => flake/package.nix} (55%) rename templates/dotnet/{nix => flake}/shell.nix (55%) diff --git a/templates/c/flake.nix b/templates/c/flake.nix index c8044b1..ceaa6f5 100644 --- a/templates/c/flake.nix +++ b/templates/c/flake.nix @@ -1,28 +1,21 @@ { description = "REPLACE_DESC"; - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - }; + inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; }; - outputs = { - self, - nixpkgs, - }: let - inherit (nixpkgs) lib; - forAllSystems = f: - lib.genAttrs ["x86_64-linux" "aarch64-linux"] (system: - f { - pkgs = import nixpkgs { - inherit system; - }; - }); - in { - packages = forAllSystems ({pkgs}: { - default = pkgs.callPackage ./flake/default.nix {}; - REPLACE_ME = self.packages.${pkgs.system}.default; - }); + outputs = { self, nixpkgs, }: + let + inherit (nixpkgs) lib; + forAllSystems = f: + lib.genAttrs [ "x86_64-linux" "aarch64-linux" ] + (system: f { pkgs = import nixpkgs { inherit system; }; }); + in { + packages = forAllSystems ({ pkgs }: { + default = pkgs.callPackage ./flake/default.nix { }; + REPLACE_ME = self.packages.${pkgs.system}.default; + }); - formatter = forAllSystems ({pkgs}: pkgs.callPackage ./flake/formatter.nix {}); - }; + formatter = + forAllSystems ({ pkgs }: pkgs.callPackage ./flake/formatter.nix { }); + }; } diff --git a/templates/c/flake/default.nix b/templates/c/flake/default.nix index 59a80a3..f506116 100644 --- a/templates/c/flake/default.nix +++ b/templates/c/flake/default.nix @@ -1,9 +1,4 @@ -{ - stdenv, - lib, - meson, - ninja, -}: +{ stdenv, lib, meson, ninja, }: stdenv.mkDerivation { pname = "REPLACE_ME"; version = "1"; @@ -13,10 +8,7 @@ stdenv.mkDerivation { filter = path: _type: baseNameOf path != ".git"; }; - nativeBuildInputs = [ - meson - ninja - ]; + nativeBuildInputs = [ meson ninja ]; installPhase = '' mkdir -p $out/bin diff --git a/templates/c/flake/formatter.nix b/templates/c/flake/formatter.nix index 02b734f..7e835fa 100644 --- a/templates/c/flake/formatter.nix +++ b/templates/c/flake/formatter.nix @@ -1,20 +1,10 @@ -{ - writeShellApplication, - alejandra, - llvmPackages_19, - fd, -}: +{ writeShellApplication, nixfmt, deadnix, statix, llvmPackages_19, fd, }: writeShellApplication { name = "formatter"; - runtimeInputs = [ - alejandra - llvmPackages_19.clang-tools - fd - ]; + runtimeInputs = [ nixfmt deadnix statix llvmPackages_19.clang-tools fd ]; text = '' - fd --extension nix -X alejandra -- {} - fd --extension nix -X deadnix -e -- {} - fd --extension nix -x statix fix -- {} - fd --extension c -X clang-format --verbose -i -- {} + fd -e nix -X nixfmt {} \; -X deadnix -e {} + fd -e nix -x statix fix {} + fd -e c -e h -X clang-format --verbose -i {} ''; } diff --git a/templates/dotnet/DotnetApplication/DotnetApplication.csproj b/templates/dotnet/CHANGE_NAME/CHANGE_NAME.csproj similarity index 100% rename from templates/dotnet/DotnetApplication/DotnetApplication.csproj rename to templates/dotnet/CHANGE_NAME/CHANGE_NAME.csproj diff --git a/templates/dotnet/DotnetApplication/Program.cs b/templates/dotnet/CHANGE_NAME/Program.cs similarity index 82% rename from templates/dotnet/DotnetApplication/Program.cs rename to templates/dotnet/CHANGE_NAME/Program.cs index 760e08b..6e3a7f7 100644 --- a/templates/dotnet/DotnetApplication/Program.cs +++ b/templates/dotnet/CHANGE_NAME/Program.cs @@ -1,6 +1,6 @@ using System; -namespace DotnetApplication { +namespace CHANGE_NAME { class Program { static void Main(string[] args) { Console.WriteLine("Hello, world!"); diff --git a/templates/dotnet/DotnetApplication/obj/JSchlattVideoGame.csproj.nuget.dgspec.json b/templates/dotnet/DotnetApplication/obj/JSchlattVideoGame.csproj.nuget.dgspec.json deleted file mode 100644 index 32bac24..0000000 --- a/templates/dotnet/DotnetApplication/obj/JSchlattVideoGame.csproj.nuget.dgspec.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "format": 1, - "restore": { - "/home/artur/Projects/C#/JSchlattVideoGame/JSchlattVideoGame.csproj": {} - }, - "projects": { - "/home/artur/Projects/C#/JSchlattVideoGame/JSchlattVideoGame.csproj": { - "version": "1.0.0", - "restore": { - "projectUniqueName": "/home/artur/Projects/C#/JSchlattVideoGame/JSchlattVideoGame.csproj", - "projectName": "JSchlattVideoGame", - "projectPath": "/home/artur/Projects/C#/JSchlattVideoGame/JSchlattVideoGame.csproj", - "packagesPath": "/home/artur/.nuget/packages/", - "outputPath": "/home/artur/Projects/C#/JSchlattVideoGame/obj/", - "projectStyle": "PackageReference", - "configFilePaths": [ - "/home/artur/.nuget/NuGet/NuGet.Config" - ], - "originalTargetFrameworks": [ - "net9.0" - ], - "sources": { - "/nix/store/0w5k79zvjzingpnzz07ijqjbgsylcgfa-dotnet-sdk-9.0.100/share/dotnet/library-packs": {}, - "https://api.nuget.org/v3/index.json": {} - }, - "frameworks": { - "net9.0": { - "targetAlias": "net9.0", - "projectReferences": {} - } - }, - "warningProperties": { - "warnAsError": [ - "NU1605" - ] - }, - "restoreAuditProperties": { - "enableAudit": "true", - "auditLevel": "low", - "auditMode": "all" - }, - "SdkAnalysisLevel": "9.0.100" - }, - "frameworks": { - "net9.0": { - "targetAlias": "net9.0", - "imports": [ - "net461", - "net462", - "net47", - "net471", - "net472", - "net48", - "net481" - ], - "assetTargetFallback": true, - "warn": true, - "frameworkReferences": { - "Microsoft.NETCore.App": { - "privateAssets": "all" - } - }, - "runtimeIdentifierGraphPath": "/nix/store/0w5k79zvjzingpnzz07ijqjbgsylcgfa-dotnet-sdk-9.0.100/share/dotnet/sdk/9.0.100/PortableRuntimeIdentifierGraph.json" - } - } - } - } -} \ No newline at end of file diff --git a/templates/dotnet/DotnetApplication/obj/JSchlattVideoGame.csproj.nuget.g.props b/templates/dotnet/DotnetApplication/obj/JSchlattVideoGame.csproj.nuget.g.props deleted file mode 100644 index 2cac44f..0000000 --- a/templates/dotnet/DotnetApplication/obj/JSchlattVideoGame.csproj.nuget.g.props +++ /dev/null @@ -1,15 +0,0 @@ - - - - True - NuGet - $(MSBuildThisFileDirectory)project.assets.json - /home/artur/.nuget/packages/ - /home/artur/.nuget/packages/ - PackageReference - 6.12.0 - - - - - \ No newline at end of file diff --git a/templates/dotnet/DotnetApplication/obj/JSchlattVideoGame.csproj.nuget.g.targets b/templates/dotnet/DotnetApplication/obj/JSchlattVideoGame.csproj.nuget.g.targets deleted file mode 100644 index 3dc06ef..0000000 --- a/templates/dotnet/DotnetApplication/obj/JSchlattVideoGame.csproj.nuget.g.targets +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/templates/dotnet/DotnetApplication/obj/project.assets.json b/templates/dotnet/DotnetApplication/obj/project.assets.json deleted file mode 100644 index c348176..0000000 --- a/templates/dotnet/DotnetApplication/obj/project.assets.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "version": 3, - "targets": { - "net9.0": {} - }, - "libraries": {}, - "projectFileDependencyGroups": { - "net9.0": [] - }, - "packageFolders": { - "/home/artur/.nuget/packages/": {} - }, - "project": { - "version": "1.0.0", - "restore": { - "projectUniqueName": "/home/artur/Projects/C#/JSchlattVideoGame/JSchlattVideoGame.csproj", - "projectName": "JSchlattVideoGame", - "projectPath": "/home/artur/Projects/C#/JSchlattVideoGame/JSchlattVideoGame.csproj", - "packagesPath": "/home/artur/.nuget/packages/", - "outputPath": "/home/artur/Projects/C#/JSchlattVideoGame/obj/", - "projectStyle": "PackageReference", - "configFilePaths": [ - "/home/artur/.nuget/NuGet/NuGet.Config" - ], - "originalTargetFrameworks": [ - "net9.0" - ], - "sources": { - "/nix/store/0w5k79zvjzingpnzz07ijqjbgsylcgfa-dotnet-sdk-9.0.100/share/dotnet/library-packs": {}, - "https://api.nuget.org/v3/index.json": {} - }, - "frameworks": { - "net9.0": { - "targetAlias": "net9.0", - "projectReferences": {} - } - }, - "warningProperties": { - "warnAsError": [ - "NU1605" - ] - }, - "restoreAuditProperties": { - "enableAudit": "true", - "auditLevel": "low", - "auditMode": "all" - }, - "SdkAnalysisLevel": "9.0.100" - }, - "frameworks": { - "net9.0": { - "targetAlias": "net9.0", - "imports": [ - "net461", - "net462", - "net47", - "net471", - "net472", - "net48", - "net481" - ], - "assetTargetFallback": true, - "warn": true, - "frameworkReferences": { - "Microsoft.NETCore.App": { - "privateAssets": "all" - } - }, - "runtimeIdentifierGraphPath": "/nix/store/0w5k79zvjzingpnzz07ijqjbgsylcgfa-dotnet-sdk-9.0.100/share/dotnet/sdk/9.0.100/PortableRuntimeIdentifierGraph.json" - } - } - } -} \ No newline at end of file diff --git a/templates/dotnet/DotnetApplication/obj/project.nuget.cache b/templates/dotnet/DotnetApplication/obj/project.nuget.cache deleted file mode 100644 index f8e1195..0000000 --- a/templates/dotnet/DotnetApplication/obj/project.nuget.cache +++ /dev/null @@ -1,8 +0,0 @@ -{ - "version": 2, - "dgSpecHash": "1YIpH04Ngl4=", - "success": true, - "projectFilePath": "/home/artur/Projects/C#/JSchlattVideoGame/JSchlattVideoGame.csproj", - "expectedPackageFiles": [], - "logs": [] -} \ No newline at end of file diff --git a/templates/dotnet/flake.lock b/templates/dotnet/flake.lock index 7a552b1..697aa59 100644 --- a/templates/dotnet/flake.lock +++ b/templates/dotnet/flake.lock @@ -9,7 +9,7 @@ "narHash": "sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9", + "rev": "205b12d8b7cd4802fbcb8e8ef6aCHANGE_VER8781a4f9", "type": "github" }, "original": { diff --git a/templates/dotnet/flake.nix b/templates/dotnet/flake.nix index 249217f..1f70822 100644 --- a/templates/dotnet/flake.nix +++ b/templates/dotnet/flake.nix @@ -1,42 +1,27 @@ { inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - flake-parts.url = "github:hercules-ci/flake-parts"; + systems.url = "github:nix-systems/default"; }; - outputs = inputs @ { - self, - nixpkgs, - ... - }: - inputs.flake-parts.lib.mkFlake {inherit inputs;} { - systems = ["x86_64-linux"]; - flake.overlays.default = final: prev: { - dotnet-application = final.callPackage ./nix/derivation.nix {}; - }; - perSystem = { - pkgs, - system, - self', - ... - }: { - _module.args.pkgs = import nixpkgs { - inherit system; - overlays = [ - self.overlays.default - ]; - }; + outputs = + { + self, + nixpkgs, + systems + }: let + pkgsFor = nixpkgs.legacyPackages; + forAllSystems = f: nixpkgs.lib.genAttrs (import systems) (system: f system pkgsFor.${system}); + in { + packages = forAllSystems (system: pkgs: { + default = pkgs.callPackage ./flake/package.nix { }; + CHANGE_NAME = self.packages.${system}.default; + }); - packages = { - inherit (pkgs) dotnet-application; - default = self'.packages.dotnet-application; - }; + devShells = forAllSystems (_: pkgs: { + default = pkgs.callPackage ./flake/shell.nix { }; + }); - devShells.default = pkgs.mkShell { - packages = [ - pkgs.dotnetCorePackages.dotnet_9.sdk - ]; - }; - }; + formatter = forAllSystems (_: pkgs: pkgs.callPackage ./flake/formatter.nix { }); }; } diff --git a/templates/dotnet/nix/derivation.nix b/templates/dotnet/flake/package.nix similarity index 55% rename from templates/dotnet/nix/derivation.nix rename to templates/dotnet/flake/package.nix index 9cb5f34..6ba8b88 100644 --- a/templates/dotnet/nix/derivation.nix +++ b/templates/dotnet/flake/package.nix @@ -3,11 +3,11 @@ dotnetCorePackages, }: buildDotnetModule { - pname = "DotnetApplication"; - version = "0.1.0"; + pname = "CHANGE_NAME"; + version = "CHANGE_VER"; src = ../.; - projectFile = "DotnetApplication/DotnetApplication.csproj"; + projectFile = "CHANGE_NAME/CHANGE_NAME.csproj"; dotnet-sdk = dotnetCorePackages.dotnet_9.sdk; dotnet-runtime = dotnetCorePackages.dotnet_9.runtime; - executables = ["DotnetApplication"]; + executables = ["CHANGE_NAME"]; } diff --git a/templates/dotnet/nix/shell.nix b/templates/dotnet/flake/shell.nix similarity index 55% rename from templates/dotnet/nix/shell.nix rename to templates/dotnet/flake/shell.nix index 01e72da..1ce578a 100644 --- a/templates/dotnet/nix/shell.nix +++ b/templates/dotnet/flake/shell.nix @@ -1,9 +1,16 @@ { mkShell, dotnetCorePackages, + nixfmt, + deadnix, + statix, }: mkShell { + name = "dotnet"; packages = [ dotnetCorePackages.dotnet_9.sdk + nixfmt + deadnix + statix ]; }