Skip to content

Commit

Permalink
Major rework
Browse files Browse the repository at this point in the history
  • Loading branch information
kip93 committed May 16, 2022
1 parent 45630bc commit be56fcc
Show file tree
Hide file tree
Showing 20 changed files with 860 additions and 360 deletions.
109 changes: 35 additions & 74 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
paths:
- 'keymap/**'
- 'QMK'
- 'shell.nix'
- '**/*.nix'
- '.github/workflows/check.yml'
workflow_dispatch: {}

Expand All @@ -21,126 +21,87 @@ jobs:
submodules: recursive
path: ./repo

- name: Set up Nix
- name: "Nix: set up"
uses: cachix/install-nix-action@v15
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
experimental-features = nix-command
- name: Set up cache
- name: "Nix: cache set up"
uses: cachix/cachix-action@v10
with:
name: kip93
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
extraPullNames: nix-community
skipPush: true

- name: Print nixpkgs version
- name: "Nix: version"
run: |
nix-instantiate --eval -E '"nixpkgs version: ${(import <nixpkgs> {}).lib.version}"'
nix-env --version
- name: Shellcheck shell.nix
id: shellcheck
- name: "Nix: format"
id: nix-format
working-directory: ./repo
run: |
(
printf '#!/bin/bash\n' ;
nix-shell --pure shell.nix --run : >/dev/null ;
nix-instantiate shell.nix 2>/dev/null | xargs -i sed '1,5d' {} ;
) | nix-shell -p shellcheck --run 'shellcheck -'
nix-build scripts/nix-format.nix | xargs sh -c
continue-on-error: true

- name: QMK Format
id: qmk-format
- name: "Nix: lint"
id: nix-lint
working-directory: ./repo
run: |
nix-shell --run format
git diff --exit-code --name-only
nix-build scripts/nix-lint.nix | xargs sh -c
continue-on-error: true

- name: QMK Lint
id: qmk-lint
- name: "Nix: shellcheck"
id: nix-shellcheck
working-directory: ./repo
run: |
nix-shell --run lint
nix-build scripts/nix-shellcheck.nix | xargs sh -c
continue-on-error: true

- name: Check shell.nix format
id: nixpkgs-fmt
- name: "Nix: vulnerabilities"
id: nix-vulnerabilities
working-directory: ./repo
run: |
nix-shell -p nixpkgs-fmt --run 'nixpkgs-fmt --check shell.nix'
nix-build scripts/nix-vulnerabilities.nix | xargs sh -c
continue-on-error: true

- name: Lint shell.nix
id: nix-linter
- name: "Nix: logic"
id: nix-logic
working-directory: ./repo
run: |
nix-shell -p nix-linter --run ' \
nix-linter -W no-AlphabeticalArgs \
-W no-AlphabeticalBindings \
-W BetaReduction \
-W DIYInherit \
-W EmptyInherit \
-W EmptyLet \
-W no-EmptyVariadicParamSet \
-W FreeLetInFunc \
-W LetInInheritRecset \
-W no-ListLiteralConcat \
-W NegateAtom \
-W SequentialLet \
-W SetLiteralUpdate \
-W UnfortunateArgName \
-W no-UnneededAntiquote \
-W UnneededRec \
-W UnusedArg \
-W UnusedLetBind \
-W UpdateEmptySet \
-v shell.nix \
'
nix-build scripts/nix-logic.nix | TMPDIR=../tmp xargs sh -c
continue-on-error: true

- name: Check shell.nix for vulnerabilities
id: vulnix
- name: "QMK: format"
id: qmk-format
working-directory: ./repo
run: |
nix-shell -p vulnix --run 'vulnix -f shell.nix'
nix-build scripts/qmk-format.nix | xargs sh -c
continue-on-error: true

- name: Validate shell.nix logic
id: validate
working-directory: .
- name: "QMK: lint"
id: qmk-lint
working-directory: ./repo
run: |
(
mkdir -p ./tmp ;
cp ./repo/shell.nix ./tmp/shell.nix ;
sed -i -E 's|\bKEYBOARD\b\s*=\s*".+?"\s*;|KEYBOARD = "ergodox_ez";|' ./tmp/shell.nix ;
cd ./tmp ;
MANPAGER=cat nix-shell --run help ;
nix-shell --pure --run init ;
# nix-shell --pure --run setup ; # No root access, but not needed since we won't be flashing
nix-shell --pure --run format ;
nix-shell --pure --run lint ;
nix-shell --pure --run compile ;
# nix-shell --pure --run flash ; # Can't flash since there is no keyboard attached
nix-shell --pure --run clean ;
)
nix-build scripts/qmk-lint.nix | xargs sh -c
continue-on-error: true

- name: Check for failures
if: |
steps.shellcheck.outcome != 'success' ||
steps.qmk-format.outcome != 'success' ||
steps.qmk-lint.outcome != 'success' ||
steps.nixpkgs-fmt.outcome != 'success' ||
steps.nix-linter.outcome != 'success' ||
steps.vulnix.outcome != 'success' ||
steps.validate.outcome != 'success'
steps.nix-format.outcome != 'success' ||
steps.nix-lint.outcome != 'success' ||
steps.nix-shellcheck.outcome != 'success' ||
steps.nix-vulnerabilities.outcome != 'success' ||
steps.nix-logic.outcome != 'success' ||
steps.qmk-format.outcome != 'success' ||
steps.qmk-lint.outcome != 'success'
run: exit 1

- name: Push to cache
working-directory: ./repo
run: |
nix-shell --pure shell.nix --run :
nix-store -qR --include-outputs $(nix-instantiate shell.nix 2>/dev/null) | cachix push kip93
nix-build scripts/nix-cache.nix | xargs -I{} sh -c '{}' kip93
4 changes: 1 addition & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,4 @@ jobs:

- name: Push to cache
run: |
nix-shell --pure shell.nix --run :
nix-shell --pure QMK/shell.nix --run :
nix-store -qR --include-outputs $(nix-instantiate shell.nix QMK/shell.nix 2>/dev/null) | cachix push kip93
nix-build scripts/nix-cache.nix | xargs -I{} sh -c '{}' kip93
3 changes: 1 addition & 2 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@ jobs:
- name: Push to cache
run: |
nix-shell --pure QMK/shell.nix --run :
nix-store -qR --include-outputs $(nix-instantiate QMK/shell.nix 2>/dev/null) | cachix push kip93
nix-build scripts/nix-cache.nix | xargs -I{} sh -c '{}' kip93
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**/*[~#]
/**/.*
/**/result
/**/result-*
!/**/.github
!/**/.gitignore
!/**/.vscode
7 changes: 7 additions & 0 deletions .vscode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# VSCodium settings

[Settings](./settings.json) for
[VSCodium](https://vscodium.com/) /
[VSCode](https://code.visualstudio.com/) /
[Code OSS](https://github.com/Microsoft/vscode)
and [suggested extensions](./extensions.json).
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ // Suggested extensions
"recommendations": [
// General
"aaron-bond.better-comments",
"medo64.render-crlf",
"tumido.cron-explained",

Expand All @@ -16,6 +17,12 @@
"bbenoist.Nix",
"jnoortheen.nix-ide",

// Shell
"timonwong.shellcheck",

// SVG
"jock.svg",

// YAML
"redhat.vscode-yaml",
]
Expand Down
2 changes: 2 additions & 0 deletions .vscode/ltex.dictionary.en-GB.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ nixos
nixpkgs
ortholinear
QMK
VSCode
VSCodium
79 changes: 75 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,71 @@
{
// General
"better-comments.multilineComments": true,
"better-comments.tags": [
{
"tag": "TODO",
"color": "#DF4C9D",
"strikethrough": false,
"underline": false,
"backgroundColor": "transparent",
"bold": true,
"italic": false,
},
],
"code-eol.decorateBeforeEol": false,
"code-eol.highlightExtraWhitespace": true,
"code-eol.highlightNonDefault": true,
"cron-explained.codeLens.enabled": true,
"cron-explained.codeLens.showCommentAction": false,
"cron-explained.codeLens.showTranscript": true,
"cron-explained.cronstrueOptions.dayOfWeekStartIndexZero": true,
"cron-explained.cronstrueOptions.monthStartIndexZero": false,
"cron-explained.cronstrueOptions.use24HourTimeFormat": true,
"cron-explained.cronstrueOptions.verbose": false,
"cron-explained.hover.enabled": false,
"diffEditor.ignoreTrimWhitespace": false,
"editor.insertSpaces": true,
"editor.renderWhitespace": "all",
"files.associations": {
"*.c": "c",
"*.cpp": "cpp",
"*.h": "c",
"*.hpp": "cpp",
"*.inc": "c",
},
"files.exclude": {
"**/.DS_Store": false,
"**/Thumbs.db": false,
},
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"json.maxItemsComputed": 999999,
"search.exclude": {
".build": true,
"QMK": true,
},

// Git
"git.allowForcePush": false,
"git.allowNoVerifyCommit": false,
"git.autofetch": true,
"git.autofetchPeriod": 120,
"git.autoStash": true,
"git.enabled": true,
"git.enableSmartCommit": false,
"git.inputValidationLength": 72,
"git.inputValidationSubjectLength": 50,
"git.pruneOnFetch": true,
"git.pullTags": true,
"git.requireGitUserConfig": true,
"git.suggestSmartCommit": false,

// MarkDown
"ltex.additionalRules.enablePickyRules": true,
"ltex.additionalRules.motherTongue": "en-GB",
"ltex.checkFrequency": "edit",
"ltex.completionEnabled": true,
"ltex.enabled": [
"markdown",
],
"ltex.enabled": ["markdown"],
"ltex.language": "en-GB",
"ltex.statusBarItem": true,
"markyMarkdown.statsAlignment": "Right",
Expand All @@ -30,4 +75,30 @@
"markyMarkdown.statsShowLines": true,
"markyMarkdown.statsShowWords": true,
"markyMarkdown.statsWordsPerMinute": 150,

// Nix
"nix.enableLanguageServer": true,
"nixEnvSelector.suggestion": true,
"nixEnvSelector.nixFile": "${workspaceFolder}/env.nix",

// Shell
"shellcheck.enable": true,
"shellcheck.enableQuickFix": true,
"shellcheck.run": "onType",
"shellcheck.useWorkspaceRootAsCwd": true,

// SVG
"svg.completion.showAdvanced": true,
"svg.pathDataHighlight": true,
"svg.preview.background": "dark-transparent",
"svg.preview.mode": "img",

// YAML
"yaml.completion": true,
"yaml.format.bracketSpacing": true,
"yaml.format.printWidth": 120,
"yaml.format.proseWrap": "preserve",
"yaml.format.singleQuote": false,
"yaml.validate": true,
"yaml.yamlVersion": "1.2",
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ First, you'll need to acquire the base components for the build. The board schem
bought mine from [Keyhive](https://keyhive.xyz/corne) in a nice kit containing most of the basics. To that I had
to add in the MCUs, a TRRS cable, 42 key switches and keycaps, and a USB-A to USB-C cable.

Once you have everything you just have to put it all together. It is intuitive enough, but there is also a
Once you have everything, you just have to put it all together. It is intuitive enough, but there is also a
[handy-dandy build guide](https://github.com/foostan/crkbd/blob/master/corne-cherry/doc/v3/buildguide_en.md) that
you can follow if needed.

Expand Down
11 changes: 11 additions & 0 deletions env.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ pkgs ? import <nixpkgs> { }, ... }:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [
cacert
git
nix
nix-linter
nixpkgs-fmt
openssh
];
}
3 changes: 3 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Scripts

A collection of scripts that handle and manipulate the code. Mostly intended for use on the CI.
15 changes: 15 additions & 0 deletions scripts/nix-cache.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ pkgs ? import <nixpkgs> { } }:
with pkgs; writeScript "nix-cache" ''
#!${bash}/bin/bash
set -eu
# shellcheck disable=SC2016
${findutils}/bin/find '${toString ../.}' -type f -name '*.nix' -a \( -not -path '${toString ../QMK}/*' -o -path '${toString ../QMK}/shell.nix' \) |
${findutils}/bin/xargs -I{} sh -c '
set -eu
if [ "$(${nix}/bin/nix-instantiate --eval -E "builtins.hasAttr \"shellHook\" ((import <nixpkgs> { }).callPackage \"{}\" { })")" == "true" ] ; then
${nix}/bin/nix-build "{}" --no-out-link -A inputDerivation
else
${nix}/bin/nix-build "{}" --no-out-link
fi
' | ${cachix}/bin/cachix push "''${1}"
''
7 changes: 7 additions & 0 deletions scripts/nix-format.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ pkgs ? import <nixpkgs> { } }:
with pkgs; writeScript "nix-format" ''
#!${bash}/bin/bash
set -eu
${findutils}/bin/find '${toString ../.}' -type f -name '*.nix' -not -path '${toString ../QMK}/*' |
${findutils}/bin/xargs ${nixpkgs-fmt}/bin/nixpkgs-fmt --check
''
Loading

0 comments on commit be56fcc

Please sign in to comment.