aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-03-31 23:31:08 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-04-01 00:00:03 +0200
commit76932b24718c6b4c0d7bdffe8f776a6105ea3745 (patch)
treefa53fd6cc1a5a0be43693de2da69f1c0aebfd223
parentrefactor(shell): Move to the new `templates` directory (diff)
downloadflake-templates-76932b24718c6b4c0d7bdffe8f776a6105ea3745.zip
feat(shell): Update to my new SOTA
-rw-r--r--templates/shell/.envrc6
-rw-r--r--templates/shell/.gitignore4
-rw-r--r--templates/shell/.licensure.yml166
-rw-r--r--templates/shell/README.md10
-rw-r--r--templates/shell/cog.toml24
-rw-r--r--templates/shell/docs/TODO.1.md70
-rw-r--r--templates/shell/flake.lock159
-rw-r--r--templates/shell/flake.nix104
l---------templates/shell/scripts/renew_copyright_header.sh1
-rwxr-xr-xtemplates/shell/src/main.sh17
l---------templates/shell/treefmt.nix1
-rwxr-xr-xtemplates/shell/update.sh3
12 files changed, 513 insertions, 52 deletions
diff --git a/templates/shell/.envrc b/templates/shell/.envrc
index a9c7e4e..3bc1085 100644
--- a/templates/shell/.envrc
+++ b/templates/shell/.envrc
@@ -1,4 +1,8 @@
-use flake
+use flake || use nix
+watch_file flake.nix
+
+PATH_add ./scripts
+
if on_git_branch; then
echo && git status --short --branch &&
echo && git fetch --verbose
diff --git a/templates/shell/.gitignore b/templates/shell/.gitignore
index aad77ec..cb87f36 100644
--- a/templates/shell/.gitignore
+++ b/templates/shell/.gitignore
@@ -1,4 +1,6 @@
-# build dirs
+# build
+/target
/result
+# dev env
.direnv
diff --git a/templates/shell/.licensure.yml b/templates/shell/.licensure.yml
new file mode 100644
index 0000000..e1f5a01
--- /dev/null
+++ b/templates/shell/.licensure.yml
@@ -0,0 +1,166 @@
+---
+# 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
+
+ - extensions:
+ - tex
+ 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/shell/README.md b/templates/shell/README.md
new file mode 100644
index 0000000..5912c16
--- /dev/null
+++ b/templates/shell/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/shell/cog.toml b/templates/shell/cog.toml
index 2b049c7..ff2c110 100644
--- a/templates/shell/cog.toml
+++ b/templates/shell/cog.toml
@@ -1,26 +1,24 @@
-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"]
pre_bump_hooks = [
- "nix build", # verify the project builds
- "flake_version_update --version v{{version}} --input-file flake.nix",
+ "nix flake check", # verify the project builds
+ "./scripts/renew_copyright_header.sh", # update the license header in each file
+ "flake_version_update --version v{{version}} --input-file flake.nix", # update the version in the flake.nix file
+ "nix fmt", # format
]
post_bump_hooks = [
"git push",
"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/shell/docs/TODO.1.md b/templates/shell/docs/TODO.1.md
new file mode 100644
index 0000000..e14fec5
--- /dev/null
+++ b/templates/shell/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/shell/flake.lock b/templates/shell/flake.lock
new file mode 100644
index 0000000..60caf54
--- /dev/null
+++ b/templates/shell/flake.lock
@@ -0,0 +1,159 @@
+{
+ "nodes": {
+ "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"
+ }
+ },
+ "flake_version_update": {
+ "inputs": {
+ "flake-utils": [
+ "flake-utils"
+ ],
+ "nixpkgs": [
+ "nixpkgs"
+ ],
+ "systems": [
+ "systems"
+ ]
+ },
+ "locked": {
+ "lastModified": 1685288691,
+ "narHash": "sha256-oP6h34oJ8rm6KlUpyZrX+ww3hnoWny2ecrEXxkU7F3c=",
+ "ref": "refs/heads/prime",
+ "rev": "e9a97e01eca780bd16e1dbdbd8856b59558f4959",
+ "revCount": 5,
+ "type": "git",
+ "url": "https://codeberg.org/soispha/flake_version_update.git"
+ },
+ "original": {
+ "type": "git",
+ "url": "https://codeberg.org/soispha/flake_version_update.git"
+ }
+ },
+ "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": {
+ "flake-compat": "flake-compat",
+ "flake-utils": "flake-utils",
+ "flake_version_update": "flake_version_update",
+ "nixpkgs": "nixpkgs",
+ "shell_library": "shell_library",
+ "systems": "systems",
+ "treefmt-nix": "treefmt-nix"
+ }
+ },
+ "shell_library": {
+ "inputs": {
+ "flake-utils": [
+ "flake-utils"
+ ],
+ "flake_version_update": [
+ "flake_version_update"
+ ],
+ "nixpkgs": [
+ "nixpkgs"
+ ],
+ "systems": [
+ "systems"
+ ]
+ },
+ "locked": {
+ "lastModified": 1710519017,
+ "narHash": "sha256-7C7onkhZiLwzrrf9XfzHEOjht9FmZfGABPbzE8XOYoI=",
+ "ref": "refs/heads/prime",
+ "rev": "24713f56f30e755553cac9497258ebc5d73036dc",
+ "revCount": 180,
+ "type": "git",
+ "url": "https://codeberg.org/soispha/shell_library.git"
+ },
+ "original": {
+ "type": "git",
+ "url": "https://codeberg.org/soispha/shell_library.git"
+ }
+ },
+ "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/shell/flake.nix b/templates/shell/flake.nix
index b699f25..4025fbe 100644
--- a/templates/shell/flake.nix
+++ b/templates/shell/flake.nix
@@ -1,15 +1,22 @@
{
- description = ""; # TODO
+ description = "TODO";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
- systems = {
- url = "github:nix-systems/x86_64-linux"; # only evaluate for this system
+
+ treefmt-nix = {
+ url = "github:numtide/treefmt-nix";
+ inputs = {
+ nixpkgs.follows = "nixpkgs";
+ };
};
- flake-utils = {
- url = "github:numtide/flake-utils";
+
+ flake_version_update = {
+ url = "git+https://codeberg.org/soispha/flake_version_update.git";
inputs = {
systems.follows = "systems";
+ nixpkgs.follows = "nixpkgs";
+ flake-utils.follows = "flake-utils";
};
};
shell_library = {
@@ -18,14 +25,22 @@
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixpkgs";
systems.follows = "systems";
+ flake_version_update.follows = "flake_version_update";
};
};
- flake_version_update = {
- url = "git+https://codeberg.org/soispha/flake_version_update.git";
+
+ # 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";
- nixpkgs.follows = "nixpkgs";
- flake-utils = "flake-utils";
};
};
};
@@ -34,55 +49,70 @@
self,
nixpkgs,
flake-utils,
- shell_library,
+ treefmt-nix,
flake_version_update,
+ shell_library,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
- pkgs = nixpkgs.legacyPackages.${system};
+ pkgs = nixpkgs.legacyPackages."${system}";
- built_script = shell_library.lib.${system}.writeShellScriptWithLibrary {
- name = ""; # TODO
- path = ./src/your_path; # TODO
- dependencies = builtins.attrValues {inherit (pkgs) dash;};
- };
+ treefmtEval = import ./treefmt.nix {inherit treefmt-nix pkgs;};
# This version is set automatically on `cog bump --auto`;
- version = "v1.0.0"; # GUIDING VERSION STRING
- in {
- packages.default = pkgs.stdenv.mkDerivation {
- pname = ""; # TODO
+ version = "v0.1.0"; # GUIDING VERSION STRING
+ pname = "TODO";
+
+ build = shell_library.lib.${system}.writeShellScript {
+ inherit version;
+ name = pname;
+
+ src = ./src/main.sh;
+ dependencies = with pkgs; [dash];
+
+ replacementStrings = null;
+ generateCompletions = false;
+ keepPath = false;
+ wrap = true;
+ };
+
+ manual = pkgs.stdenv.mkDerivation {
+ name = "${pname}-manual";
inherit version;
- src = ./.;
- nativeBuildInputs = builtins.attrValues {
- inherit
- (pkgs)
- #pandoc
-
- ;
- };
+ src = ./docs;
+ nativeBuildInputs = with pkgs; [pandoc];
buildPhase = ''
- #mkdir --parents $out/docs;
- #pandoc $src/docs/<name>.1.md -s -t man > $out/docs/<name>.1
+ mkdir --parents $out/docs;
+
+ pandoc "./${pname}.1.md" -s -t man > $out/docs/${pname}.1
'';
installPhase = ''
- install -D $out/docs/<name>.<man_number> $out/share/man/man<man_number>/<name>;
- install -D ${built_script}/bin/<name> $out/bin/<name>;
+ install -D $out/docs/${pname}.1 $out/share/man/man1/${pname};
'';
};
- app.default = {
- type = "app";
- program = "${self.packages.${system}.default}/bin/<name>";
+ in {
+ packages.default = pkgs.symlinkJoin {
+ name = pname;
+
+ paths = [manual build];
+ };
+
+ checks = {
+ inherit build;
+ formatting = treefmtEval.config.build.check self;
};
+ formatter = treefmtEval.config.build.wrapper;
+
devShells.default = pkgs.mkShell {
packages = with pkgs; [
+ cocogitto
flake_version_update.packages."${system}".default
+
+ licensure
];
};
});
}
-# vim: ts=2
-
diff --git a/templates/shell/scripts/renew_copyright_header.sh b/templates/shell/scripts/renew_copyright_header.sh
new file mode 120000
index 0000000..f286da9
--- /dev/null
+++ b/templates/shell/scripts/renew_copyright_header.sh
@@ -0,0 +1 @@
+../../../common/renew_copyright_header.sh \ No newline at end of file
diff --git a/templates/shell/src/main.sh b/templates/shell/src/main.sh
new file mode 100755
index 0000000..4c4c836
--- /dev/null
+++ b/templates/shell/src/main.sh
@@ -0,0 +1,17 @@
+#!/usr/bin/env dash
+
+# shellcheck source=/dev/null
+SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH
+
+# Both are used in `version`
+# shellcheck disable=2034
+AUTHORS="Benedikt Peetz"
+# shellcheck disable=2034
+YEARS="2024"
+
+printf "Hello World!\n\n"
+
+# Show off the library provided version function
+version
+
+# vim: ft=sh
diff --git a/templates/shell/treefmt.nix b/templates/shell/treefmt.nix
new file mode 120000
index 0000000..6a4fe7d
--- /dev/null
+++ b/templates/shell/treefmt.nix
@@ -0,0 +1 @@
+../../treefmt.nix \ No newline at end of file
diff --git a/templates/shell/update.sh b/templates/shell/update.sh
new file mode 100755
index 0000000..49216b8
--- /dev/null
+++ b/templates/shell/update.sh
@@ -0,0 +1,3 @@
+#!/usr/bin/env sh
+
+nix flake update