Skip to content

Commit

Permalink
Quickfix and checks
Browse files Browse the repository at this point in the history
- Adjust quickfix to allow running apps in multiple VMs
- Change nix formatter to rfc-style
- Add nix flake check to github actions

Signed-off-by: Manuel Bluhm <[email protected]>
  • Loading branch information
mbssrc committed Aug 22, 2024
1 parent 418eaa4 commit 31b1181
Show file tree
Hide file tree
Showing 23 changed files with 694 additions and 654 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ jobs:
run: nix fmt -- --fail-on-change
- name: Check nix flake show runs successfully
run: nix flake show
# - name: Run nix flake check
# run: nix flake check
- name: Run nix flake check
run: nix flake check

125 changes: 62 additions & 63 deletions devshell.nix
Original file line number Diff line number Diff line change
@@ -1,71 +1,70 @@
{inputs, ...}: {
{ inputs, ... }:
{
imports = [
inputs.devshell.flakeModule
inputs.pre-commit-hooks-nix.flakeModule
];

perSystem = {
pkgs,
config,
...
}: {
devshells.default = {
devshell = {
name = "GIVC";
motd = ''
❄️ Welcome to the {14}{bold}Welcome to givc-devshell{reset} devshell ❄️
$(type -p menu &>/dev/null && menu)
$(type -p update-pre-commit-hooks &>/dev/null && update-pre-commit-hooks)
'';
perSystem =
{ pkgs, config, ... }:
{
devshells.default = {
devshell = {
name = "GIVC";
motd = ''
❄️ Welcome to the {14}{bold}Welcome to givc-devshell{reset} devshell ❄️
$(type -p menu &>/dev/null && menu)
$(type -p update-pre-commit-hooks &>/dev/null && update-pre-commit-hooks)
'';
};
packages = with pkgs; [
config.treefmt.build.wrapper
reuse
go
gotests
gopls
golangci-lint
rustc
rustfmt
cargo
pkgs.stdenv.cc # Need for build rust components
protobuf
protoc-gen-go
protoc-gen-go-grpc
grpcurl
];
commands = [
{
name = "update-pre-commit-hooks";
command = config.pre-commit.installationScript;
category = "tools";
help = "update git pre-commit hooks";
}
{
help = "Generate go files from protobuffers";
name = "protogen";
command = "./api/protoc.sh";
}
{
help = "Like cURL, but for gRPC: Command-line tool for interacting with gRPC servers";
name = "gcl";
command = "grpcurl";
}
{
help = "Update go dependencies";
name = "go-update";
command = "go get -u ./... && go mod tidy && echo Done - do not forget to update the vendorHash in the packages (use pkgs.lib.fakeHash).";
}
{
help = "golang linter";
package = "golangci-lint";
category = "linters";
}
];
};
pre-commit.settings = {
hooks.treefmt.enable = true;
hooks.treefmt.package = config.treefmt.build.wrapper;
};
packages = with pkgs; [
config.treefmt.build.wrapper
reuse
go
gotests
gopls
golangci-lint
rustc
rustfmt
cargo
pkgs.stdenv.cc # Need for build rust components
protobuf
protoc-gen-go
protoc-gen-go-grpc
grpcurl
];
commands = [
{
name = "update-pre-commit-hooks";
command = config.pre-commit.installationScript;
category = "tools";
help = "update git pre-commit hooks";
}
{
help = "Generate go files from protobuffers";
name = "protogen";
command = "./api/protoc.sh";
}
{
help = "Like cURL, but for gRPC: Command-line tool for interacting with gRPC servers";
name = "gcl";
command = "grpcurl";
}
{
help = "Update go dependencies";
name = "go-update";
command = "go get -u ./... && go mod tidy && echo Done - do not forget to update the vendorHash in the packages (use pkgs.lib.fakeHash).";
}
{
help = "golang linter";
package = "golangci-lint";
category = "linters";
}
];
};
pre-commit.settings = {
hooks.treefmt.enable = true;
hooks.treefmt.package = config.treefmt.build.wrapper;
};
};
}
81 changes: 39 additions & 42 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@
};
};

outputs = inputs @ {
self,
flake-parts,
crane,
...
}:
flake-parts.lib.mkFlake
{
inherit inputs;
}
{
outputs =
inputs@{
self,
flake-parts,
crane,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
Expand All @@ -48,46 +45,46 @@
./nixos/tests
];

perSystem = {
pkgs,
lib,
...
}: {
# Packages
packages = let
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./go.mod
./go.sum
./api
./internal
];
};
in {
givc-app = pkgs.callPackage ./nixos/packages/givc-app.nix {inherit src;};
givc-agent = pkgs.callPackage ./nixos/packages/givc-agent.nix {inherit src;};
givc-admin = pkgs.callPackage ./nixos/packages/givc-admin.nix {inherit src;};
givc-admin-rs = pkgs.callPackage ./nixos/packages/givc-admin-rs.nix {
inherit crane;
src = ./.;
};
perSystem =
{ pkgs, lib, ... }:
{
# Packages
packages =
let
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./go.mod
./go.sum
./api
./internal
];
};
in
{
givc-app = pkgs.callPackage ./nixos/packages/givc-app.nix { inherit src; };
givc-agent = pkgs.callPackage ./nixos/packages/givc-agent.nix { inherit src; };
givc-admin = pkgs.callPackage ./nixos/packages/givc-admin.nix { inherit src; };
givc-admin-rs = pkgs.callPackage ./nixos/packages/givc-admin-rs.nix {
inherit crane;
src = ./.;
};
};
};
};
flake = {
# NixOS Modules
nixosModules = {
admin-go = import ./nixos/modules/admin-go.nix {inherit self;};
admin = import ./nixos/modules/admin.nix {inherit self;};
host = import ./nixos/modules/host.nix {inherit self;};
sysvm = import ./nixos/modules/sysvm.nix {inherit self;};
appvm = import ./nixos/modules/appvm.nix {inherit self;};
admin-go = import ./nixos/modules/admin-go.nix { inherit self; };
admin = import ./nixos/modules/admin.nix { inherit self; };
host = import ./nixos/modules/host.nix { inherit self; };
sysvm = import ./nixos/modules/sysvm.nix { inherit self; };
appvm = import ./nixos/modules/appvm.nix { inherit self; };
};

# Overlays
overlays.default = _final: prev: {
src = ./.;
givc-app = prev.callPackage ./nixos/packages/givc-app.nix {pkgs = prev;};
givc-app = prev.callPackage ./nixos/packages/givc-app.nix { pkgs = prev; };
};
};
};
Expand Down
6 changes: 4 additions & 2 deletions nixos/checks/run-vm-test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
writeShellApplication {
name = "run-vm-test";

runtimeInputs = [];
runtimeInputs = [ ];

text = ''
cmd_name=$(basename "$0")
Expand All @@ -35,7 +35,9 @@ writeShellApplication {
list() {
echo " list of available tests:"
echo
echo "${lib.concatMapStrings (s: " - " + s + "\n") (lib.mapAttrsToList (_: test: test.name) tests)}"
echo "${
lib.concatMapStrings (s: " - " + s + "\n") (lib.mapAttrsToList (_: test: test.name) tests)
}"
}
args=$(getopt -o lihs: --long list,interactive,help,system: -n 'tests' -- "$@")
Expand Down
62 changes: 33 additions & 29 deletions nixos/checks/treefmt.nix
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
{inputs, ...}: {
{ inputs, ... }:
{
imports = [
inputs.flake-root.flakeModule
inputs.treefmt-nix.flakeModule
];

perSystem = {
config,
pkgs,
lib,
...
}: {
treefmt.config = {
inherit (config.flake-root) projectRootFile;
package = pkgs.treefmt;
flakeFormatter = true;
flakeCheck = true;
programs = {
alejandra.enable = true;
rustfmt.enable = true;
deadnix.enable = true; # removes dead nix code https://github.com/astro/deadnix
statix.enable = true; # prevents use of nix anti-patterns https://github.com/nerdypepper/statix
gofmt.enable = true; # go formatter https://golang.org/cmd/gofmt/
shellcheck.enable = true; # lints shell scripts https://github.com/koalaman/shellcheck
perSystem =
{
config,
pkgs,
lib,
...
}:
{
treefmt.config = {
inherit (config.flake-root) projectRootFile;
package = pkgs.treefmt;
flakeFormatter = true;
flakeCheck = true;
programs = {
nixfmt.enable = true;
nixfmt.package = pkgs.nixfmt-rfc-style;
rustfmt.enable = true;
deadnix.enable = true; # removes dead nix code https://github.com/astro/deadnix
statix.enable = true; # prevents use of nix anti-patterns https://github.com/nerdypepper/statix
gofmt.enable = true; # go formatter https://golang.org/cmd/gofmt/
shellcheck.enable = true; # lints shell scripts https://github.com/koalaman/shellcheck
};
};
};

devshells.default.commands = [
{
category = "tools";
name = "fmt";
help = "format the source tree";
command = lib.getExe config.treefmt.build.wrapper;
}
];
};
devshells.default.commands = [
{
category = "tools";
name = "fmt";
help = "format the source tree";
command = lib.getExe config.treefmt.build.wrapper;
}
];
};
}
Loading

0 comments on commit 31b1181

Please sign in to comment.