Merge pull request 'chore: integrate treefmt' (#18) from treefmt into main
Some checks failed
build and publish containers / build (nixos, 24.11) (push) Failing after 39s
build and publish containers / build (nixos, unstable) (push) Successful in 3m56s

Reviewed-on: #18
This commit is contained in:
flyinggecko 2025-05-23 23:11:55 +02:00
commit b93d09edbc
6 changed files with 154 additions and 23 deletions

4
.envrc Normal file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
if has nix; then
use flake
fi

6
.forgejo/actionlint.yaml Normal file
View file

@ -0,0 +1,6 @@
# Configuration related to self-hosted runner.
self-hosted-runner:
# Labels of self-hosted runner in array of strings.
labels:
- nixos-latest
- nixos-24.11

38
flake.lock generated
View file

@ -54,7 +54,9 @@
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"nixpkgs-unstable": "nixpkgs-unstable"
"nixpkgs-unstable": "nixpkgs-unstable",
"systems": "systems_2",
"treefmt-nix": "treefmt-nix"
}
},
"systems": {
@ -71,6 +73,40 @@
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"id": "systems",
"type": "indirect"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1747912973,
"narHash": "sha256-XgxghfND8TDypxsMTPU2GQdtBEsHTEc3qWE6RVEk8O0=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "020cb423808365fa3f10ff4cb8c0a25df35065a3",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",

View file

@ -5,14 +5,19 @@
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
# Treefmt for formatting
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{
self,
nixpkgs,
nixpkgs-unstable,
flake-utils,
treefmt-nix,
systems,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
@ -56,7 +61,7 @@
in
pkgs.dockerTools.buildImageWithNixDb {
name = "git.flyinggecko.org/oci-images/nixos-runner/${name}";
tag = tag;
inherit tag;
copyToRoot =
with pkgs;
(imagePackages pkgs)
@ -66,20 +71,20 @@
name = "containerPolicy";
destination = "/etc/containers/policy.json";
text = ''
{
"default": [
{
"type": "insecureAcceptAnything"
}
],
"transports":
{
"docker-daemon":
{
"": [{"type":"insecureAcceptAnything"}]
}
}
}
{
"default": [
{
"type": "insecureAcceptAnything"
}
],
"transports":
{
"docker-daemon":
{
"": [{"type":"insecureAcceptAnything"}]
}
}
}
'';
})
@ -87,14 +92,14 @@
name = "containerRegistries";
destination = "/etc/containers/registries.conf";
text = ''
[registries.block]
registries = []
[registries.block]
registries = []
[registries.insecure]
registries = []
[registries.insecure]
registries = []
[registries.search]
registries = ["docker.io", "quay.io"]
[registries.search]
registries = ["docker.io", "quay.io"]
'';
})
@ -230,12 +235,31 @@
];
};
};
forEachSystem =
f:
nixpkgs.lib.genAttrs (import systems) (
system:
let
pkgs = import nixpkgs {
inherit system;
};
in
f pkgs
);
treefmtEval = forEachSystem (pkgs: treefmt-nix.lib.evalModule pkgs ./treefmt.nix);
# treefmtWrapper = pkgs: treefmtEval.${pkgs.system}.config.build.wrapper;
in
{
packages = {
nixos-2411 = containerLambda "nixos" "24.11" nixpkgs;
nixos-unstable = containerLambda "nixos" "unstable" nixpkgs-unstable;
};
# dev shells in project
devShells = import ./shell.nix { inherit nixpkgs treefmtEval system; };
# formatter = forEachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper);
}
);
}

23
shell.nix Normal file
View file

@ -0,0 +1,23 @@
{
nixpkgs,
treefmtEval,
system,
...
}:
let
pkgs = nixpkgs.legacyPackages.${system};
packages = with pkgs; [
podman
direnv
git
];
in
{
default = pkgs.mkShell {
inherit packages;
# nativeBuildInputs = packages;
inputsFrom = [
treefmtEval.${pkgs.system}.config.build.devShell
];
};
}

38
treefmt.nix Normal file
View file

@ -0,0 +1,38 @@
_: {
settings = {
# General config
# allow-missing-formatter = true;
on-unmatched = "debug";
global.excludes = [
# lock files
"*.lock"
];
formatter.actionlint = {
options = [
"-config-file"
".forgejo/actionlint.yaml"
];
includes = [
".forgejo/workflows/*.yml"
".forgejo/workflows/*.yaml"
];
};
formatter.yamlfmt.excludes = [
".forgejo/*"
];
};
programs = {
# Nix
deadnix.enable = true;
nixfmt.enable = true;
statix.enable = true;
# Config files
yamlfmt.enable = true;
# ActionLint/forgejo workflows
actionlint.enable = true;
};
}