diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-03-31 18:22:20 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-03-31 23:59:58 +0200 |
commit | 43655648a602b5b21e10dc69726d0d351bec8056 (patch) | |
tree | 39a2d11066355556006e7f61cd8cf1044377a21b /templates | |
parent | refactor(rust): Move to template dir (diff) | |
download | flake-templates-43655648a602b5b21e10dc69726d0d351bec8056.tar.gz flake-templates-43655648a602b5b21e10dc69726d0d351bec8056.zip |
feat(rust): Update to my SOTA
Diffstat (limited to '')
-rw-r--r-- | templates/rust/.envrc | 6 | ||||
-rw-r--r-- | templates/rust/.gitignore | 3 | ||||
-rw-r--r-- | templates/rust/.licensure.yml | 159 | ||||
-rw-r--r-- | templates/rust/Cargo.lock | 7 | ||||
-rw-r--r-- | templates/rust/Cargo.toml | 8 | ||||
-rw-r--r-- | templates/rust/README.md | 10 | ||||
-rw-r--r-- | templates/rust/cog.toml | 24 | ||||
-rw-r--r-- | templates/rust/docs/TODO.1.md | 70 | ||||
-rw-r--r-- | templates/rust/flake.lock | 147 | ||||
-rw-r--r-- | templates/rust/flake.nix | 81 | ||||
l--------- | templates/rust/scripts/renew_copyright_header.sh | 1 | ||||
-rw-r--r-- | templates/rust/src/main.rs | 3 | ||||
l--------- | templates/rust/treefmt.nix | 1 | ||||
-rwxr-xr-x | templates/rust/update.sh | 6 |
14 files changed, 486 insertions, 40 deletions
diff --git a/templates/rust/.envrc b/templates/rust/.envrc index a9c7e4e..77f9235 100644 --- a/templates/rust/.envrc +++ b/templates/rust/.envrc @@ -1,4 +1,8 @@ -use flake +use flake || use nix +watch_file flake.nix + +PATH_add ./target/ + if on_git_branch; then echo && git status --short --branch && echo && git fetch --verbose diff --git a/templates/rust/.gitignore b/templates/rust/.gitignore index 8884339..cb87f36 100644 --- a/templates/rust/.gitignore +++ b/templates/rust/.gitignore @@ -1,5 +1,6 @@ -# build dirs +# build /target /result +# dev env .direnv diff --git a/templates/rust/.licensure.yml b/templates/rust/.licensure.yml new file mode 100644 index 0000000..6c8dcfc --- /dev/null +++ b/templates/rust/.licensure.yml @@ -0,0 +1,159 @@ +--- +# Regexes which if matched by a file path will always be excluded from +# getting a license header +excludes: + - .*lock + - \.git/.* + - LICENSE.spdx + - COPYING + - COPYING.LESSER + - .*\.(rst|txt|pdf) +# Definition of the licenses used on this project and to what files +# they should apply. +# +# No default license configuration is provided. This section must be +# configured by the user. +licenses: + # Either a regex or the string "any" to determine to what files this + # license should apply. It is common for projects to have files + # under multiple licenses or with multiple copyright holders. This + # provides the ability to automatically license files correctly + # based on their file paths. + # + # If "any" is provided all files will match this license. + - files: any + # + # The license identifier, a list of common identifiers can be + # found at: https://spdx.org/licenses/ but existence of the ident + # in this list it is not enforced unless auto_template is set to + # true. + ident: GPL-3.0-or-later + # + # A list of authors who hold copyright over these files + authors: + # Provide either your full name or company name for copyright purposes + - name: Benedikt Peetz + # Optionally provide email for copyright purposes + email: "benedikt.peetz@b-peetz.de" + + # The template that will be rendered to generate the header before + # comment characters are applied. Available variables are: + # - [year]: substituted with the current year. + # - [name of author]: Substituted with name of the author and email + # if provided. If email is provided the output appears as Full + # Name <email@example.com>. If multiple authors are provided the + # list is concatenated together with commas. + template: | + Copyright (C) 2023 - [year]: + [name of author] + SPDX-License-Identifier: GPL-3.0-or-later + + This file is part of the TODO. + + Trixy is free software: you can redistribute it and/or modify + it under the terms of the Lesser GNU General Public License as + published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + and the Lesser GNU General Public License along with this program. + If not, see <https://www.gnu.org/licenses/>. + + + # If auto_template is true then template is ignored and the SPDX + # API will be queried with the ident value to automatically + # determine the license header template. auto_template works best + # with licenses that have a standardLicenseHeader field defined in + # their license info JSON, if it is not then we will use the full + # licenseText to generate the header which works fine for short + # licenses like MIT but can be quite lengthy for other licenses + # like BSD-4-Clause. The above default template is valid for most + # licenses and is recommended for MIT, and BSD licenses. Common + # licenses that work well with the auto_template feature are GPL + # variants, and the Apache 2.0 license. + # + # Important Note: this means the ident must be a valid SPDX identifier + # auto_template: true + + # If true try to detect the text wrapping of the template, and unwrap it + unwrap_text: false + +# Define type of comment characters to apply based on file extensions. +comments: + # The extensions (or singular extension) field defines which file + # extensions to apply the commenter to. + - extensions: + - js + - go + # The commenter field defines the kind of commenter to + # generate. There are two types of commenters: line and block. + # + # This demonstrates a line commenter configuration. A line + # commenter type will apply the comment_char to the beginning of + # each line in the license header. It will then apply a number of + # empty newlines to the end of the header equal to trailing_lines. + # + # If trailing_lines is omitted it is assumed to be 0. + commenter: + type: line + comment_char: "//" + trailing_lines: 1 + + - extensions: + - rs + - tri + - css + - cpp + - c + - h + # This demonstrates a block commenter configuration. A block + # commenter type will add start_block_char as the first character + # in the license header and add end_block_char as the last character + # in the license header. If per_line_char is provided each line of + # the header between the block start and end characters will be + # line commented with the per_line_char + # + # trailing_lines works the same for both block and line commenter + # types + commenter: + type: block + start_block_char: "/*\n" + end_block_char: "*/\n" + per_line_char: "*" + trailing_lines: 1 + + - extension: + - html + - md + commenter: + type: block + start_block_char: "<!--\n" + end_block_char: "-->\n" + trailing_lines: 1 + + - extensions: + - el + - lisp + commenter: + type: line + comment_char: ";;;" + trailing_lines: 1 + + # The extension string "any" is special and so will match any file + # extensions. Commenter configurations are always checked in the + # order they are defined, so if any is used it should be the last + # commenter configuration or else it will override all others. + # + # In this configuration if we can't match the file extension we fall + # back to the popular '#' line comment used in most scripting + # languages. + - extension: any + commenter: + type: line + comment_char: '#' + trailing_lines: 1 diff --git a/templates/rust/Cargo.lock b/templates/rust/Cargo.lock new file mode 100644 index 0000000..9d8cd04 --- /dev/null +++ b/templates/rust/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "TODO" +version = "0.1.0" diff --git a/templates/rust/Cargo.toml b/templates/rust/Cargo.toml new file mode 100644 index 0000000..6813ae1 --- /dev/null +++ b/templates/rust/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "TODO" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/templates/rust/README.md b/templates/rust/README.md new file mode 100644 index 0000000..5912c16 --- /dev/null +++ b/templates/rust/README.md @@ -0,0 +1,10 @@ +# TODO + +Some text about the project. + +## Licence + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. diff --git a/templates/rust/cog.toml b/templates/rust/cog.toml index 0756943..2646f07 100644 --- a/templates/rust/cog.toml +++ b/templates/rust/cog.toml @@ -1,14 +1,14 @@ -from_latest_tag = false tag_prefix = "v" +branch_whitelist = ["main", "prime"] ignore_merge_commits = false -pre_package_bump_hooks = [] -post_package_bump_hooks = [] -branch_whitelist = ["prime"] +[commit_types] pre_bump_hooks = [ - "nix build", # verify the project builds - "cargo set-version {{version}}", # bump version in Cargo.toml + "nix flake check", # verify the project builds + "./scripts/renew_copyright_header.sh", # update the license header in each file + "cargo set-version {{version}}", # bump version in Cargo.toml + "nix fmt", # format ] post_bump_hooks = [ "git push", @@ -16,12 +16,12 @@ post_bump_hooks = [ "git push origin v{{version}}", # push the new tag to origin ] -[commit_types] +[bump_profiles] [changelog] path = "NEWS.md" -authors = [] - -[bump_profiles] - -[packages] +template = "remote" +remote = "TODO" +repository = "TODO" +owner = "TODO" +authors = [{ signature = "Benedikt Peetz", username = "bpeetz" }] diff --git a/templates/rust/docs/TODO.1.md b/templates/rust/docs/TODO.1.md new file mode 100644 index 0000000..e14fec5 --- /dev/null +++ b/templates/rust/docs/TODO.1.md @@ -0,0 +1,70 @@ +% FUPDATE(1) fupdate 1.0.0 +% Benedikt Peetz +% May 2023 + +# NAME + +fupdate - updates your flake, while checking for common mistakes + +# SYNOPSIS + +**fupdate** list of \[*flake*|*\<some word>*|*--help*|*-h*\] + +# DESCRIPTION + +Argument can be stacked, this makes it possible to specify multiple targets to be updated in succession. See the Examples section for further details. + +No argument or *flake* +: **fupdate**, when executed without arguments or with *flake*, will update your *flake.lock*, check for duplicate flake inputs, i.e., an input has an input declared, which you have also declared as input, and will run a script called *update.sh*, if you allow it. +The allowance for the script is asked, when you run **fupdate** and the found script is not yet allowed. Furthermore, the allowance is based on the concrete sha256 hash of the script, so any changes will require another allowance. + +**\<some word>** as argument +: If the executable **update-\<some word>** is reachable thought the PATH variable, than this is run. Otherwise, the program will exit. + +# OPTIONS + +**--help**, **-h** +: Displays a help message and exit. + +**--version**, **-v** +: Displays the software version and exit. + +# EXAMPLES + +**fupdate** or **fupdate flake** +: Updates your *flake.lock*. See the Description section for further details. + +**fupdate sys** +: Run the executable **update-sys**, if it exists. See the Description section for further details. + +**fupdate flake sys docs** +: First updates your flake, then, if the command succeeded, runs **update-sys**, afterweich **update-docs** is run. + +# FILES + +*update.sh* +: This is supposed to be a shell script located in your flake base directory, i.e., the directory which contains both a *flake.nix* and a *flake.lock* file. + +*~/.local/share/flake-update/* +: **fupdate** will store the hashes to the allowed *update.sh* files here. + +# BUGS + +Report bugs to <https://codeberg.org/soispha/flake_update/issues>. + +# COPYRIGHT + +Copyright (C) 2023 Benedikt Peetz + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <https://www.gnu.org/licenses/>. diff --git a/templates/rust/flake.lock b/templates/rust/flake.lock new file mode 100644 index 0000000..ea926e5 --- /dev/null +++ b/templates/rust/flake.lock @@ -0,0 +1,147 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1711681752, + "narHash": "sha256-LEg6/dmEFxx6Ygti5DO9MOhGNpyB7zdxdWtzv/FCTXk=", + "owner": "ipetkov", + "repo": "crane", + "rev": "ada0fb4dcce4561acb1eb17c59b7306d9d4a95f3", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": [ + "systems" + ] + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1711715736, + "narHash": "sha256-9slQ609YqT9bT/MNX9+5k5jltL9zgpn36DpFB7TkttM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "807c549feabce7eddbf259dbdcec9e0600a0660d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay", + "systems": "systems", + "treefmt-nix": "treefmt-nix" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1711851236, + "narHash": "sha256-EJ03x3N9ihhonAttkaCrqxb0djDq3URCuDpmVPbNZhA=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "f258266af947599e8069df1c2e933189270f143a", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1680978846, + "narHash": "sha256-Gtqg8b/v49BFDpDetjclCYXm8mAnTrUzR0JnE2nv5aw=", + "owner": "nix-systems", + "repo": "x86_64-linux", + "rev": "2ecfcac5e15790ba6ce360ceccddb15ad16d08a8", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "x86_64-linux", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1711803027, + "narHash": "sha256-Qic3OvsVLpetchzaIe2hJqgliWXACq2Oee6mBXa/IZQ=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "1810d51a015c1730f2fe05a255258649799df416", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/templates/rust/flake.nix b/templates/rust/flake.nix index 4512bed..2e65c7d 100644 --- a/templates/rust/flake.nix +++ b/templates/rust/flake.nix @@ -1,30 +1,20 @@ { - description = "<app_description>"; # TODO + description = "TODO"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - # inputs for following - systems = { - url = "github:nix-systems/x86_64-linux"; # only evaluate for this system - }; - flake-compat = { - url = "github:edolstra/flake-compat"; - flake = false; - }; - crane = { - url = "github:ipetkov/crane"; + treefmt-nix = { + url = "github:numtide/treefmt-nix"; inputs = { nixpkgs.follows = "nixpkgs"; - flake-compat.follows = "flake-compat"; - flake-utils.follows = "flake-utils"; - rust-overlay.follows = "rust-overlay"; }; }; - flake-utils = { - url = "github:numtide/flake-utils"; + + crane = { + url = "github:ipetkov/crane"; inputs = { - systems.follows = "systems"; + nixpkgs.follows = "nixpkgs"; }; }; rust-overlay = { @@ -34,13 +24,29 @@ flake-utils.follows = "flake-utils"; }; }; + + # inputs for following + systems = { + url = "github:nix-systems/x86_64-linux"; # only evaluate for this system + }; + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + flake-utils = { + url = "github:numtide/flake-utils"; + inputs = { + systems.follows = "systems"; + }; + }; }; outputs = { self, nixpkgs, - crane, flake-utils, + treefmt-nix, + crane, rust-overlay, ... }: @@ -55,27 +61,54 @@ if nightly then pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.minimal) else pkgs.rust-bin.stable.latest.minimal; - rust_default = if nightly then pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default) else pkgs.rust-bin.stable.latest.default; - craneLib = (crane.mkLib pkgs).overrideToolchain rust_minimal; + cargo_toml = craneLib.cleanCargoToml {cargoToml = ./Cargo.toml;}; + pname = cargo_toml.package.name; + craneLib = (crane.mkLib pkgs).overrideToolchain rust_minimal; craneBuild = craneLib.buildPackage { src = craneLib.cleanCargoSource ./.; doCheck = true; }; + + manual = pkgs.stdenv.mkDerivation { + name = "${pname}-manual"; + inherit (cargo_toml.package) version; + + src = ./docs; + nativeBuildInputs = with pkgs; [pandoc]; + + buildPhase = '' + mkdir --parents $out/docs; + + pandoc "./${pname}.1.md" -s -t man > $out/docs/${pname}.1 + ''; + + installPhase = '' + install -D $out/docs/${pname}.1 $out/share/man/man1/${pname}; + ''; + }; + + treefmtEval = import ./treefmt.nix {inherit treefmt-nix pkgs;}; in { - packages.default = craneBuild; + packages.default = pkgs.symlinkJoin { + inherit (cargo_toml.package) name; - app.default = { - type = "app"; - program = "${self.packages.${system}.default}/bin/<app_name>"; # TODO + paths = [manual craneBuild]; }; + checks = { + inherit craneBuild; + formatting = treefmtEval.config.build.check self; + }; + + formatter = treefmtEval.config.build.wrapper; + devShells.default = pkgs.mkShell { packages = with pkgs; [ cocogitto diff --git a/templates/rust/scripts/renew_copyright_header.sh b/templates/rust/scripts/renew_copyright_header.sh new file mode 120000 index 0000000..f286da9 --- /dev/null +++ b/templates/rust/scripts/renew_copyright_header.sh @@ -0,0 +1 @@ +../../../common/renew_copyright_header.sh \ No newline at end of file diff --git a/templates/rust/src/main.rs b/templates/rust/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/templates/rust/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/templates/rust/treefmt.nix b/templates/rust/treefmt.nix new file mode 120000 index 0000000..6a4fe7d --- /dev/null +++ b/templates/rust/treefmt.nix @@ -0,0 +1 @@ +../../treefmt.nix \ No newline at end of file diff --git a/templates/rust/update.sh b/templates/rust/update.sh index 9268caf..b34dabf 100755 --- a/templates/rust/update.sh +++ b/templates/rust/update.sh @@ -1,3 +1,5 @@ -#!/bin/sh +#!/usr/bin/env sh -cargo update && cargo upgrade +nix flake update +cargo update +[ "$1" = "upgrade" ] && cargo upgrade |