meta: refactor repository

This commit is contained in:
Artur Manuel 2025-03-26 15:08:13 +00:00
commit 599fe1903f
Signed by: amadaluzia
SSH key fingerprint: SHA256:Zwg7gBuZyaG48ucAZneJwltiXu0+tJb7c3lYt9AYlLg
28 changed files with 276 additions and 136 deletions

1
templates/go/.envrc Normal file
View file

@ -0,0 +1 @@
use flake .#

View file

@ -18,7 +18,23 @@
}, },
"root": { "root": {
"inputs": { "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"
} }
} }
}, },

View file

@ -1,38 +1,27 @@
{ {
description = "Go flake template"; description = "CHANGE DESC";
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
systems.url = "github:nix-systems/default";
}; };
outputs = { outputs = { self, nixpkgs, systems, }:
self, let
nixpkgs, inherit (nixpkgs) lib;
}: let pkgsFor = nixpkgs.legacyPackages;
allSystems = [ forAllSystems = f:
"x86_64-linux" lib.genAttrs (import systems) (system: f system pkgsFor.${system});
"aarch64-linux" in {
]; packages = forAllSystems (system: pkgs: {
forAllSystems = f: default = pkgs.callPackage ./flake/package.nix { };
nixpkgs.lib.genAttrs allSystems (system: CHANGE_NAME = self.packages.${system}.default;
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;
});
devShells = forAllSystems ({ devShells = forAllSystems
pkgs, (_: pkgs: { default = pkgs.callPackage ./flake/shell.nix { }; });
system,
}: { formatter =
default = pkgs.callPackage ./nix/shell.nix {inherit (self.packages.${system}) go-app;}; forAllSystems (_: pkgs: pkgs.callPackage ./flake/formatter.nix { });
}); };
};
} }

View file

@ -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 {} \;
'';
}

View file

@ -1,9 +1,8 @@
{ buildGoModule }: { buildGoModule }:
let let
pname = "go-app"; pname = "CHANGE_ME";
version = "0.1.0"; version = "CHANGE_VER";
in in buildGoModule {
buildGoModule {
inherit pname version; inherit pname version;
src = ../.; src = ../.;
vendorHash = null; vendorHash = null;

View file

@ -0,0 +1,9 @@
{ mkShell, go, gopls, go-tools }:
mkShell {
name = "go";
packages = [
go
gopls
go-tools
];
}

View file

@ -1,3 +1,3 @@
module codeberg.org/amadaluzia/go-app module codeberg.org/amadaluzia/CHANGE_ME
go 1.22.5 go 1.22.5

View file

@ -29,14 +29,14 @@ func GetResponse() (*http.Response, error) {
for attempts != 0 { for attempts != 0 {
res, err = http.Get(url) res, err = http.Get(url)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, "Error encountered... trying again...") fmt.Fprintln(os.Stderr, "error encountered... trying again")
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
attempts-- attempts--
continue continue
} }
if res.StatusCode != 200 { 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) time.Sleep(2 * time.Second)
attempts-- attempts--
continue continue
@ -52,7 +52,7 @@ func GetResponse() (*http.Response, error) {
} }
if res.StatusCode != 200 { 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 return res, nil
@ -73,10 +73,8 @@ func GetBodyFromResponse(res *http.Response) ([]byte, error) {
func NewQuoteFromBody(body []byte) (Quote, error) { func NewQuoteFromBody(body []byte) (Quote, error) {
var quote Quote var quote Quote
var err error
err = json.Unmarshal(body, &quote) if err := json.Unmarshal(body, &quote); err != nil {
if err != nil {
return Quote{}, err return Quote{}, err
} }

View file

@ -1,11 +0,0 @@
{ mkShell, go, go-app, gopls, go-tools, gotools }:
mkShell {
name = "Gopherborough";
inputsFrom = [ go-app ];
buildInputs = [
go
gopls
go-tools
gotools
];
}

1
templates/nim/.envrc Normal file
View file

@ -0,0 +1 @@
use flake .#

View file

@ -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"

43
templates/nim/flake.lock generated Normal file
View file

@ -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
}

32
templates/nim/flake.nix Normal file
View file

@ -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 { });
};
}

View file

@ -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 {}
'';
}

View file

@ -0,0 +1,7 @@
{ buildNimPackage }:
buildNimPackage (_finalAttrs: {
pname = "CHANGE_ME";
version = "CHANGE_VER";
src = ../.;
})

View file

@ -0,0 +1,14 @@
{
mkShell,
nim-2_0,
nimble,
nimlsp,
}:
mkShell {
name = "nim";
packages = [
nim-2_0
nimble
nimlsp
];
}

View file

@ -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())

View file

@ -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!"

View file

@ -0,0 +1 @@
switch("path", "$projectDir/../src")

View file

@ -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!"

1
templates/rust/.envrc Normal file
View file

@ -0,0 +1 @@
use flake .#

View file

@ -3,5 +3,5 @@
version = 3 version = 3
[[package]] [[package]]
name = "rust-app" name = "CHANGE_NAME"
version = "0.1.0" version = "CHANGE_VER"

View file

@ -1,6 +1,6 @@
[package] [package]
name = "rust-app" name = "CHANGE_NAME"
version = "0.1.0" version = "CHANGE_VER"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -2,11 +2,11 @@
"nodes": { "nodes": {
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1733212471, "lastModified": 1742889210,
"narHash": "sha256-M1+uCoV5igihRfcUKrr1riygbe73/dzNnzPsmaLCmpo=", "narHash": "sha256-hw63HnwnqU3ZQfsMclLhMvOezpM7RSB0dMAtD5/sOiw=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "55d15ad12a74eb7d4646254e13638ad0c4128776", "rev": "698214a32beb4f4c8e3942372c694f40848b360d",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -16,43 +16,24 @@
"type": "github" "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": { "root": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"rust": "rust" "systems": "systems"
} }
}, },
"rust": { "systems": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": { "locked": {
"lastModified": 1733279627, "lastModified": 1681028828,
"narHash": "sha256-NCNDAGPkdFdu+DLErbmNbavmVW9AwkgP7azROFFSB0U=", "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "oxalica", "owner": "nix-systems",
"repo": "rust-overlay", "repo": "default",
"rev": "4da5a80ef76039e80468c902f1e9f5c0eab87d96", "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "oxalica", "owner": "nix-systems",
"repo": "rust-overlay", "repo": "default",
"type": "github" "type": "github"
} }
} }

View file

@ -1,45 +1,25 @@
{ {
description = "Rust Developer Environment"; description = "CHANGE DESC";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust.url = "github:oxalica/rust-overlay"; systems.url = "github:nix-systems/default";
}; };
outputs = { outputs = { self, nixpkgs, systems, }:
self, let
nixpkgs, pkgsFor = nixpkgs.legacyPackages;
rust, forAllSystems = f:
}: let nixpkgs.lib.genAttrs (import systems)
systems = [ (system: f system pkgsFor.${system});
"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;
in { in {
rust-app = pkgs.callPackage ./nix/package.nix {}; packages = forAllSystems (system: pkgs: {
default = self.packages.${system}.rust-app; default = pkgs.callPackage ./nix/package.nix { };
}); CHANGE_NAME = self.packages.${system}.default;
});
devShells = forAllSystems (system: let devShells = forAllSystems
pkgs = import nixpkgs { (_: pkgs: { default = pkgs.callPackage ./nix/shell.nix { }; });
inherit system;
overlays = [ formatter =
(import rust) forAllSystems (_: pkgs: pkgs.callPackage ./nix/formatter.nix { });
]; };
};
inherit system;
in {
default = pkgs.callPackage ./nix/shell.nix {
inherit (self.packages.${system}) rust-app;
};
});
};
} }

View file

@ -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 {} \;
'';
}

View file

@ -1,6 +1,7 @@
{ rustPlatform }: let { rustPlatform }:
pname = "rust-app"; let
version = "0.1.0"; pname = "CHANGE_NAME";
version = "CHANGE_VER";
in rustPlatform.buildRustPackage { in rustPlatform.buildRustPackage {
inherit pname version; inherit pname version;
src = ../.; src = ../.;

View file

@ -1,8 +1,5 @@
{ mkShell, rust-app, rust-bin }: { mkShell, rustc, cargo, nixfmt, deadnix, statix, rustfmt, clippy }:
mkShell { mkShell {
name = "Rust Rivers"; name = "rust";
inputsFrom = [ rust-app ]; packages = [ nixfmt deadnix statix rustfmt clippy rustc cargo ];
buildInputs = [
rust-bin.stable.latest.default
];
} }