Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(tree): rewrite in std #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
indent_style = space
indent_size = 2
17 changes: 17 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#! /bin/sh

# SPDX-FileCopyrightText: 2022 David Arnold <[email protected]>
# SPDX-FileCopyrightText: 2022 Kevin Amado <[email protected]>
#
# SPDX-License-Identifier: Unlicense

source "$(
nix eval \
--no-update-lock-file \
--no-write-lock-file \
--no-warn-dirty \
--accept-flake-config \
.#__std.direnv_lib 2>/dev/null \
|| nix eval .#__std.direnv_lib # show the errors
)"
use std cells //_automation/devshells:default
28 changes: 28 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test all package sets

on:
push:
branches:
- main
merge_request:
workflow_dispatch:

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]

- name: Install latest nix
uses: cachix/install-nix-action@v18
with:
extra_nix_config: |
substituters = https://cache.nixos.org https://nix-community.cachix.org https://fog.cachix.org
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= fog.cachix.org-1:FAxiA6qMLoXEUdEq+HaT24g1MjnxdfygrbrLDBp6U/s=
nix_path: nixpkgs=channel:nixos-unstable

- name: Quick eval
run: nix develop --show-trace --print-build-logs --command evalnix

- name: Run all tests
run: nix develop --show-trace --print-build-logs .#devShells.x86_64-linux.checks --command run-all
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-FileCopyrightText: 2022 David Arnold <[email protected]>
# SPDX-FileCopyrightText: 2022 Kevin Amado <[email protected]>
#
# SPDX-License-Identifier: Unlicense

.std
/**/flake.lock
result
.direnv
10 changes: 0 additions & 10 deletions bud/default.nix

This file was deleted.

16 changes: 0 additions & 16 deletions bud/vscode-ext-prefetch.bash

This file was deleted.

80 changes: 80 additions & 0 deletions cells/_automation/devshells.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
inputs,
cell,
}: let
l = nixpkgs.lib // builtins;
inherit (inputs) cells nixpkgs std;
in
l.mapAttrs (_: std.lib.dev.mkShell) {
default = {
extraModulesPath,
pkgs,
...
}: {
name = "devos-ext-lib";

git.hooks = {
enable = true;
pre-commit.text = builtins.readFile ./devshells/pre-flight-check.sh;
};

imports = [
std.std.devshellProfiles.default
"${extraModulesPath}/git/hooks.nix"
];

packages = [
# formatters
nixpkgs.alejandra
];

commands = with cell.lib.categories; [
(formatters nixpkgs.treefmt)
(formatters nixpkgs.editorconfig-checker)
(legal nixpkgs.reuse)
(utils {
name = "evalnix";
help = "Check Nix parsing";
command = "${nixpkgs.fd}/bin/fd --extension nix --exec ${nixpkgs.nix}/bin/nix-instantiate --parse --quiet {} >/dev/null";
})
(utils cell.packages.repl)
];
};

checks = {...}: {
name = "checks";
imports = [std.std.devshellProfiles.default];
commands = let
tests = cells.std.lib.trimBy cells ["tests"];
testToCommand = l.mapAttrsToList (otherCell: targets: let
targetToTest =
l.mapAttrsToList (targetName: value: {
name = otherCell + "-" + targetName;
command = l.concatStringsSep "; " [
"echo -n '${value.description} \n => '"
(
if value.result == value.expected
then "echo 'PASSED!'"
else "echo 'FAILED! Run `nix develop .#devShells.${nixpkgs.system}.default --command repl` to inspect the problem. \n => trace: Flake.${nixpkgs.system}.${otherCell}.tests.${targetName}'; export checks=1"
)
];
})
targets;
in
targetToTest)
tests;
testCommands = l.flatten testToCommand;
testNames = l.catAttrs "name" testCommands;
in
[
{
name = "run-all";
command = l.concatStringsSep "; " (testNames
++ [
"[[ -z \${checks+x} ]] && echo 'All tests passed!' || { echo 'Some tests failed!' && exit 1; }"
]);
}
]
++ testCommands;
};
}
28 changes: 28 additions & 0 deletions cells/_automation/devshells/pre-flight-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# SPDX-FileCopyrightText: 2022 The Standard Authors
# SPDX-FileCopyrightText: 2022 Kevin Amado <[email protected]>
#
# SPDX-License-Identifier: Unlicense

if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(${git}/bin/git hash-object -t tree /dev/null)
fi

diff="git diff-index --name-only --cached $against --diff-filter d"
all_files=($($diff))

# Format the entire tree.
treefmt

# check editorconfig
editorconfig-checker -- "${all_files[@]}"
if [[ $? != '0' ]]; then
printf "%b\n" \
"\nCode is not aligned with .editorconfig" \
"Review the output and commit your fixes" >&2
exit 1
fi
36 changes: 36 additions & 0 deletions cells/_automation/lib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
inputs,
cell,
}: let
l = inputs.nixpkgs.lib // builtins;

cmdWithCategory = category: attrs: attrs // {inherit category;};

pkgWithCategory = category: package: cmdWithCategory category {inherit package;};

withCategory = category: attrs: let
mapWith =
if l.isDerivation attrs
then pkgWithCategory
else cmdWithCategory;
in
mapWith category attrs;

mkCategories = categories: attrs: let
withCategories = l.genAttrs categories (category: withCategory category);
in
withCategories // attrs;

categories = [
"cli-dev"
"devos"
"docs"
"formatters"
"legal"
"utils"
];
in {
categories = mkCategories categories {
inherit cmdWithCategory pkgWithCategory withCategory categories;
};
}
14 changes: 14 additions & 0 deletions cells/_automation/packages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
inputs,
cell,
}: let
inherit (inputs) nixpkgs;
in {
repl = nixpkgs.writeShellScriptBin "repl" ''
if [ -z "$1" ]; then
nix repl --argstr host "$HOST" --argstr flakePath "$PRJ_ROOT" --file ${./packages/repl/repl.nix}
else
nix repl --argstr host "$HOST" --argstr flakePath $(readlink -f $1 | sed 's|/flake.nix||') --file ${./packages/repl/repl.nix} ''${@: 1}
fi
'';
}
23 changes: 23 additions & 0 deletions cells/_automation/packages/repl/repl.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Adapted on 3rd of July 2021 from
# https://github.com/gytis-ivaskevicius/flake-utils-plus/blob/438316a7b7d798bff326c97da8e2b15a56c7657e/lib/repl.nix
{
flakePath,
host,
}: let
Flake =
if builtins.pathExists flakePath
then builtins.getFlake (toString flakePath)
else {};

Me = Flake.nixosConfigurations.${host} or {};
Channels = Flake.pkgs.${builtins.currentSystem} or {};

LoadFlake = path: builtins.getFlake (toString path);
in {
inherit
Channels
Flake
LoadFlake
Me
;
}
Loading