From 9da3840a6f4c86c3058f8bd2e1d824dbee2abdfe Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 27 Mar 2022 18:43:21 -0500 Subject: [PATCH] fix: missing dep in CI devshell script --- devshell/flake.nix | 158 +++++++++++++++++++++++---------------------- 1 file changed, 81 insertions(+), 77 deletions(-) diff --git a/devshell/flake.nix b/devshell/flake.nix index f8c05e6..76c688e 100644 --- a/devshell/flake.nix +++ b/devshell/flake.nix @@ -9,94 +9,97 @@ system: let inherit (inputs.main.inputs.std.deSystemize system inputs) - main devshell nixpkgs ; + main + devshell + nixpkgs + ; inherit (main.inputs.std.deSystemize system inputs.main.inputs) - std ; - withCategory = category: attrset: attrset // { inherit category; }; - utils = withCategory "utils"; - docs = withCategory "docs"; + std + ; + withCategory = category: attrset: attrset // {inherit category;}; + utils = withCategory "utils"; + docs = withCategory "docs"; - makeDocs = { - name = "make-docs"; - help = "Execute the docs creating jobs and place the results in ./doc"; - command = '' - nix build "$PRJ_ROOT#jobs.${system}.mkApiReferenceTopLevel" \ - && cp result "$PRJ_ROOT/doc/api-reference.md" \ - && chmod 755 "$PRJ_ROOT//doc/api-reference.md" - nix build "$PRJ_ROOT#jobs.${system}.mkApiReferenceChannels" \ - && cp result "$PRJ_ROOT/doc/api-reference-channels.md" \ - && chmod 755 "$PRJ_ROOT//doc/api-reference-channels.md" - nix build "$PRJ_ROOT#jobs.${system}.mkApiReferenceHome" \ - && cp result "$PRJ_ROOT/doc/api-reference-home.md" \ - && chmod 755 "$PRJ_ROOT//doc/api-reference-home.md" - nix build "$PRJ_ROOT#jobs.${system}.mkApiReferenceDevshell" \ - && cp result "$PRJ_ROOT/doc/api-reference-devshell.md" \ - && chmod 755 "$PRJ_ROOT//doc/api-reference-devshell.md" - nix build "$PRJ_ROOT#jobs.${system}.mkApiReferenceNixos" \ - && cp result "$PRJ_ROOT/doc/api-reference-nixos.md" \ - && chmod 755 "$PRJ_ROOT//doc/api-reference-nixos.md" - ''; + makeDocs = { + name = "make-docs"; + help = "Execute the docs creating jobs and place the results in ./doc"; + command = '' + nix build "$PRJ_ROOT#jobs.${system}.mkApiReferenceTopLevel" \ + && cp result "$PRJ_ROOT/doc/api-reference.md" \ + && chmod 755 "$PRJ_ROOT//doc/api-reference.md" + nix build "$PRJ_ROOT#jobs.${system}.mkApiReferenceChannels" \ + && cp result "$PRJ_ROOT/doc/api-reference-channels.md" \ + && chmod 755 "$PRJ_ROOT//doc/api-reference-channels.md" + nix build "$PRJ_ROOT#jobs.${system}.mkApiReferenceHome" \ + && cp result "$PRJ_ROOT/doc/api-reference-home.md" \ + && chmod 755 "$PRJ_ROOT//doc/api-reference-home.md" + nix build "$PRJ_ROOT#jobs.${system}.mkApiReferenceDevshell" \ + && cp result "$PRJ_ROOT/doc/api-reference-devshell.md" \ + && chmod 755 "$PRJ_ROOT//doc/api-reference-devshell.md" + nix build "$PRJ_ROOT#jobs.${system}.mkApiReferenceNixos" \ + && cp result "$PRJ_ROOT/doc/api-reference-nixos.md" \ + && chmod 755 "$PRJ_ROOT//doc/api-reference-nixos.md" + ''; + }; - }; + test = type: name: + withCategory "tests" { + name = "check-${name}"; + help = "Checks ${name} ${type}"; + command = '' + set -e + # set -x - test = type: name: withCategory "tests" { - name = "check-${name}"; - help = "Checks ${name} ${type}"; - command = '' - set -e - # set -x + diggaurl= + lockfile_updated=1 + lockfile_present=1 + tempdigga="\"path:$PRJ_ROOT\"" - diggaurl= - lockfile_updated=1 - lockfile_present=1 - tempdigga="\"path:$PRJ_ROOT\"" + cleanup() { + if is $lockfile_present; then + git checkout -- flake.lock + elif is $lockfile_updated; then + git rm -f flake.lock + fi + # ensure: restore input + [ -z $diggaurl ] || ${nixpkgs.legacyPackages.gnused}/bin/sed -i "s|$tempdigga|$diggaurl|g" flake.nix + } - cleanup() { - if is $lockfile_present; then - git checkout -- flake.lock - elif is $lockfile_updated; then - git rm -f flake.lock - fi - # ensure: restore input - [ -z $diggaurl ] || ${nixpkgs.legacyPackages.gnused}/bin/sed -i "s|$tempdigga|$diggaurl|g" flake.nix - } + digga_fixture() { + # ensure: replace input + diggaurl=$({ grep -o '"github:divnix/digga.*"' flake.nix || true; }) + [ -z $diggaurl ] || ${nixpkgs.legacyPackages.gnused}/bin/sed -i "s|$diggaurl|$tempdigga|g" flake.nix + } - digga_fixture() { - # ensure: replace input - diggaurl=$({ grep -o '"github:divnix/digga.*"' flake.nix || true; }) - [ -z $diggaurl ] || ${nixpkgs.legacyPackages.gnused}/bin/sed -i "s|$diggaurl|$tempdigga|g" flake.nix - } + trap_err() { + local ret=$? + cleanup + echo -e \ + "\033[1m\033[31m""exit $ret: \033[0m\033[1m""command [$BASH_COMMAND] failed""\033[0m" + } - trap_err() { - local ret=$? - cleanup - echo -e \ - "\033[1m\033[31m""exit $ret: \033[0m\033[1m""command [$BASH_COMMAND] failed""\033[0m" - } + is () { [ "$1" -eq "0" ]; } - is () { [ "$1" -eq "0" ]; } + trap 'trap_err' ERR - trap 'trap_err' ERR + # -------------------------------------------------------------------------------- - # -------------------------------------------------------------------------------- + cd $PRJ_ROOT/${type}/${name} - cd $PRJ_ROOT/${type}/${name} + digga_fixture - digga_fixture - - test -f flake.lock && lockfile_present=$? || true - ${nixpkgs.legacyPackages.nixUnstable}/bin/nix flake lock --update-input digga "$@"; lockfile_updated=$?; - ${nixpkgs.legacyPackages.nixUnstable}/bin/nix flake show "$@" - ${nixpkgs.legacyPackages.nixUnstable}/bin/nix flake check "$@" - - cleanup - ''; - }; + test -f flake.lock && lockfile_present=$? || true + ${nixpkgs.legacyPackages.nixUnstable}/bin/nix flake lock --update-input digga "$@"; lockfile_updated=$?; + ${nixpkgs.legacyPackages.nixUnstable}/bin/nix flake show "$@" + ${nixpkgs.legacyPackages.nixUnstable}/bin/nix flake check "$@" + cleanup + ''; + }; in { - devShells.default = devshell.legacyPackages.mkShell ( { extraModulesPath, ... }: { - + devShells.default = devshell.legacyPackages.mkShell ( + {extraModulesPath, ...}: { name = "Digga (formerly DevOS)"; imports = [ @@ -116,9 +119,12 @@ nixpkgs.legacyPackages.nodePackages.prettier nixpkgs.legacyPackages.shfmt nixpkgs.legacyPackages.editorconfig-checker + + # deps for devshell scripts + nixpkgs.legacyPackages.fd ]; commands = [ - (utils { package = nixpkgs.legacyPackages.treefmt; }) + (utils {package = nixpkgs.legacyPackages.treefmt;}) (utils { command = "git rm --ignore-unmatch -f $PRJ_ROOT/{tests,examples}/*/flake.lock"; help = "Remove all lock files"; @@ -132,8 +138,8 @@ (test "examples" "devos") (test "examples" "groupByConfig") (test "examples" "hmOnly") - (test "examples" "all" // { command = "check-devos && check-groupByConfig && check-hmOnly"; }) - (docs { package = nixpkgs.legacyPackages.mdbook; }) + (test "examples" "all" // {command = "check-devos && check-groupByConfig && check-hmOnly";}) + (docs {package = nixpkgs.legacyPackages.mdbook;}) (docs makeDocs) ]; } @@ -141,5 +147,3 @@ } ); } - -