diff --git a/templates/go/.envrc b/templates/go/.envrc new file mode 100644 index 0000000..bc49353 --- /dev/null +++ b/templates/go/.envrc @@ -0,0 +1 @@ +use flake .# diff --git a/templates/go/flake.lock b/templates/go/flake.lock index 124a788..d5567ad 100644 --- a/templates/go/flake.lock +++ b/templates/go/flake.lock @@ -18,7 +18,23 @@ }, "root": { "inputs": { - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" } } }, diff --git a/templates/go/flake.nix b/templates/go/flake.nix index 715e90d..90aa8ba 100644 --- a/templates/go/flake.nix +++ b/templates/go/flake.nix @@ -1,38 +1,27 @@ { - description = "Go flake template"; + description = "CHANGE DESC"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + systems.url = "github:nix-systems/default"; }; - outputs = { - self, - nixpkgs, - }: let - allSystems = [ - "x86_64-linux" - "aarch64-linux" - ]; - forAllSystems = f: - nixpkgs.lib.genAttrs allSystems (system: - f { - pkgs = import nixpkgs {inherit system;}; - inherit system; - }); - in { - packages = forAllSystems ({ - pkgs, - system, - }: { - default = pkgs.callPackage ./nix/package.nix {}; - go-app = self.packages.${system}.default; - }); + outputs = { self, nixpkgs, systems, }: + let + inherit (nixpkgs) lib; + pkgsFor = nixpkgs.legacyPackages; + forAllSystems = f: + 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; + }); - devShells = forAllSystems ({ - pkgs, - system, - }: { - default = pkgs.callPackage ./nix/shell.nix {inherit (self.packages.${system}) go-app;}; - }); - }; + devShells = forAllSystems + (_: pkgs: { default = pkgs.callPackage ./flake/shell.nix { }; }); + + formatter = + forAllSystems (_: pkgs: pkgs.callPackage ./flake/formatter.nix { }); + }; } diff --git a/templates/go/flake/formatter.nix b/templates/go/flake/formatter.nix new file mode 100644 index 0000000..f088272 --- /dev/null +++ b/templates/go/flake/formatter.nix @@ -0,0 +1,10 @@ +{ writeShellApplication, fd, nixfmt, deadnix, statix, go }: +writeShellApplication { + name = "linter"; + runtimeInputs = [ fd nixfmt deadnix statix go ]; + text = '' + fd -e nix -X nixfmt {} \; -X deadnix -e {} \; + fd -e nix -x statix fix {} \; + fd -e rs -X go fmt {} \; -X go vet {} \; + ''; +} diff --git a/templates/go/nix/package.nix b/templates/go/flake/package.nix similarity index 55% rename from templates/go/nix/package.nix rename to templates/go/flake/package.nix index 09b5221..a0b8079 100644 --- a/templates/go/nix/package.nix +++ b/templates/go/flake/package.nix @@ -1,9 +1,8 @@ { buildGoModule }: let - pname = "go-app"; - version = "0.1.0"; -in -buildGoModule { + pname = "CHANGE_ME"; + version = "CHANGE_VER"; +in buildGoModule { inherit pname version; src = ../.; vendorHash = null; diff --git a/templates/go/flake/shell.nix b/templates/go/flake/shell.nix new file mode 100644 index 0000000..f5e8adb --- /dev/null +++ b/templates/go/flake/shell.nix @@ -0,0 +1,9 @@ +{ mkShell, go, gopls, go-tools }: +mkShell { + name = "go"; + packages = [ + go + gopls + go-tools + ]; +} diff --git a/templates/go/go.mod b/templates/go/go.mod index ee8d795..3d4d07c 100644 --- a/templates/go/go.mod +++ b/templates/go/go.mod @@ -1,3 +1,3 @@ -module codeberg.org/amadaluzia/go-app +module codeberg.org/amadaluzia/CHANGE_ME go 1.22.5 diff --git a/templates/go/main.go b/templates/go/main.go index d1b1d77..9b4f148 100644 --- a/templates/go/main.go +++ b/templates/go/main.go @@ -29,14 +29,14 @@ func GetResponse() (*http.Response, error) { for attempts != 0 { res, err = http.Get(url) if err != nil { - fmt.Fprintln(os.Stderr, "Error encountered... trying again...") + fmt.Fprintln(os.Stderr, "error encountered... trying again") time.Sleep(2 * time.Second) attempts-- continue } if res.StatusCode != 200 { - fmt.Fprintf(os.Stderr, "API returned but a 200, so I will be running this again in a few seconds.") + fmt.Fprintf(os.Stderr, "the API returned but a 200, so I will be running this again in a few seconds") time.Sleep(2 * time.Second) attempts-- continue @@ -52,7 +52,7 @@ func GetResponse() (*http.Response, error) { } if res.StatusCode != 200 { - return nil, errors.New("Gave up attempting to get 200.") + return nil, errors.New("gave up attempting to get 200") } return res, nil @@ -73,10 +73,8 @@ func GetBodyFromResponse(res *http.Response) ([]byte, error) { func NewQuoteFromBody(body []byte) (Quote, error) { var quote Quote - var err error - - err = json.Unmarshal(body, "e) - if err != nil { + + if err := json.Unmarshal(body, "e); err != nil { return Quote{}, err } diff --git a/templates/go/nix/shell.nix b/templates/go/nix/shell.nix deleted file mode 100644 index b4a1f67..0000000 --- a/templates/go/nix/shell.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ mkShell, go, go-app, gopls, go-tools, gotools }: -mkShell { - name = "Gopherborough"; - inputsFrom = [ go-app ]; - buildInputs = [ - go - gopls - go-tools - gotools - ]; -} diff --git a/templates/nim/.envrc b/templates/nim/.envrc new file mode 100644 index 0000000..bc49353 --- /dev/null +++ b/templates/nim/.envrc @@ -0,0 +1 @@ +use flake .# diff --git a/templates/nim/CHANGE_NAME.nimble b/templates/nim/CHANGE_NAME.nimble new file mode 100644 index 0000000..6111a43 --- /dev/null +++ b/templates/nim/CHANGE_NAME.nimble @@ -0,0 +1,14 @@ +# Package + +version = "CHANGE_VER" +author = "Artur Manuel" +description = "CHANGE DESC" +license = "BSD-3-Clause" +srcDir = "src" +installExt = @["nim"] +bin = @["nim"] + + +# Dependencies + +requires "nim >= 2.0.12" diff --git a/templates/nim/flake.lock b/templates/nim/flake.lock new file mode 100644 index 0000000..19c8b93 --- /dev/null +++ b/templates/nim/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1742669843, + "narHash": "sha256-G5n+FOXLXcRx+3hCJ6Rt6ZQyF1zqQ0DL0sWAMn2Nk0w=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "1e5b653dff12029333a6546c11e108ede13052eb", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/templates/nim/flake.nix b/templates/nim/flake.nix new file mode 100644 index 0000000..62778ca --- /dev/null +++ b/templates/nim/flake.nix @@ -0,0 +1,32 @@ +{ + description = "CHANGE DESC"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + systems.url = "github:nix-systems/default"; + }; + + outputs = + inputs@{ self, nixpkgs, ... }: + let + inherit (nixpkgs) lib; + pkgsFor = nixpkgs.legacyPackages; + eachSystem = f: lib.genAttrs (import inputs.systems) (system: f system pkgsFor.${system}); + in + { + packages = eachSystem ( + system: pkgs: { + default = pkgs.callPackage ./flake/package.nix { }; + CHANGE_NAME = self.packages.${system}.default; + } + ); + + devShells = eachSystem ( + _system: pkgs: { + default = pkgs.callPackage ./flake/shell.nix { }; + } + ); + + formatter = eachSystem (_: pkgs: pkgs.callPackage ./flake/formatter.nix { }); + }; +} diff --git a/templates/nim/flake/formatter.nix b/templates/nim/flake/formatter.nix new file mode 100644 index 0000000..2662819 --- /dev/null +++ b/templates/nim/flake/formatter.nix @@ -0,0 +1,22 @@ +{ + writeShellApplication, + fd, + statix, + nixfmt-rfc-style, + deadnix, + nim-2_0, +}: +writeShellApplication { + name = "linter"; + runtimeInputs = [ + fd + statix + nixfmt-rfc-style + deadnix + nim-2_0 + ]; + text = '' + fd -e nix -X deadnix -e \; -X nixfmt {} + fd -e nix -x statix fix {} + ''; +} diff --git a/templates/nim/flake/package.nix b/templates/nim/flake/package.nix new file mode 100644 index 0000000..0ee7594 --- /dev/null +++ b/templates/nim/flake/package.nix @@ -0,0 +1,7 @@ +{ buildNimPackage }: +buildNimPackage (_finalAttrs: { + pname = "CHANGE_ME"; + version = "CHANGE_VER"; + + src = ../.; +}) diff --git a/templates/nim/flake/shell.nix b/templates/nim/flake/shell.nix new file mode 100644 index 0000000..a6063fe --- /dev/null +++ b/templates/nim/flake/shell.nix @@ -0,0 +1,14 @@ +{ + mkShell, + nim-2_0, + nimble, + nimlsp, +}: +mkShell { + name = "nim"; + packages = [ + nim-2_0 + nimble + nimlsp + ]; +} diff --git a/templates/nim/src/CHANGE_NAME.nim b/templates/nim/src/CHANGE_NAME.nim new file mode 100644 index 0000000..50cc01c --- /dev/null +++ b/templates/nim/src/CHANGE_NAME.nim @@ -0,0 +1,7 @@ +# This is just an example to get you started. A typical hybrid package +# uses this file as the main entry point of the application. + +import CHANGE_NAME/submodule + +when isMainModule: + echo(getWelcomeMessage()) diff --git a/templates/nim/src/CHANGE_NAME/submodule.nim b/templates/nim/src/CHANGE_NAME/submodule.nim new file mode 100644 index 0000000..966eac5 --- /dev/null +++ b/templates/nim/src/CHANGE_NAME/submodule.nim @@ -0,0 +1,6 @@ +# This is just an example to get you started. Users of your hybrid library will +# import this file by writing ``import nimpkg/submodule``. Feel free to rename or +# remove this file altogether. You may create additional modules alongside +# this file as required. + +proc getWelcomeMessage*(): string = "Hello, World!" diff --git a/templates/nim/tests/config.nims b/templates/nim/tests/config.nims new file mode 100644 index 0000000..3bb69f8 --- /dev/null +++ b/templates/nim/tests/config.nims @@ -0,0 +1 @@ +switch("path", "$projectDir/../src") \ No newline at end of file diff --git a/templates/nim/tests/test1.nim b/templates/nim/tests/test1.nim new file mode 100644 index 0000000..5ef4c61 --- /dev/null +++ b/templates/nim/tests/test1.nim @@ -0,0 +1,12 @@ +# This is just an example to get you started. You may wish to put all of your +# tests into a single file, or separate them into multiple `test1`, `test2` +# etc. files (better names are recommended, just make sure the name starts with +# the letter 't'). +# +# To run these tests, simply execute `nimble test`. + +import unittest + +import CHANGE_NAME/submodule +test "correct welcome": + check getWelcomeMessage() == "Hello, World!" diff --git a/templates/rust/.envrc b/templates/rust/.envrc new file mode 100644 index 0000000..bc49353 --- /dev/null +++ b/templates/rust/.envrc @@ -0,0 +1 @@ +use flake .# diff --git a/templates/rust/Cargo.lock b/templates/rust/Cargo.lock index 9c64ef4..651ea32 100644 --- a/templates/rust/Cargo.lock +++ b/templates/rust/Cargo.lock @@ -3,5 +3,5 @@ version = 3 [[package]] -name = "rust-app" -version = "0.1.0" +name = "CHANGE_NAME" +version = "CHANGE_VER" diff --git a/templates/rust/Cargo.toml b/templates/rust/Cargo.toml index e5e90c8..78bd33a 100644 --- a/templates/rust/Cargo.toml +++ b/templates/rust/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "rust-app" -version = "0.1.0" +name = "CHANGE_NAME" +version = "CHANGE_VER" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/templates/rust/flake.lock b/templates/rust/flake.lock index 787d031..956dbd2 100644 --- a/templates/rust/flake.lock +++ b/templates/rust/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1733212471, - "narHash": "sha256-M1+uCoV5igihRfcUKrr1riygbe73/dzNnzPsmaLCmpo=", + "lastModified": 1742889210, + "narHash": "sha256-hw63HnwnqU3ZQfsMclLhMvOezpM7RSB0dMAtD5/sOiw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "55d15ad12a74eb7d4646254e13638ad0c4128776", + "rev": "698214a32beb4f4c8e3942372c694f40848b360d", "type": "github" }, "original": { @@ -16,43 +16,24 @@ "type": "github" } }, - "nixpkgs_2": { - "locked": { - "lastModified": 1728538411, - "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, "root": { "inputs": { "nixpkgs": "nixpkgs", - "rust": "rust" + "systems": "systems" } }, - "rust": { - "inputs": { - "nixpkgs": "nixpkgs_2" - }, + "systems": { "locked": { - "lastModified": 1733279627, - "narHash": "sha256-NCNDAGPkdFdu+DLErbmNbavmVW9AwkgP7azROFFSB0U=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "4da5a80ef76039e80468c902f1e9f5c0eab87d96", + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", "type": "github" }, "original": { - "owner": "oxalica", - "repo": "rust-overlay", + "owner": "nix-systems", + "repo": "default", "type": "github" } } diff --git a/templates/rust/flake.nix b/templates/rust/flake.nix index eb854d2..db0ba2e 100644 --- a/templates/rust/flake.nix +++ b/templates/rust/flake.nix @@ -1,45 +1,25 @@ { - description = "Rust Developer Environment"; + description = "CHANGE DESC"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - rust.url = "github:oxalica/rust-overlay"; + systems.url = "github:nix-systems/default"; }; - outputs = { - self, - nixpkgs, - rust, - }: let - systems = [ - "x86_64-linux" - "aarch64-linux" - ]; - forAllSystems = nixpkgs.lib.genAttrs systems; - in { - packages = forAllSystems (system: let - pkgs = import nixpkgs { - inherit system; - overlays = [ - (import rust) - ]; - }; - inherit system; + outputs = { self, nixpkgs, systems, }: + let + pkgsFor = nixpkgs.legacyPackages; + forAllSystems = f: + nixpkgs.lib.genAttrs (import systems) + (system: f system pkgsFor.${system}); in { - rust-app = pkgs.callPackage ./nix/package.nix {}; - default = self.packages.${system}.rust-app; - }); + packages = forAllSystems (system: pkgs: { + default = pkgs.callPackage ./nix/package.nix { }; + CHANGE_NAME = self.packages.${system}.default; + }); - devShells = forAllSystems (system: let - pkgs = import nixpkgs { - inherit system; - overlays = [ - (import rust) - ]; - }; - inherit system; - in { - default = pkgs.callPackage ./nix/shell.nix { - inherit (self.packages.${system}) rust-app; - }; - }); - }; + devShells = forAllSystems + (_: pkgs: { default = pkgs.callPackage ./nix/shell.nix { }; }); + + formatter = + forAllSystems (_: pkgs: pkgs.callPackage ./nix/formatter.nix { }); + }; } diff --git a/templates/rust/nix/formatter.nix b/templates/rust/nix/formatter.nix new file mode 100644 index 0000000..fc11dda --- /dev/null +++ b/templates/rust/nix/formatter.nix @@ -0,0 +1,10 @@ +{ writeShellApplication, fd, nixfmt, deadnix, statix, rustfmt }: +writeShellApplication { + name = "liner"; + runtimeInputs = [ fd nixfmt deadnix statix rustfmt ]; + text = '' + fd -e nix -X nixfmt {} \; -X deadnix -e {} \; + fd -e nix -x statix fix {} \; + fd -e rs -X rustfmt {} \; + ''; +} diff --git a/templates/rust/nix/package.nix b/templates/rust/nix/package.nix index 4cef8f8..9663602 100644 --- a/templates/rust/nix/package.nix +++ b/templates/rust/nix/package.nix @@ -1,6 +1,7 @@ -{ rustPlatform }: let - pname = "rust-app"; - version = "0.1.0"; +{ rustPlatform }: +let + pname = "CHANGE_NAME"; + version = "CHANGE_VER"; in rustPlatform.buildRustPackage { inherit pname version; src = ../.; diff --git a/templates/rust/nix/shell.nix b/templates/rust/nix/shell.nix index 4eecb2c..74d0002 100644 --- a/templates/rust/nix/shell.nix +++ b/templates/rust/nix/shell.nix @@ -1,8 +1,5 @@ -{ mkShell, rust-app, rust-bin }: +{ mkShell, rustc, cargo, nixfmt, deadnix, statix, rustfmt, clippy }: mkShell { - name = "Rust Rivers"; - inputsFrom = [ rust-app ]; - buildInputs = [ - rust-bin.stable.latest.default - ]; + name = "rust"; + packages = [ nixfmt deadnix statix rustfmt clippy rustc cargo ]; }