diff --git a/devenv.nix b/devenv.nix index 2c0033990..8224e2a8e 100644 --- a/devenv.nix +++ b/devenv.nix @@ -31,6 +31,12 @@ devcontainer.settings.customizations.vscode.extensions = [ "jnoortheen.nix-ide" ]; difftastic.enable = true; + #enable just. + just = { + enable = true; + recipes.convco.enable = true; + }; + dotenv.enable = true; processes = { @@ -40,6 +46,7 @@ scripts.devenv-test-cli = { description = "Test devenv CLI."; + just.enable = true; exec = '' set -xe set -o pipefail @@ -97,6 +104,7 @@ }; scripts."devenv-generate-doc-options" = { description = "Generate option docs."; + just.enable = true; exec = '' set -e output_file=docs/reference/options.md @@ -110,6 +118,7 @@ }; scripts."devenv-generate-languages-example" = { description = "Generate an example enabling every supported language."; + just.enable = true; exec = '' cat > examples/supported-languages/devenv.nix < docs/services-all.md <, }, diff --git a/devenv/src/devenv.rs b/devenv/src/devenv.rs index 12a0da387..0372226d5 100644 --- a/devenv/src/devenv.rs +++ b/devenv/src/devenv.rs @@ -19,7 +19,13 @@ use std::{ // templates const FLAKE_TMPL: &str = include_str!("flake.tmpl.nix"); -const REQUIRED_FILES: [&str; 4] = ["devenv.nix", "devenv.yaml", ".envrc", ".gitignore"]; +const REQUIRED_FILES: [&str; 5] = [ + "devenv.nix", + "devenv.yaml", + ".envrc", + ".gitignore", + "justfile", +]; const EXISTING_REQUIRED_FILES: [&str; 1] = [".gitignore"]; const PROJECT_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/init"); // project vars diff --git a/docs/reference/options.md b/docs/reference/options.md index 6add637f4..996d4b7dd 100644 --- a/docs/reference/options.md +++ b/docs/reference/options.md @@ -1694,6 +1694,738 @@ attribute set of list of string +## just.enable + + + +Whether to enable the just command runner. + + + +*Type:* +boolean + + + +*Default:* +` false ` + + + +*Example:* +` true ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just) + + + +## just.package + + + +The just package to use. + + + +*Type:* +package + + + +*Default:* +` pkgs.just ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just) + + + +## just.commonFileName + + + +The name of the common justfile generated by this module. + + + +*Type:* +string + + + +*Default:* +` "just-flake.just" ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just) + + + +## just.recipes + + + +This option has no description. + + + +*Type:* +attribute set of (submodule) + + + +*Default:* +` { } ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/rust.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/rust.nix) + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/git-cliff.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/git-cliff.nix) + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/devenv-up.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/devenv-up.nix) + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/devenv-script.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/devenv-script.nix) + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/convco.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/convco.nix) + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just) + + + +## just.recipes.\.enable + + + +Whether to enable this recipe. + + + +*Type:* +boolean + + + +*Default:* +` false ` + + + +*Example:* +` true ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.\.package + + + +An optional package that provides the recipe. + + + +*Type:* +null or package + + + +*Default:* +` null ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.\.justfile + + + +The justfile representing this recipe. + + + +*Type:* +string or path + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.\.outputs.justfile + + + +The justfile code for importing this recipe’s justfile. + +See https://just.systems/man/en/chapter_53.html + + + +*Type:* +string *(read only)* + + + +*Default:* +` "" ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.convco + + + +Add the ‘changelog’ target calling convco + + + +*Type:* +submodule + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/convco.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/convco.nix) + + + +## just.recipes.convco.enable + + + +Whether to enable this recipe. + + + +*Type:* +boolean + + + +*Default:* +` false ` + + + +*Example:* +` true ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.convco.package + + + +An optional package that provides the recipe. + + + +*Type:* +null or package + + + +*Default:* +` null ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.convco.justfile + + + +The justfile representing this recipe. + + + +*Type:* +string or path + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.convco.outputs.justfile + + + +The justfile code for importing this recipe’s justfile. + +See https://just.systems/man/en/chapter_53.html + + + +*Type:* +string *(read only)* + + + +*Default:* +` "" ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.convco.settings.file-name + + + +The name of the file to output the chaneglog to. + + + +*Type:* +string + + + +*Default:* +` "CHANGELOG.md" ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/convco.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/convco.nix) + + + +## just.recipes.git-cliff + + + +Add the ‘changelog’ target calling convco + + + +*Type:* +submodule + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/git-cliff.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/git-cliff.nix) + + + +## just.recipes.git-cliff.enable + + + +Whether to enable this recipe. + + + +*Type:* +boolean + + + +*Default:* +` false ` + + + +*Example:* +` true ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.git-cliff.package + + + +An optional package that provides the recipe. + + + +*Type:* +null or package + + + +*Default:* +` null ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.git-cliff.justfile + + + +The justfile representing this recipe. + + + +*Type:* +string or path + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.git-cliff.outputs.justfile + + + +The justfile code for importing this recipe’s justfile. + +See https://just.systems/man/en/chapter_53.html + + + +*Type:* +string *(read only)* + + + +*Default:* +` "" ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.git-cliff.settings.config-file + + + +The git-cliff config to use. + +See https://git-cliff.org/docs/configuration/ + + + +*Type:* +string + + + +*Default:* + +``` +'' + [changelog] + header = """ + # Changelog\n + All notable changes to this project will be documented in this file.\n + """ + body = """ + {% if version %}\ + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} + {% else %}\ + ## [unreleased] + {% endif %}\ + {% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | striptags | trim | upper_first }} + {% for commit in commits %} + - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ + {% if commit.breaking %}[**breaking**] {% endif %}\ + {{ commit.message | upper_first }}\ + {% endfor %} + {% endfor %}\n + """ + # template for the changelog footer + footer = """ + + """ + # remove the leading and trailing s + trim = true + + [git] + conventional_commits = true + filter_unconventional = true + split_commits = false + commit_parsers = [ + { message = "^feat", group = "🚀 Features" }, + { message = "^fix", group = "🐛 Bug Fixes" }, + { message = "^doc", group = "📚 Documentation" }, + { message = "^perf", group = "⚡ Performance" }, + { message = "^refactor", group = "🚜 Refactor" }, + { message = "^style", group = "🎨 Styling" }, + { message = "^test", group = "🧪 Testing" }, + { message = "^chore\\(release\\): prepare for", skip = true }, + { message = "^chore\\(deps.*\\)", skip = true }, + { message = "^chore\\(pr\\)", skip = true }, + { message = "^chore\\(pull\\)", skip = true }, + { message = "^chore|^ci", group = "⚙️ Miscellaneous Tasks" }, + { body = ".*security", group = "🛡️ Security" }, + { message = "^revert", group = "◀️ Revert" }, + ] + protect_breaking_commits = false + filter_commits = false + topo_order = false + sort_commits = "oldest" +'' +``` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/git-cliff.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/git-cliff.nix) + + + +## just.recipes.git-cliff.settings.file-name + + + +The name of the file to output the chaneglog to. + + + +*Type:* +string + + + +*Default:* +` "CHANGELOG.md" ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/git-cliff.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/git-cliff.nix) + + + +## just.recipes.git-cliff.settings.integrations.github.enable + + + +Whether to enable Enable the GitHub integration. See https://git-cliff.org/docs/integration/github. + + + +*Type:* +boolean + + + +*Default:* +` false ` + + + +*Example:* +` true ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/git-cliff.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/git-cliff.nix) + + + +## just.recipes.rust + + + +Add ‘w’ and ‘test’ targets for running cargo + + + +*Type:* +submodule + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/rust.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/rust.nix) + + + +## just.recipes.rust.enable + + + +Whether to enable this recipe. + + + +*Type:* +boolean + + + +*Default:* +` false ` + + + +*Example:* +` true ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.rust.package + + + +An optional package that provides the recipe. + + + +*Type:* +null or package + + + +*Default:* +` null ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.rust.justfile + + + +The justfile representing this recipe. + + + +*Type:* +string or path + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.rust.outputs.justfile + + + +The justfile code for importing this recipe’s justfile. + +See https://just.systems/man/en/chapter_53.html + + + +*Type:* +string *(read only)* + + + +*Default:* +` "" ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.up + +Starts processes in foreground. See http://devenv.sh/processes + + + +*Type:* +submodule + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/devenv-up.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipes/devenv-up.nix) + + + +## just.recipes.up.enable + + + +Whether to enable this recipe. + + + +*Type:* +boolean + + + +*Default:* +` false ` + + + +*Example:* +` true ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.up.package + + + +An optional package that provides the recipe. + + + +*Type:* +null or package + + + +*Default:* +` null ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.up.justfile + + + +The justfile representing this recipe. + + + +*Type:* +string or path + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + +## just.recipes.up.outputs.justfile + + + +The justfile code for importing this recipe’s justfile. + +See https://just.systems/man/en/chapter_53.html + + + +*Type:* +string *(read only)* + + + +*Default:* +` "" ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/just/recipe-module.nix) + + + ## languages.ansible.enable @@ -2370,6 +3102,8 @@ package ## languages.haskell.languageServer + + Haskell language server to use. @@ -4051,8 +4785,6 @@ boolean ## languages.purescript.package - - The PureScript package to use. @@ -4791,6 +5523,8 @@ boolean ## languages.robotframework.python + + The Python package to use. @@ -6931,8 +7665,6 @@ list of string ## pre-commit.hooks.\.types_or - - List of file types to run on, where only a single type needs to match. @@ -7639,6 +8371,8 @@ list of package ## pre-commit.hooks.ansible-lint.fail_fast + + if true pre-commit will stop running hooks if this hook fails. @@ -8849,8 +9583,6 @@ package ## pre-commit.hooks.clippy.packageOverrides.clippy - - The clippy package to use @@ -11160,8 +11892,6 @@ boolean ## pre-commit.hooks.denolint.description - - Description of the hook. Used for metadata purposes only. @@ -13198,8 +13928,6 @@ boolean ## pre-commit.hooks.flake8.settings.binPath - - flake8 binary path. Should be used to specify flake8 binary from your Nix-managed Python environment. @@ -15254,8 +15982,6 @@ submodule ## pre-commit.hooks.isort.enable - - Whether to enable this pre-commit hook. @@ -17418,8 +18144,6 @@ null or package ## pre-commit.hooks.markdownlint.always_run - - if true this hook will run even if there are no matching files. @@ -19484,8 +20208,6 @@ string ## pre-commit.hooks.nixfmt.excludes - - Exclude files that were matched by these patterns. @@ -21540,8 +22262,6 @@ submodule ## pre-commit.hooks.phpcs.enable - - Whether to enable this pre-commit hook. @@ -23705,8 +24425,6 @@ list of string ## pre-commit.hooks.psalm.extraPackages - - Additional packages required to run the hook. These are propagated to ` enabledPackages ` for constructing developer @@ -25806,8 +26524,6 @@ string ## pre-commit.hooks.ripsecrets.entry - - The entry point - the executable to run. ` entry ` can also contain arguments that will not be overridden, such as ` entry = "autopep8 -i"; `. @@ -27878,8 +28594,6 @@ list of string ## pre-commit.hooks.statix.verbose - - forces the output of the hook to be printed even when the hook passes. @@ -30037,8 +30751,6 @@ boolean ## pre-commit.hooks.yamllint.stages - - Confines the hook to run at a particular stage. @@ -30778,6 +31490,27 @@ string +## scripts.\.just.enable + + + +Include this script in just runner. + + + +*Type:* +boolean + + + +*Default:* +` false ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/scripts.nix](https://github.com/cachix/devenv/blob/main/src/modules/scripts.nix) + + + ## services.adminer.enable @@ -31199,7 +31932,7 @@ path *Default:* -` "/home/runner/work/devenv/devenv/.devenv/state/caddy" ` +` "/home/sincore/source/devenv/.devenv/state/caddy" ` *Declared by:* - [https://github.com/cachix/devenv/blob/main/src/modules/services/caddy.nix](https://github.com/cachix/devenv/blob/main/src/modules/services/caddy.nix) @@ -32440,8 +33173,6 @@ boolean ## services.httpbin.bind - - Addresses for httpbin to listen on. @@ -35781,16 +36512,16 @@ unspecified value *(read only)* ``` { bindir = "/nix/store/p4vjvd38l79jsxzxlv9q2hbajm7g2js9-trafficserver-9.2.3/bin"; - cachedir = "/home/runner/work/devenv/devenv/.devenv/state/trafficserver/cache"; - datadir = "/home/runner/work/devenv/devenv/.devenv/state/trafficserver/share"; - exec_prefix = "/home/runner/work/devenv/devenv/.devenv/state/trafficserver"; + cachedir = "/home/sincore/source/devenv/.devenv/state/trafficserver/cache"; + datadir = "/home/sincore/source/devenv/.devenv/state/trafficserver/share"; + exec_prefix = "/home/sincore/source/devenv/.devenv/state/trafficserver"; includedir = "/nix/store/p4vjvd38l79jsxzxlv9q2hbajm7g2js9-trafficserver-9.2.3/include"; libdir = "/nix/store/p4vjvd38l79jsxzxlv9q2hbajm7g2js9-trafficserver-9.2.3/lib"; libexecdir = "/nix/store/p4vjvd38l79jsxzxlv9q2hbajm7g2js9-trafficserver-9.2.3/libexec"; - localstatedir = "/home/runner/work/devenv/devenv/.devenv/state/trafficserver/state"; - logdir = "/home/runner/work/devenv/devenv/.devenv/state/trafficserver/log"; - prefix = "/home/runner/work/devenv/devenv/.devenv/state/trafficserver"; - runtimedir = "/run/user/1001/devenv-0957646/trafficserver"; + localstatedir = "/home/sincore/source/devenv/.devenv/state/trafficserver/state"; + logdir = "/home/sincore/source/devenv/.devenv/state/trafficserver/log"; + prefix = "/home/sincore/source/devenv/.devenv/state/trafficserver"; + runtimedir = "/run/user/1000/devenv-cdc0ceb/trafficserver"; sbindir = "/nix/store/p4vjvd38l79jsxzxlv9q2hbajm7g2js9-trafficserver-9.2.3/bin"; sysconfdir = ; } @@ -35922,7 +36653,7 @@ strings concatenated with “\\n” *Default:* -` "/home/runner/work/devenv/devenv/.devenv/state/trafficserver/cache 256M" ` +` "/home/sincore/source/devenv/.devenv/state/trafficserver/cache 256M" ` diff --git a/justfile b/justfile new file mode 100644 index 000000000..434376193 --- /dev/null +++ b/justfile @@ -0,0 +1,5 @@ +import 'just-flake.just' + +# Display the list of recipes +default: + @just --list diff --git a/src/modules/integrations/just/default.nix b/src/modules/integrations/just/default.nix new file mode 100644 index 000000000..d86976eaf --- /dev/null +++ b/src/modules/integrations/just/default.nix @@ -0,0 +1,76 @@ +# This largely inspired by the use of freeformType in +# https://github.com/cachix/git-hooks.nix/blob/master/modules/hooks.nix +# as well as https://github.com/juspay/just-flake/tree/main +{ pkgs, lib, config, ... }: + +let + inherit (lib) types mkOption mkEnableOption attrsets; + inherit (import ./utils.nix { inherit lib pkgs; }) recipeModule recipeType; + + version = lib.fileContents ./../../latest-version; + + # Returns a list of all the entries in a folder + listEntries = path: + map (name: path + "/${name}") (builtins.attrNames (builtins.readDir path)); + + +in +{ + + imports = [{ + options.just.recipes = mkOption { + type = types.submoduleWith { + modules = [{ freeformType = types.attrsOf recipeType; }]; + specialArgs = { inherit pkgs; }; + }; + default = { }; + }; + }] + ++ (listEntries ./recipes); + + options.just = { + enable = mkEnableOption "the just command runner"; + + package = mkOption { + type = types.package; + default = pkgs.just; + defaultText = lib.literalExpression "pkgs.just"; + description = "The just package to use."; + }; + + commonFileName = mkOption { + type = types.str; + default = "just-flake.just"; + description = '' + The name of the common justfile generated by this module. + ''; + }; + + }; + + config = lib.mkIf config.just.enable { + + packages = [ + config.just.package + ]; + + enterShell = + let + commonJustfile = pkgs.writeTextFile { + name = "justfile"; + text = + lib.concatStringsSep "\n" + (lib.mapAttrsToList (name: recipe: recipe.outputs.justfile) config.just.recipes); + }; + in + '' + ln -sf ${builtins.toString commonJustfile} ./${config.just.commonFileName} + + echo + echo "https://devenv.sh (version ${version}): Fast, Declarative, Reproducible, and Composable Developer Environments 🦾🦾" + echo + echo "Run 'just ' to get started" + just --list + ''; + }; +} diff --git a/src/modules/integrations/just/recipe-module.nix b/src/modules/integrations/just/recipe-module.nix new file mode 100644 index 000000000..c2435c80d --- /dev/null +++ b/src/modules/integrations/just/recipe-module.nix @@ -0,0 +1,43 @@ +{ config, name, lib, pkgs, ... }: +let + inherit (lib) mkOption mkEnableOption types; + +in +{ + options = { + enable = mkEnableOption "this recipe"; + justfile = mkOption { + type = types.either types.str types.path; + description = '' + The justfile representing this recipe. + ''; + apply = x: + if builtins.isPath x then x else + pkgs.writeTextFile { + name = "${name}.just"; + text = x; + }; + }; + package = mkOption { + type = types.nullOr types.package; + default = null; + description = lib.mdDoc + '' + An optional package that provides the recipe. + ''; + }; + outputs.justfile = mkOption { + type = types.str; + readOnly = true; + description = '' + The justfile code for importing this recipe's justfile. + + See https://just.systems/man/en/chapter_53.html + ''; + default = + if config.enable + then "import '${builtins.toString config.justfile}'" + else ""; + }; + }; +} diff --git a/src/modules/integrations/just/recipes/convco.nix b/src/modules/integrations/just/recipes/convco.nix new file mode 100644 index 000000000..4101e144e --- /dev/null +++ b/src/modules/integrations/just/recipes/convco.nix @@ -0,0 +1,37 @@ +{ pkgs, lib, config, ... }: + +let + inherit (lib) types mkOption mkEnableOption; + inherit (import ../utils.nix { inherit lib pkgs; }) recipeModule recipeType; + +in +{ + options.just.recipes.convco = mkOption { + description = "Add the 'changelog' target calling convco"; + type = types.submodule { + imports = [ recipeModule ]; + options.settings = { + file-name = + mkOption { + type = types.str; + description = lib.mdDoc "The name of the file to output the chaneglog to."; + default = "CHANGELOG.md"; + }; + }; + }; + }; + + config.just.recipes.convco = lib.mkIf config.just.enable { + package = lib.mkDefault pkgs.convco; + justfile = + let + binPath = lib.getExe config.just.recipes.convco.package; + fileName = config.just.recipes.convco.settings.file-name; + in + lib.mkDefault '' + # Generate ${fileName} using recent commits + changelog: + ${binPath} changelog -p "" > ${fileName} + ''; + }; +} diff --git a/src/modules/integrations/just/recipes/devenv-script.nix b/src/modules/integrations/just/recipes/devenv-script.nix new file mode 100644 index 000000000..d16212e4d --- /dev/null +++ b/src/modules/integrations/just/recipes/devenv-script.nix @@ -0,0 +1,42 @@ +{ pkgs, lib, config, ... }: + +let + inherit (lib) types mkOption mkEnableOption; + inherit (import ../utils.nix { inherit lib pkgs; }) recipeModule recipeType; + + devenvScriptRecipes = lib.genAttrs (builtins.attrNames config.scripts) (name: + let + script = config.scripts.${name}; + in + mkOption { + description = script.description; + type = types.submodule { + imports = [ recipeModule ]; + }; + }); + +in +{ + options = { + just = { + recipes = devenvScriptRecipes; + }; + }; + + config = lib.mkIf config.just.enable { + just = { + recipes = lib.genAttrs (builtins.attrNames config.scripts) (name: + let + script = config.scripts.${name}; + in + { + enable = lib.mkDefault script.just.enable; + justfile = lib.mkDefault '' + #${script.description} + ${name}: + ${name} + ''; + }); + }; + }; +} diff --git a/src/modules/integrations/just/recipes/devenv-up.nix b/src/modules/integrations/just/recipes/devenv-up.nix new file mode 100644 index 000000000..50ec11cbe --- /dev/null +++ b/src/modules/integrations/just/recipes/devenv-up.nix @@ -0,0 +1,24 @@ +{ pkgs, lib, config, ... }: + +let + inherit (lib) types mkOption mkEnableOption; + inherit (import ../utils.nix { inherit lib pkgs; }) recipeModule recipeType; + +in +{ + options.just.recipes.up = mkOption { + description = "Starts processes in foreground. See http://devenv.sh/processes"; + type = types.submodule { + imports = [ recipeModule ]; + }; + }; + + config.just.recipes.up = lib.mkIf config.just.enable { + enable = lib.mkDefault true; + justfile = lib.mkDefault '' + # Starts processes in foreground. See http://devenv.sh/processes + up: + devenv up + ''; + }; +} diff --git a/src/modules/integrations/just/recipes/git-cliff.nix b/src/modules/integrations/just/recipes/git-cliff.nix new file mode 100644 index 000000000..668b31359 --- /dev/null +++ b/src/modules/integrations/just/recipes/git-cliff.nix @@ -0,0 +1,132 @@ +{ pkgs, lib, config, ... }: + +let + inherit (lib) types mkOption mkEnableOption; + inherit (import ../utils.nix { inherit lib pkgs; }) recipeModule recipeType; + + cfg = config.just.recipes.git-cliff; + fileName = cfg.settings.file-name; + + git-cliff-config = pkgs.writeTextFile { + name = "cliff.toml"; + text = cfg.settings.config-file; + }; + + git-cliff-entry = pkgs.writeShellScriptBin "git-cliff" '' + ${lib.optionalString cfg.settings.integrations.github.enable '' + # Get the remote URL + REMOTE_URL=$(git config --get remote.origin.url) + + # Extract the owner and repo name from the URL + if [[ $REMOTE_URL =~ ^https://github.com/(.*)/(.*)\.git$ ]]; then + OWNER=''${BASH_REMATCH[1]} + REPO=''${BASH_REMATCH[2]} + elif [[ $REMOTE_URL =~ ^git@github.com:(.*)/(.*)\.git$ ]]; then + OWNER=''${BASH_REMATCH[1]} + REPO=''${BASH_REMATCH[2]} + else + echo "Unsupported remote URL format: $REMOTE_URL" + exit 1 + fi + + # Combine owner and repo name + GITHUB_REPO="$OWNER/$REPO" + ''} + + ${lib.getExe' cfg.package "git-cliff"} \ + --output ${fileName} \ + --config ${git-cliff-config.outPath} + ''; + +in +{ + options.just.recipes.git-cliff = mkOption { + description = "Add the 'changelog' target calling convco"; + type = types.submodule { + imports = [ recipeModule ]; + options.settings = { + file-name = + mkOption { + type = types.str; + description = lib.mdDoc "The name of the file to output the chaneglog to."; + default = "CHANGELOG.md"; + }; + + config-file = mkOption { + type = types.str; + description = '' + The git-cliff config to use. + + See https://git-cliff.org/docs/configuration/ + ''; + default = '' + [changelog] + header = """ + # Changelog\n + All notable changes to this project will be documented in this file.\n + """ + body = """ + {% if version %}\ + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} + {% else %}\ + ## [unreleased] + {% endif %}\ + {% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | striptags | trim | upper_first }} + {% for commit in commits %} + - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ + {% if commit.breaking %}[**breaking**] {% endif %}\ + {{ commit.message | upper_first }}\ + {% endfor %} + {% endfor %}\n + """ + # template for the changelog footer + footer = """ + + """ + # remove the leading and trailing s + trim = true + + [git] + conventional_commits = true + filter_unconventional = true + split_commits = false + commit_parsers = [ + { message = "^feat", group = "🚀 Features" }, + { message = "^fix", group = "🐛 Bug Fixes" }, + { message = "^doc", group = "📚 Documentation" }, + { message = "^perf", group = "⚡ Performance" }, + { message = "^refactor", group = "🚜 Refactor" }, + { message = "^style", group = "🎨 Styling" }, + { message = "^test", group = "🧪 Testing" }, + { message = "^chore\\(release\\): prepare for", skip = true }, + { message = "^chore\\(deps.*\\)", skip = true }, + { message = "^chore\\(pr\\)", skip = true }, + { message = "^chore\\(pull\\)", skip = true }, + { message = "^chore|^ci", group = "⚙️ Miscellaneous Tasks" }, + { body = ".*security", group = "🛡️ Security" }, + { message = "^revert", group = "◀️ Revert" }, + ] + protect_breaking_commits = false + filter_commits = false + topo_order = false + sort_commits = "oldest" + ''; + }; + integrations = { + github.enable = mkEnableOption "GitHub integration. See https://git-cliff.org/docs/integration/github"; + }; + }; + }; + }; + + config.just.recipes.git-cliff = lib.mkIf config.just.enable { + package = lib.mkDefault pkgs.git-cliff; + justfile = lib.mkDefault + '' + # Generate ${fileName} using recent commits + changelog: + ${git-cliff-entry}/bin/git-cliff + ''; + }; +} diff --git a/src/modules/integrations/just/recipes/rust.nix b/src/modules/integrations/just/recipes/rust.nix new file mode 100644 index 000000000..76b427bcc --- /dev/null +++ b/src/modules/integrations/just/recipes/rust.nix @@ -0,0 +1,27 @@ +{ pkgs, lib, config, ... }: + +let + inherit (lib) types mkOption mkEnableOption; + inherit (import ../utils.nix { inherit lib pkgs; }) recipeModule recipeType; + +in +{ + options.just.recipes.rust = mkOption { + description = "Add 'w' and 'test' targets for running cargo"; + type = types.submodule { + imports = [ recipeModule ]; + }; + }; + + config.just.recipes.rust = lib.mkIf config.just.enable { + justfile = lib.mkDefault '' + # Compile and watch the project + w: + cargo watch + + # Run and watch 'cargo test' + test: + cargo watch -s "cargo test" + ''; + }; +} diff --git a/src/modules/integrations/just/utils.nix b/src/modules/integrations/just/utils.nix new file mode 100644 index 000000000..9dcbbab46 --- /dev/null +++ b/src/modules/integrations/just/utils.nix @@ -0,0 +1,24 @@ +{ lib, pkgs, ... }: +let + inherit (lib) types; + inherit (lib.attrsets) recursiveUpdate; + + recipeModule = { + imports = [ ./recipe-module.nix ]; + config._module.args = { inherit pkgs; }; + }; + recipeType = types.submodule recipeModule; + + mkCmdArgs = predActionList: + lib.concatStringsSep + " " + (builtins.foldl' + (acc: entry: + acc ++ lib.optional (builtins.elemAt entry 0) (builtins.elemAt entry 1)) + [ ] + predActionList); + +in +{ + inherit mkCmdArgs recipeModule recipeType; +} diff --git a/src/modules/scripts.nix b/src/modules/scripts.nix index c74ece408..168e41f57 100644 --- a/src/modules/scripts.nix +++ b/src/modules/scripts.nix @@ -29,6 +29,13 @@ let description = "Description of the script."; default = ""; }; + just = { + enable = lib.mkOption { + type = types.bool; + description = "Include this script in just runner."; + default = false; + }; + }; scriptPackage = lib.mkOption { internal = true; type = types.package; diff --git a/tests/just/.test.sh b/tests/just/.test.sh new file mode 100644 index 000000000..b4cfda711 --- /dev/null +++ b/tests/just/.test.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -ex +just | grep "Generate CHANGELOG.md using recent commits" +just | grep "test hello" +just | grep "Hello Script" diff --git a/tests/just/devenv.nix b/tests/just/devenv.nix new file mode 100644 index 000000000..11c0d6d78 --- /dev/null +++ b/tests/just/devenv.nix @@ -0,0 +1,25 @@ +{ pkgs, ... }: { + just = { + enable = true; + recipes = { + convco.enable = true; + hello = { + enable = true; + justfile = '' + # test hello + hello: + echo Hello World; + ''; + }; + }; + }; + + scripts.hello-scripts = { + exec = '' + echo "Hello Script!" + ''; + description = "Hello Script"; + just.enable = true; + }; + +}