From 546eda3ee24807a251346b2e0c2d889b00c2d93e Mon Sep 17 00:00:00 2001 From: matt1432 Date: Mon, 20 Jan 2025 12:34:07 -0500 Subject: [PATCH] feat: refactor to add apps README --- _outputs.nix | 4 ++-- apps/README.md | 11 +++++++++++ apps/buildApp.nix | 19 ++++++++++--------- apps/default.nix | 27 +++++++++------------------ apps/extract-subs/default.nix | 4 ++++ apps/gen-docs/default.nix | 4 ++++ apps/gen-docs/script.sh | 5 +++-- apps/gen-docs/templates/apps.md | 11 +++++++++++ apps/gen-docs/templates/devShells.md | 2 +- apps/packages.nix | 19 ++++++++++--------- apps/update-sources/default.nix | 5 +++++ devShells/README.md | 22 +++++++++++----------- 12 files changed, 81 insertions(+), 52 deletions(-) create mode 100644 apps/README.md create mode 100644 apps/gen-docs/templates/apps.md diff --git a/_outputs.nix b/_outputs.nix index b0cdf533..d8cd3331 100644 --- a/_outputs.nix +++ b/_outputs.nix @@ -133,11 +133,11 @@ apps = perSystem (pkgs: - import ./apps {inherit inputs pkgs;}); + import ./apps {inherit pkgs self;}); appsPackages = perSystem (pkgs: - import ./apps/packages.nix {inherit pkgs self;}); + import ./apps/packages.nix {inherit inputs pkgs;}); devShells = perSystem (pkgs: diff --git a/apps/README.md b/apps/README.md new file mode 100644 index 00000000..a716e2ef --- /dev/null +++ b/apps/README.md @@ -0,0 +1,11 @@ +# apps + +This directory contains every derivations for apps exposed by this flake. + +## List of my apps found in `self.apps` + +| Name | Description | +| ---- | ----------- | +| `app-extract-subs` | Extract all `srt` subtitle files from a `mkv` video with the appropriate name. | +| `app-gen-docs` | Generates the READMEs in this repository from nix attributes. | +| `app-update-sources` | Updates all derivation sources in this repository and generates a commit message for the changes made. | diff --git a/apps/buildApp.nix b/apps/buildApp.nix index 8b8c274d..d0c43195 100644 --- a/apps/buildApp.nix +++ b/apps/buildApp.nix @@ -1,9 +1,10 @@ { - runtimeInputs, - npmDepsHash, - src, lib, + src, + npmDepsHash, + runtimeInputs, buildNpmPackage, + meta, makeWrapper, nodejs_latest, jq, @@ -13,12 +14,11 @@ inherit (builtins) fromJSON readFile; packageJSON = fromJSON (readFile "${src}/package.json"); + pname = packageJSON.name; + inherit (packageJSON) version; in - buildNpmPackage rec { - pname = packageJSON.name; - inherit (packageJSON) version; - - inherit src runtimeInputs npmDepsHash; + buildNpmPackage { + inherit pname version src runtimeInputs npmDepsHash; prePatch = '' mv ./tsconfig.json ./project.json @@ -35,5 +35,6 @@ in ''; nodejs = nodejs_latest; - meta.mainProgram = pname; + + meta = {mainProgram = pname;} // meta; } diff --git a/apps/default.nix b/apps/default.nix index 1f960d3c..0306c3b9 100644 --- a/apps/default.nix +++ b/apps/default.nix @@ -1,26 +1,17 @@ { - inputs, pkgs, + self, ... }: let - inherit (pkgs.lib) getExe listToAttrs nameValuePair; + inherit (pkgs.lib) getExe mapAttrs' nameValuePair removePrefix; - buildApp = attrs: (pkgs.callPackage ./buildApp.nix ({} // inputs // attrs)); - - mkNodeApp = file: { - program = getExe (pkgs.callPackage file ({inherit buildApp;} // inputs)); + mkApp = pkg: { + program = getExe pkg; type = "app"; }; - - mkNodeApps = apps: listToAttrs (map (x: nameValuePair x (mkNodeApp ./${x})) apps); in - mkNodeApps [ - "extract-subs" - "update-sources" - ] - // { - gen-docs = { - program = getExe (pkgs.callPackage ./gen-docs {}); - type = "app"; - }; - } + mapAttrs' ( + n: v: + nameValuePair (removePrefix "app-" n) (mkApp v) + ) + self.appsPackages.${pkgs.system} diff --git a/apps/extract-subs/default.nix b/apps/extract-subs/default.nix index 95e8b147..5a4bb717 100644 --- a/apps/extract-subs/default.nix +++ b/apps/extract-subs/default.nix @@ -10,4 +10,8 @@ buildApp { runtimeInputs = [ ffmpeg-full ]; + + meta.description = '' + Extract all `srt` subtitle files from a `mkv` video with the appropriate name. + ''; } diff --git a/apps/gen-docs/default.nix b/apps/gen-docs/default.nix index f0d095ac..f18758e9 100644 --- a/apps/gen-docs/default.nix +++ b/apps/gen-docs/default.nix @@ -8,4 +8,8 @@ writeShellApplication { name = "gen-docs"; runtimeInputs = [jq pandoc]; text = builtins.readFile ./script.sh; + + meta.description = '' + Generates the READMEs in this repository from nix attributes. + ''; } diff --git a/apps/gen-docs/script.sh b/apps/gen-docs/script.sh index 48018425..0501ecb8 100755 --- a/apps/gen-docs/script.sh +++ b/apps/gen-docs/script.sh @@ -1,7 +1,7 @@ packageMetaFunc=$(cat << EOF (x: { attrs = builtins.mapAttrs (_: v: { - desc = builtins.replaceStrings ["\n"] [""] (v.meta.description or ""); + desc = builtins.replaceStrings ["\n"] [" "] (v.meta.description or ""); homepage = v.meta.homepage or ""; }) (builtins.removeAttrs x.\${builtins.currentSystem} ["default"]); }) @@ -14,10 +14,11 @@ substitute() { nix eval \ --impure \ --json \ - .#"$1" \ + "$FLAKE"#"$1" \ --apply "$packageMetaFunc" | jq -r ) -t markdown --template "$2" -o "$3" } substitute "devShells" "$FLAKE/apps/gen-docs/templates/devShells.md" "$FLAKE/devShells/README.md" +substitute "appsPackages" "$FLAKE/apps/gen-docs/templates/apps.md" "$FLAKE/apps/README.md" diff --git a/apps/gen-docs/templates/apps.md b/apps/gen-docs/templates/apps.md new file mode 100644 index 00000000..43e702fa --- /dev/null +++ b/apps/gen-docs/templates/apps.md @@ -0,0 +1,11 @@ +# apps + +This directory contains every derivations for apps exposed by this flake. + +## List of my apps found in `self.apps` + +| Name | Description | +| ---- | ----------- | +$for(attrs/pairs)$ +| `$it.key$` | $it.value.desc/nowrap$ | +$endfor$ diff --git a/apps/gen-docs/templates/devShells.md b/apps/gen-docs/templates/devShells.md index e608570a..0723836a 100644 --- a/apps/gen-docs/templates/devShells.md +++ b/apps/gen-docs/templates/devShells.md @@ -7,5 +7,5 @@ This directory contains every derivations for devShells exposed by this flake. | Name | Description | | ---- | ----------- | $for(attrs/pairs)$ -| $it.key$ | $it.value.desc/nowrap$ | +| `$it.key$` | $it.value.desc/nowrap$ | $endfor$ diff --git a/apps/packages.nix b/apps/packages.nix index dc41fb8e..fd3ecf61 100644 --- a/apps/packages.nix +++ b/apps/packages.nix @@ -1,14 +1,15 @@ { + inputs, pkgs, - self, ... }: let - inherit (pkgs.lib) mapAttrs removeSuffix; + inherit (pkgs.lib) listToAttrs nameValuePair; + + buildApp = attrs: (pkgs.callPackage ./buildApp.nix ({} // inputs // attrs)); + callPackage = file: pkgs.callPackage file ({inherit buildApp;} // inputs); in - mapAttrs ( - name: app: (pkgs.symlinkJoin { - name = "app-${name}"; - paths = [(removeSuffix "/bin/${name}" (toString app.program))]; - }) - ) - (removeAttrs self.apps.${pkgs.system} ["genflake"]) + listToAttrs (map (x: nameValuePair "app-${x}" (callPackage ./${x})) [ + "extract-subs" + "gen-docs" + "update-sources" + ]) diff --git a/apps/update-sources/default.nix b/apps/update-sources/default.nix index c179d3c0..02115d21 100644 --- a/apps/update-sources/default.nix +++ b/apps/update-sources/default.nix @@ -18,4 +18,9 @@ buildApp { prefetch-npm-deps (callPackage ../../modules/docker/updateImage.nix {}) ]; + + meta.description = '' + Updates all derivation sources in this repository and + generates a commit message for the changes made. + ''; } diff --git a/devShells/README.md b/devShells/README.md index 43067e6b..9f6be8f6 100644 --- a/devShells/README.md +++ b/devShells/README.md @@ -6,14 +6,14 @@ This directory contains every derivations for devShells exposed by this flake. | Name | Description | | ---- | ----------- | -| c-lang | c-lang shell to be loaded by my Neovim config dynamically. | -| csharp | csharp shell to be loaded by my Neovim config dynamically. | -| flake | Shell providing some utility scripts concerning the main flake. | -| json | json shell to be loaded by my Neovim config dynamically. | -| lua | lua shell to be loaded by my Neovim config dynamically. | -| markdown | markdown shell to be loaded by my Neovim config dynamically. | -| netdaemon | Shell that makes sure we have the right dotnet-sdk version for NetDaemon development. | -| node | Shell that provides `bumpNpmDeps`, node and typescript. | -| rust | rust shell to be loaded by my Neovim config dynamically. | -| subtitles-dev | Shell that provides the dependencies for my subtitle management scripts. | -| web | web shell to be loaded by my Neovim config dynamically. | +| `c-lang` | c-lang shell to be loaded by my Neovim config dynamically. | +| `csharp` | csharp shell to be loaded by my Neovim config dynamically. | +| `flake` | Shell providing some utility scripts concerning the main flake. | +| `json` | json shell to be loaded by my Neovim config dynamically. | +| `lua` | lua shell to be loaded by my Neovim config dynamically. | +| `markdown` | markdown shell to be loaded by my Neovim config dynamically. | +| `netdaemon` | Shell that makes sure we have the right dotnet-sdk version for NetDaemon development. | +| `node` | Shell that provides `bumpNpmDeps`, node and typescript. | +| `rust` | rust shell to be loaded by my Neovim config dynamically. | +| `subtitles-dev` | Shell that provides the dependencies for my subtitle management scripts. | +| `web` | web shell to be loaded by my Neovim config dynamically. |