diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..15c7329 --- /dev/null +++ b/.envrc @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +if has nix; then + use flake +fi diff --git a/.forgejo/actionlint.yaml b/.forgejo/actionlint.yaml new file mode 100644 index 0000000..8e09575 --- /dev/null +++ b/.forgejo/actionlint.yaml @@ -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 diff --git a/flake.lock b/flake.lock index 480733a..9127c6f 100644 --- a/flake.lock +++ b/flake.lock @@ -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", diff --git a/flake.nix b/flake.nix index d42b781..e46e562 100644 --- a/flake.nix +++ b/flake.nix @@ -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); } ); } diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..fe430d9 --- /dev/null +++ b/shell.nix @@ -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 + ]; + }; +} diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 0000000..c687d36 --- /dev/null +++ b/treefmt.nix @@ -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; + }; +}