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

flake: switch formatter to treefmt-nix, reformat #106

Merged
merged 2 commits into from
Dec 16, 2024
Merged
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
1 change: 0 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
workflow_dispatch:
pull_request:


jobs:
build:
name: build binary
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ jobs:
actionlint

vendorhash:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
Expand Down
23 changes: 22 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 64 additions & 44 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,74 @@
flake-utils = {
url = "github:numtide/flake-utils";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
uplosi = pkgs.buildGoModule {
pname = "uplosi";
version = "devel";
src = ./.;
# this needs to be updated together with go.mod / go.sum
vendorHash = "sha256-2lJmPNLpI1ksFb0EtcjPjyTy7eX1DKeX0F80k9FtGno=";

CGO_ENABLED = 0;

ldflags = [ "-s" ];

nativeBuildInputs = [ pkgs.installShellFiles ];

postInstall = ''
installShellCompletion --cmd uplosi \
--bash <($out/bin/uplosi completion bash) \
--fish <($out/bin/uplosi completion fish) \
--zsh <($out/bin/uplosi completion zsh)
'';

meta = with pkgs.lib; {
description = "Upload OS images to cloud provider";
homepage = "https://github.com/edgelesssys/uplosi";
maintainers = with maintainers; [ katexochen malt3 ];
license = licenses.asl20;
};
};
in
{
devShells.default = import ./shell.nix { inherit pkgs; };
outputs =
{
self,
nixpkgs,
flake-utils,
treefmt-nix,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};

packages = {
default = uplosi;
uplosi = uplosi;
};
uplosi = pkgs.buildGoModule {
pname = "uplosi";
version = "devel";
src = ./.;
# this needs to be updated together with go.mod / go.sum
vendorHash = "sha256-2lJmPNLpI1ksFb0EtcjPjyTy7eX1DKeX0F80k9FtGno=";

CGO_ENABLED = 0;

ldflags = [ "-s" ];

nativeBuildInputs = [ pkgs.installShellFiles ];

legacyPackages = {
nixpkgs = nixpkgs.legacyPackages.${system};
postInstall = ''
installShellCompletion --cmd uplosi \
--bash <($out/bin/uplosi completion bash) \
--fish <($out/bin/uplosi completion fish) \
--zsh <($out/bin/uplosi completion zsh)
'';

meta = with pkgs.lib; {
description = "Upload OS images to cloud provider";
homepage = "https://github.com/edgelesssys/uplosi";
maintainers = with maintainers; [
katexochen
malt3
];
license = licenses.asl20;
};
};

treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
{
devShells.default = import ./shell.nix { inherit pkgs; };

packages = {
default = uplosi;
inherit uplosi;
};

legacyPackages = {
nixpkgs = nixpkgs.legacyPackages.${system};
};

formatter = treefmtEval.config.build.wrapper;

formatter = nixpkgs.legacyPackages.${system}.nixpkgs-fmt;
}
);
checks = {
formatting = treefmtEval.config.build.check self;
};
}
);
}
2 changes: 1 addition & 1 deletion hack/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ set -euo pipefail
target=$(mktemp)
truncate -s 21MiB "${target}"
parted -s -a optimal "${target}" -- \
mklabel msdos mkpart primary ext4 1MiB 100%
mklabel msdos mkpart primary ext4 1MiB 100%
echo "${target}"
90 changes: 38 additions & 52 deletions renovate.json5
Original file line number Diff line number Diff line change
@@ -1,80 +1,66 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended",
$schema: "https://docs.renovatebot.com/renovate-schema.json",
extends: [
":preserveSemverRanges",
"helpers:pinGitHubActionDigests",
":separateMajorReleases",
":semanticCommitsDisabled",
":separateMajorReleases",
"config:recommended",
"helpers:pinGitHubActionDigests",
],
"commitMessagePrefix": "deps:",
"commitMessageAction": "update",
"addLabels": [
"dependencies"
],
"postUpdateOptions": [
commitMessagePrefix: "deps:",
commitMessageAction: "update",
addLabels: [ "dependencies" ],
postUpdateOptions: [
"gomodTidy",
"gomodUpdateImportPaths"
"gomodUpdateImportPaths",
],
"prConcurrentLimit": 1,
"nix": {
"enabled": true,
prConcurrentLimit: 1,
nix: { enabled: true },
lockFileMaintenance: {
enabled: true,
commitMessageAction: "flake.lock: Update",
commitMessagePrefix: null,
schedule: [ "before 4am" ],
},
"lockFileMaintenance": {
"enabled": true,
"commitMessageAction": "flake.lock: Update",
"commitMessagePrefix": null,
"schedule": ["before 4am"],
},
"packageRules": [
packageRules: [
{
"matchManagers": ["gomod"],
"matchDepTypes": ["indirect"],
"enabled": true,
matchManagers: [ "gomod" ],
matchDepTypes: [ "indirect" ],
enabled: true,
},
{
"groupName": "Go indirect dependencies",
"matchManagers": [
"gomod"
],
"matchDepTypes": [
"indirect"
],
"prPriority": -30,
groupName: "Go indirect dependencies",
matchManagers: [ "gomod" ],
matchDepTypes: [ "indirect" ],
prPriority: -30,
},
{
"groupName": "Go dependencies",
"matchManagers": [
"gomod"
],
"matchDepTypes": [
"require"
],
"matchUpdateTypes": [
groupName: "Go dependencies",
matchManagers: [ "gomod" ],
matchDepTypes: [ "require" ],
matchUpdateTypes: [
"bump",
"digest",
"lockFileMaintenance",
"minor",
"patch",
"pin",
"pinDigest",
"digest",
"lockFileMaintenance",
"rollback",
"bump",
],
},
{
"matchManagers": [
"github-actions"
],
"groupName": "GitHub action dependencies",
"matchUpdateTypes": [
matchManagers: [ "github-actions" ],
groupName: "GitHub action dependencies",
matchUpdateTypes: [
"bump",
"digest",
"lockFileMaintenance",
"minor",
"patch",
"pin",
"pinDigest",
"digest",
"lockFileMaintenance",
"rollback",
"bump",
],
},
],
Expand Down
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ pkgs, ... }:

pkgs.mkShell {
nativeBuildInputs = with pkgs; [
go
Expand Down
32 changes: 32 additions & 0 deletions treefmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{ lib, pkgs, ... }:

{
projectRootFile = "flake.nix";
programs = {
# keep-sorted start block=true
actionlint.enable = true;
deadnix.enable = true;
formatjson5 = {
enable = true;
indent = 2;
oneElementLines = true;
sortArrays = true;
};
keep-sorted.enable = true;
nixfmt.enable = true;
shellcheck.enable = true;
shfmt.enable = true;
statix.enable = true;
# keep-sorted end
};
settings.formatter = {
yamlfmt = {
command = "${lib.getExe pkgs.yamlfmt}";
options = [ "-formatter=retain_line_breaks_single=true" ];
includes = [
"*.yaml"
"*.yml"
];
};
};
}
Loading