diff --git a/.config.nix b/.config.nix index b1eb441..ba6fd31 100644 --- a/.config.nix +++ b/.config.nix @@ -1,4 +1,4 @@ -{ plugins, tools }: +{ exts, system, tools }: let colors = { black = "#000000"; @@ -246,11 +246,11 @@ let in [ - (plugins.ghsettings github) - (plugins.conform conform) - (plugins.just just) - (plugins.lefthook lefthook) - (plugins.prettier prettier) - (plugins.prettier prettier-ignore) + (exts.ghsettings.${system} github) + (exts.conform.${system} conform) + (exts.just.${system} just) + (exts.lefthook.${system} lefthook) + (exts.prettier.${system} prettier) + (exts.prettier.${system} prettier-ignore) ] diff --git a/flake.lock b/flake.lock index 7a89635..d9eb66a 100644 --- a/flake.lock +++ b/flake.lock @@ -15,6 +15,80 @@ "type": "github" } }, + "flake-utils_2": { + "locked": { + "lastModified": 1653893745, + "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "locked": { + "lastModified": 1653893745, + "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixago": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": [ + "nixago-exts", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1655405483, + "narHash": "sha256-Crd49aZWNrpczlRTOwWGfwBMsTUoG9vlHDKQC7cx264=", + "owner": "nix-community", + "repo": "nixago", + "rev": "e6a9566c18063db5b120e69e048d3627414e327d", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixago", + "type": "github" + } + }, + "nixago-exts": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixago": "nixago", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1655508669, + "narHash": "sha256-BDDdo5dZQMmwNH/GNacy33nPBnCpSIydWFPZs0kkj/g=", + "owner": "nix-community", + "repo": "nixago-extensions", + "rev": "3022a932ce109258482ecc6568c163e8d0b426aa", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixago-extensions", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1654568412, @@ -33,6 +107,7 @@ "root": { "inputs": { "flake-utils": "flake-utils", + "nixago-exts": "nixago-exts", "nixpkgs": "nixpkgs" } } diff --git a/flake.nix b/flake.nix index 28a0712..35c3ba2 100644 --- a/flake.nix +++ b/flake.nix @@ -2,9 +2,11 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs"; flake-utils.url = "github:numtide/flake-utils"; + nixago-exts.url = "github:nix-community/nixago-extensions"; + nixago-exts.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, nixpkgs, flake-utils }: + outputs = { self, nixpkgs, flake-utils, nixago-exts }: rec { # Only run CI on Linux herculesCI.ciSystems = [ "x86_64-linux" "aarch64-linux" ]; @@ -26,7 +28,6 @@ engines = import ./engines { inherit pkgs lib; }; lib = (import ./lib { inherit pkgs lib engines; }); - plugins = import ./plugins { inherit pkgs lib engines; }; # Setup pkgs pkgs = import nixpkgs { @@ -59,11 +60,12 @@ ]; # Define development tool configuration (with Nixago!) - configs = import ./.config.nix { inherit plugins tools; }; + configs = + import ./.config.nix { inherit system tools; exts = nixago-exts; }; in rec { # Expose external API - inherit engines lib plugins; + inherit engines lib; # Add local tests checks = import ./tests { inherit pkgs lib engines runTests; }; diff --git a/plugins/conform/default.nix b/plugins/conform/default.nix deleted file mode 100644 index a907a54..0000000 --- a/plugins/conform/default.nix +++ /dev/null @@ -1,29 +0,0 @@ -{ pkgs, lib, engines }: -{ commit ? { }, license ? { } }: -with pkgs.lib; -let - # Expand out the configuration - configData = { - policies = - (optional - (commit != { }) - { - type = "commit"; - spec = commit; - }) ++ - (optional - (license != { }) - { - type = "license"; - spec = license; - }); - }; -in -{ - inherit configData; - format = "yaml"; - output = ".conform.yaml"; - engine = engines.cue { - files = [ ./templates/default.cue ]; - }; -} diff --git a/plugins/conform/templates/default.cue b/plugins/conform/templates/default.cue deleted file mode 100644 index a8feb71..0000000 --- a/plugins/conform/templates/default.cue +++ /dev/null @@ -1,56 +0,0 @@ -#CommitSpec: { - header: { - body?: { - required?: bool - } - case?: string - conventional?: { - descriptionLength?: int - scopes?: [...string] - types?: [...string] - } - dco?: bool - gpg?: { - identity?: { - gitHubOrganization?: string - } - required?: bool - } - imperative?: bool - invalidLastCharacters?: string - jira?: [string]: [...string] - length?: int - maximumOfOneCommit?: bool - spellcheck?: { - locale?: string - } - } - ... -} - -#LicenseSpec: { - allowPrecedingComments?: bool - excludeSuffixes?: [...string] - header?: string - includeSuffixes?: [...string] - skipPaths?: [...string] - ... -} - -#CommitPolicy: { - type: "commit" - spec: #CommitSpec -} - -#LicensePolicy: { - type: "license" - spec: #LicenseSpec -} - -#Config: { - policies: [...#CommitPolicy | #LicensePolicy] -} - -{ - #Config -} \ No newline at end of file diff --git a/plugins/default.nix b/plugins/default.nix deleted file mode 100644 index b903a9e..0000000 --- a/plugins/default.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ pkgs, lib, engines }: -with pkgs.lib; -let - # Build a list of all local directory names (same as plugin name) - plugins = builtins.attrNames - (filterAttrs (n: v: v == "directory") (builtins.readDir ./.)); - - # Create a list of pluginName => import for each plugin - pluginsList = builtins.map - (p: { - "${p}" = import - (builtins.toPath ./. + "/${p}") - { inherit pkgs lib engines; }; - }) - plugins; - - # Fold the list back into a single set - pluginsAttrs = fold (x: y: pkgs.lib.recursiveUpdate x y) { } pluginsList; -in -pluginsAttrs diff --git a/plugins/ghsettings/default.nix b/plugins/ghsettings/default.nix deleted file mode 100644 index f4a69ef..0000000 --- a/plugins/ghsettings/default.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ pkgs, lib, engines }: -configData: -{ - inherit configData; - format = "yaml"; - output = ".github/settings.yml"; - hook.mode = "copy"; - engine = engines.cue { - files = [ ./templates/default.cue ]; - }; -} diff --git a/plugins/ghsettings/templates/default.cue b/plugins/ghsettings/templates/default.cue deleted file mode 100644 index 953a902..0000000 --- a/plugins/ghsettings/templates/default.cue +++ /dev/null @@ -1,85 +0,0 @@ -#Config: { - repository?: #Repository - labels?: [...#Label] - milestones?: [...#Milestone] - collaborators?: [...#Collaborator] - teams?: [...#Team] - branches?: [...#Branch] - ... -} - -#Repository: { - name?: string - description?: string - homepage?: string - topics?: string - private?: bool - has_issues?: bool - has_projects?: bool - has_wiki?: bool - has_downloads?: bool - default_branch?: string - allow_squash_merge?: bool - allow_merge_commit?: bool - allow_rebase_merge?: bool - delete_branch_on_merge?: bool - enable_automated_security_fixes?: bool - enable_vulnerability_alerts?: bool - ... -} - -#Label: { - name?: string - color?: string - description?: string - ... -} - -#Milestone: { - title?: string - description?: string - state?: string - ... -} - -#Collaborator: { - username?: string - permission?: string - ... -} - -#Team: { - name?: string - permission?: string - ... -} - -#Branch: { - name?: string - protection?: #Protection - ... -} - -#Protection: { - required_pull_request_reviews?: { - required_approving_review_count?: int - dismiss_stale_reviews?: bool - require_code_owner_reviews?: bool - dismissal_restrictions?: { - users?: [...string] - teams?: [...string] - } - } - required_status_checks?: { - strict?: bool - contexts?: [...string] - } - enforce_admins?: bool - required_linear_history?: bool - restrictions?: { - apps?: [...string] - users?: [...string] - teams?: [...string] - } - ... -} \ No newline at end of file diff --git a/plugins/just/default.nix b/plugins/just/default.nix deleted file mode 100644 index 465211b..0000000 --- a/plugins/just/default.nix +++ /dev/null @@ -1,31 +0,0 @@ -{ pkgs, lib, engines }: -{ head ? "", tasks }: -let - # Expand configuration data - configData = { - data = { - inherit head tasks; - }; - }; - - # Run the formatter since the output from the Go template engine is ugly - postHook = '' - cat $out - ${pkgs.just}/bin/just --unstable --fmt -f $out - ''; - - # Need to explicitly tell cue what expression to render as text output - flags = { - expression = "rendered"; - out = "text"; - }; -in -{ - inherit configData; - format = "text"; - output = ".justfile"; - engine = engines.cue { - inherit flags postHook; - files = [ ./templates/default.cue ]; - }; -} diff --git a/plugins/just/templates/default.cue b/plugins/just/templates/default.cue deleted file mode 100644 index 536bd8c..0000000 --- a/plugins/just/templates/default.cue +++ /dev/null @@ -1,29 +0,0 @@ -import "strings" -import "text/template" - -#Config: { - head: string | *"" - tasks: [string]: [...string] -} - -data: #Config - -_final: { - head: data.head - tasks: { - for task, steps in data.tasks { - "\(task)": strings.Join(steps, "\n ") - } - } -} - -tmpl: -""" -{{ .head -}} -{{ range $name, $steps := .tasks }} -{{ $name }}: - {{ $steps }} -{{- end }} -""" - -rendered: template.Execute(tmpl, _final) diff --git a/plugins/lefthook/default.nix b/plugins/lefthook/default.nix deleted file mode 100644 index 296a201..0000000 --- a/plugins/lefthook/default.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ pkgs, lib, engines }: -configData: -with pkgs.lib; -let - lefthook = pkgs.lefthook; - - # Add an extra hook for adding required stages whenever the file changes - skip_attrs = [ - "colors" - "extends" - "skip_output" - "source_dir" - "source_dir_local" - ]; - stages = builtins.attrNames (builtins.removeAttrs configData skip_attrs); - stagesStr = builtins.concatStringsSep " " stages; - extra = '' - # Install configured hooks - for stage in ${stagesStr}; do - ${lefthook}/bin/lefthook add -a "$stage" - done - ''; -in -{ - inherit configData; - format = "yaml"; - output = "lefthook.yml"; - hook = { inherit extra; }; - engine = engines.cue { - files = [ ./templates/default.cue ]; - }; -} diff --git a/plugins/lefthook/templates/default.cue b/plugins/lefthook/templates/default.cue deleted file mode 100644 index 02424cb..0000000 --- a/plugins/lefthook/templates/default.cue +++ /dev/null @@ -1,38 +0,0 @@ -#Config: { - [string]: #Hook - colors?: bool | *true - extends?: [...string] - skip_output?: [...string] - source_dir?: string - source_dir_local?: string - ... -} - -#Hook: { - commands?: [string]: #Command - exclude_tags?: [...string] - parallel?: bool | *false - piped?: bool | *false - scripts?: [string]: #Script - ... -} - -#Command: { - exclude?: string - files?: string - glob?: string - root?: string - run: string - skip?: bool | [...string] - tags?: string - ... -} - -#Script: { - runner: string - ... -} - -{ - #Config -} \ No newline at end of file diff --git a/plugins/pre-commit/default.nix b/plugins/pre-commit/default.nix deleted file mode 100644 index 14421b4..0000000 --- a/plugins/pre-commit/default.nix +++ /dev/null @@ -1,72 +0,0 @@ -{ pkgs, lib, engines }: -configData: -with pkgs.lib; -let - pre-commit = pkgs.pre-commit; - - # A list of all valid pre-commit stages - hooksStr = builtins.concatStringsSep " " [ - "pre-commit" - "pre-merge-commit" - "pre-push" - "prepare-commit-msg" - "commit-msg" - "post-checkout" - "post-commit" - ]; - - # Builds stages list from data - getStages = data: - unique (flatten - (builtins.map - (hook: optionals (hook ? stages) hook.stages) - (attrValues data))); - - # Builds up simplified config format to the expected format - buildData = data: - let - hooks = attrValues (pkgs.lib.mapAttrs - (id: hook: ( - { inherit id; name = if (hook ? name) then hook.name else id; } // hook - )) - data); - in - { - repos = [ - { - inherit hooks; - repo = "local"; - } - ]; - }; - - # Build list of stages to install - stages = getStages configData; - stagesStr = builtins.concatStringsSep " " stages; - -in -{ - configData = buildData configData; - format = "yaml"; - output = ".pre-commit-config.yaml"; - hook = { - extra = '' - # Uninstall all existing hooks - for hook in ${hooksStr}; do - ${pre-commit}/bin/pre-commit uninstall -t $hook - done - - # Install configured hooks - for stage in ${stagesStr}; do - if [[ "$stage" == "manual" ]]; then - continue - fi - - ${pre-commit}/bin/pre-commit install -t "$stage" - done - ''; - }; - engine = engines.cue { - files = [ ./templates/default.cue ]; - }; -} diff --git a/plugins/pre-commit/templates/default.cue b/plugins/pre-commit/templates/default.cue deleted file mode 100644 index 8835db5..0000000 --- a/plugins/pre-commit/templates/default.cue +++ /dev/null @@ -1,43 +0,0 @@ -#Config: { - default_install_hook_types?: [...string] - default_language_version?: [string]: string - default_stages?: [...string] - files?: string - exclude?: string - fail_fast?: bool - minimum_pre_commit_version?: string - repos: [...#Repo] -} - -#Hook: { - additional_dependencies?: [...string] - alias?: string - always_run?: bool - args?: [...string] - entry?: string - exclude?: string - exclude_types?: [...string] - files?: string - id: string - language?: string - language_version?: string - log_file?: string - name?: string - stages?: [...string] - types?: [...string] - types_or?: [...string] - verbose?: bool -} - -#Repo: { - repo: string - rev?: string - if repo != "local" { - rev: string - } - hooks: [...#Hook] -} - -{ - #Config -} \ No newline at end of file diff --git a/plugins/prettier/default.nix b/plugins/prettier/default.nix deleted file mode 100644 index 6fb3def..0000000 --- a/plugins/prettier/default.nix +++ /dev/null @@ -1,21 +0,0 @@ -{ pkgs, lib, engines }: -{ configData, type ? "default" }: -with pkgs.lib; -{ - inherit configData; - format = "json"; - output = ".prettierrc.json"; - engine = engines.cue { - files = [ ./templates/default.cue ]; - }; -} // optionalAttrs (type == "ignore") { - configData = { data = configData; }; - format = "text"; - output = ".prettierignore"; - engine = engines.cue { - files = [ ./templates/ignore.cue ]; - flags = { - expression = "rendered"; - }; - }; -} diff --git a/plugins/prettier/make_ignore.nix b/plugins/prettier/make_ignore.nix deleted file mode 100644 index 54ab291..0000000 --- a/plugins/prettier/make_ignore.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ pkgs, lib }: -userData: -let - flags = { - expression = "rendered"; - out = "text"; - }; - configData = { data = userData.configData; }; -in -{ - inherit configData; - cue = { - inherit flags; - }; -} diff --git a/plugins/prettier/templates/default.cue b/plugins/prettier/templates/default.cue deleted file mode 100644 index 275f357..0000000 --- a/plugins/prettier/templates/default.cue +++ /dev/null @@ -1,123 +0,0 @@ -// Generated from http://json.schemastore.org/prettierrc -#Config: { - // Schema for .prettierrc - @jsonschema(schema="http://json-schema.org/draft-04/schema#") - #optionsDefinition & #overridesDefinition | string - - #optionsDefinition: { - // Include parentheses around a sole arrow function parameter. - arrowParens?: "always" | "avoid" | *"always" - - // Put > of opening tags on the last line instead of on a new - // line. - bracketSameLine?: bool | *false - - // Print spaces between brackets. - bracketSpacing?: bool | *true - - // Print (to stderr) where a cursor at the given position would - // move to after formatting. - // This option cannot be used with --range-start and --range-end. - cursorOffset?: int | *-1 - - // Control how Prettier formats quoted code embedded in the file. - embeddedLanguageFormatting?: "auto" | "off" | *"auto" - - // Which end of line characters to apply. - endOfLine?: "lf" | "crlf" | "cr" | "auto" | *"lf" - - // Specify the input filepath. This will be used to do parser - // inference. - filepath?: string - - // How to handle whitespaces in HTML. - htmlWhitespaceSensitivity?: "css" | "strict" | "ignore" | *"css" - - // Insert @format pragma into file's first docblock comment. - insertPragma?: bool | *false - - // Use single quotes in JSX. - jsxSingleQuote?: bool | *false - - // Which parser to use. - parser?: ("flow" | "babel" | "babel-flow" | "babel-ts" | "typescript" | "acorn" | "espree" | "meriyah" | "css" | "less" | "scss" | "json" | "json5" | "json-stringify" | "graphql" | "markdown" | "mdx" | "vue" | "yaml" | "glimmer" | "html" | "angular" | "lwc" | string) & string - - // Custom directory that contains prettier plugins in node_modules - // subdirectory. - // Overrides default behavior when plugins are searched relatively - // to the location of Prettier. - // Multiple values are accepted. - pluginSearchDirs?: [...string] | false | *[] - - // Add a plugin. Multiple plugins can be passed as separate - // `--plugin`s. - plugins?: [...string] - - // The line length where Prettier will try wrap. - printWidth?: int | *80 - - // How to wrap prose. - proseWrap?: "always" | "never" | "preserve" | *"preserve" - - // Change when properties in objects are quoted. - quoteProps?: "as-needed" | "consistent" | "preserve" | *"as-needed" - - // Format code ending at a given character offset (exclusive). - // The range will extend forwards to the end of the selected - // statement. - // This option cannot be used with --cursor-offset. - rangeEnd?: int | *null - - // Format code starting at a given character offset. - // The range will extend backwards to the start of the first line - // containing the selected statement. - // This option cannot be used with --cursor-offset. - rangeStart?: int | *0 - - // Require either '@prettier' or '@format' to be present in the - // file's first docblock comment - // in order for it to be formatted. - requirePragma?: bool | *false - - // Print semicolons. - semi?: bool | *true - - // Enforce single attribute per line in HTML, Vue and JSX. - singleAttributePerLine?: bool | *false - - // Use single quotes instead of double quotes. - singleQuote?: bool | *false - - // Number of spaces per indentation level. - tabWidth?: int | *2 - - // Print trailing commas wherever possible when multi-line. - trailingComma?: "es5" | "none" | "all" | *"es5" - - // Indent with tabs instead of spaces. - useTabs?: bool | *false - - // Indent script and style tags in Vue files. - vueIndentScriptAndStyle?: bool | *false - ... - } - - #overridesDefinition: { - // Provide a list of patterns to override prettier configuration. - overrides?: [...{ - // Include these files in this override. - files: string | [...string] - - // Exclude these files from this override. - excludeFiles?: string | [...string] - - // The options to apply for this override. - options?: #optionsDefinition - }] - ... - } -} - -{ - #Config -} \ No newline at end of file diff --git a/plugins/prettier/templates/ignore.cue b/plugins/prettier/templates/ignore.cue deleted file mode 100644 index 9daff26..0000000 --- a/plugins/prettier/templates/ignore.cue +++ /dev/null @@ -1,5 +0,0 @@ -import "strings" - -data: [...string] - -rendered: strings.Join(data, "\n") \ No newline at end of file