Rewrite flake.nix using flake-parts (since it has gone quite large)

A few more changes:
- Update bazel to 7.0.0. Closes #5.
- Move things around (to have place for Ansible schemas in the future)

NOTE: right now, bazel package is still at 6.4.0. The MODULE.bazel.lock
file was generated using bazel_7 package.
This commit is contained in:
Hoang Nguyen 2024-01-05 00:00:00 +07:00
parent c991be4740
commit 7c68a7c00b
Signed by: folliehiyuki
GPG key ID: B0567C20730E9B11
21 changed files with 2679 additions and 135 deletions

5
.bazelignore Normal file
View file

@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2023 Hoang Nguyen <folliekazetani@protonmail.com>
#
# SPDX-License-Identifier: CC0-1.0
flake

View file

@ -2,9 +2,6 @@
#
# SPDX-License-Identifier: CC0-1.0
# TODO: remove this once Bazel 7 is released
common --enable_bzlmod
# Use these by passing `--config=ci` to Bazel's command argument
common:ci --color=no
common:ci --show_timestamps

View file

@ -2,4 +2,4 @@
#
# SPDX-License-Identifier: CC0-1.0
6.4.0
7.0.0

View file

@ -6,6 +6,11 @@ load("@gazelle//:def.bzl", "gazelle")
load("@rules_go//go:def.bzl", "TOOLS_NOGO", "nogo")
# gazelle:prefix gitlab.com/FollieHiyuki/cuelumi
# gazelle:exclude cue.mod
# gazelle:exclude examples
# gazelle:exclude flake
# gazelle:exclude LICENSES
# gazelle:exclude schemata
gazelle(name = "gazelle")
nogo(

View file

@ -8,10 +8,10 @@ module(
repo_name = "com_gitlab_folliehiyuki_cuelumi",
)
# TODO: enable when `rules_nixpkgs_go` is published and stablized (https://github.com/tweag/rules_nixpkgs/issues/181)
# TODO: enable when `rules_nixpkgs_go` is published and stabilized (https://github.com/tweag/rules_nixpkgs/issues/181)
# bazel_dep(name = "rules_nixpkgs_core", version = "0.10.0")
#
# nix_repo = use_extension("@rules_nixpkgs_core//extentions:repository.bzl", "nix_repo")
# nix_repo = use_extension("@rules_nixpkgs_core//extensions:repository.bzl", "nix_repo")
# nix_repo.file(
# name = "nixpkgs",
# file = "//:nixpkgs.nix",
@ -19,14 +19,14 @@ module(
# )
# use_repo(nix_repo, "nixpkgs")
bazel_dep(name = "rules_go", version = "0.44.0")
bazel_dep(name = "rules_go", version = "0.44.2")
# FIXME: temporarily use the Go SDK from host, until we have rules_nixpkgs_go
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.nogo(nogo = "//:nogo_vet")
go_sdk.host()
bazel_dep(name = "gazelle", version = "0.34.0", dev_dependency = True)
bazel_dep(name = "gazelle", version = "0.35.0", dev_dependency = True)
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")

2491
MODULE.bazel.lock Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 Hoang Nguyen <folliekazetani@protonmail.com>
SPDX-License-Identifier: CC0-1.0

View file

@ -16,31 +16,33 @@
"type": "github"
}
},
"flake-utils": {
"flake-parts": {
"inputs": {
"systems": "systems"
"nixpkgs-lib": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"lastModified": 1704152458,
"narHash": "sha256-DS+dGw7SKygIWf9w4eNBUZsK+4Ug27NwEWmn2tnbycg=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "88a2cd8166694ba0b6cb374700799cec53aef527",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1703013332,
"narHash": "sha256-+tFNwMvlXLbJZXiMHqYq77z/RfmpfpiI3yjL6o/Zo9M=",
"lastModified": 1704194953,
"narHash": "sha256-RtDKd8Mynhe5CFnVT8s0/0yqtWFMM9LmCzXv/YKxnq4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "54aac082a4d9bb5bbc5c4e899603abfb76a3f6d6",
"rev": "bd645e8668ec6612439a9ee7e71f7eac4099d4f6",
"type": "github"
},
"original": {
@ -53,26 +55,11 @@
"root": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"treefmt-nix": "treefmt-nix"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
@ -80,11 +67,11 @@
]
},
"locked": {
"lastModified": 1702979157,
"narHash": "sha256-RnFBbLbpqtn4AoJGXKevQMCGhra4h6G2MPcuTSZZQ+g=",
"lastModified": 1704233915,
"narHash": "sha256-GYDC4HjyVizxnyKRbkrh1GugGp8PP3+fJuh40RPCN7k=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "2961375283668d867e64129c22af532de8e77734",
"rev": "e434da615ef74187ba003b529cc72f425f5d941e",
"type": "github"
},
"original": {

113
flake.nix
View file

@ -5,7 +5,11 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
@ -17,93 +21,26 @@
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, treefmt-nix, ... }:
flake-utils.lib.eachDefaultSystem
(system:
let
inherit (nixpkgs) lib;
pkgs = import nixpkgs { inherit system; };
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
outputs = inputs @ { flake-parts, nixpkgs, ... }:
flake-parts.lib.mkFlake { inherit inputs; }
{
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
# Information to be put into reuse's arguments
copyright = "Hoang Nguyen <folliekazetani@protonmail.com>";
licenses = [ "Apache-2.0" "CC0-1.0" ];
apps = {
# Wrap bazel with `nix run .#bazel`, for convenience
inherit (pkgs) bazel cue;
# Run `go mod tidy` then update BUILD.bazel files
gazelle =
let
arguments = [
[ "@rules_go//go" "--" "mod" "tidy" "-v" ]
[ "//:gazelle" ]
];
in
pkgs.writeShellScriptBin "gazelle-update" (with lib; concatStringsSep "\n"
(forEach
arguments
(x: "${pkgs.bazel}/bin/bazel run " + (concatStringsSep " " x))
)
);
# FIXME: doesn't work yet (https://github.com/cue-lang/cue/issues/2654)
package-metaschema = with pkgs;
writeShellScriptBin "package-metaschema" ''
set -e
INPUT_SCHEMA=/tmp/pulumi.json
OUTFILE=./schemata/pulumi/package.cue
${curl}/bin/curl -fsSL \
-o "$INPUT_SCHEMA" \
https://raw.githubusercontent.com/pulumi/pulumi/master/pkg/codegen/schema/pulumi.json
${cue}/bin/cue import --force \
--package="pulumi" \
--path="#Package" \
--outfile="$OUTFILE" \
"$INPUT_SCHEMA"
# Re-add the SPDX header, to make `reuse lint` happy
${reuse}/bin/reuse annotate \
--copyright="${copyright}" \
--license="${builtins.elemAt licenses 0}" \
--style=c \
"$OUTFILE"
'';
}
// (lib.listToAttrs (
builtins.map
(x: {
name = x;
value = with pkgs; writeShellScriptBin x ''
${bazel-buildtools}/bin/${x} "$@"
'';
})
[ "buildifier" "buildozer" ]));
in
{
apps = lib.mapAttrs
(_: value:
flake-utils.lib.mkApp { drv = value; })
apps;
formatter = treefmtEval.config.build.wrapper;
checks = {
treefmt = treefmtEval.config.build.check self;
license = pkgs.writeShellScriptBin "reuse-lint" ''
${pkgs.reuse}/bin/reuse lint
'';
};
devShells.default = with pkgs; mkShellNoCC {
name = "cuelumi-dev-shell";
inputsFrom = [ treefmtEval.config.build.devShell ];
packages = [ bazel ];
};
}
);
imports =
let
inherit (nixpkgs) lib;
moduleDir = ./flake;
in
with lib; mapAttrsToList (n: _: moduleDir + "/${n}")
(filterAttrs
(name: type:
type == "directory" && builtins.pathExists "${builtins.toString moduleDir}/${name}/default.nix")
(builtins.readDir moduleDir));
};
}

45
flake/apps/default.nix Normal file
View file

@ -0,0 +1,45 @@
# SPDX-FileCopyrightText: 2024 Hoang Nguyen <folliekazetani@protonmail.com>
#
# SPDX-License-Identifier: Apache-2.0
{ lib, ... }: {
perSystem = { pkgs, ... }:
let
apps = lib.foldr (a: b: a // b) { } [
{
gazelle =
let
arguments = [
[ "@rules_go//go" "--" "mod" "tidy" "-v" ]
[ "//:gazelle" ]
];
in
pkgs.writeShellScriptBin "gazelle-update" (with lib; concatStringsSep "\n"
(forEach
arguments
(x: "${pkgs.bazel}/bin/bazel run " + (concatStringsSep " " x))
)
);
pulumi-metaschema = with pkgs; writeShellApplication {
name = "pulumi-metaschema";
runtimeInputs = [ cue curl reuse ];
text = builtins.readFile ./pulumi-metaschema.sh;
};
}
# Wrap regularly used packages with `nix run .#<program>`, for convenience
(lib.mapAttrs
(prog: package: "${lib.getBin package}/bin/${prog}")
(with pkgs; {
bazel = bazel;
cue = cue;
buildozer = bazel-buildtools;
buildifier = bazel-buildtools;
}))
];
in
{
apps = lib.mapAttrs (_: value: { type = "app"; program = value; }) apps;
};
}

View file

@ -0,0 +1,30 @@
#!/bin/sh
# SPDX-FileCopyrightText: 2024 Hoang Nguyen <folliekazetani@protonmail.com>
#
# SPDX-License-Identifier: Apache-2.0
set -e
COPYRIGHT_HEADER="Hoang Nguyen <folliekazetani@protonmail.com>"
LICENSE="Apache-2.0"
INPUT_SCHEMA=/tmp/pulumi.json
OUTFILE=./schemata/pulumi/package.cue
curl -fsSL \
-o "$INPUT_SCHEMA" \
https://raw.githubusercontent.com/pulumi/pulumi/master/pkg/codegen/schema/pulumi.json
# FIXME: doesn't work yet (https://github.com/cue-lang/cue/issues/2654)
cue import --force \
--package="pulumi" \
--path="#Package" \
--outfile="$OUTFILE" \
"$INPUT_SCHEMA"
# Re-add the SPDX header, to make `reuse lint` happy
reuse annotate \
--copyright="$COPYRIGHT_HEADER" \
--license="$LICENSE" \
--style=c \
"$OUTFILE"

View file

@ -0,0 +1,22 @@
# SPDX-FileCopyrightText: 2024 Hoang Nguyen <folliekazetani@protonmail.com>
#
# SPDX-License-Identifier: Apache-2.0
{ inputs, lib, ... }: {
imports = [ inputs.treefmt-nix.flakeModule ];
perSystem = { pkgs, config, ... }: {
treefmt = import ./treefmt.nix { inherit pkgs lib; };
checks.license = pkgs.writeShellScriptBin "reuse-lint" ''
${pkgs.reuse}/bin/reuse lint
'';
devShells.default = pkgs.mkShellNoCC {
name = "cuelumi";
meta.description = "Development shell to work with cuelumi project";
inputsFrom = [ config.treefmt.build.devShell ];
packages = with pkgs; [ bazel ];
};
};
}

View file

@ -1,12 +1,15 @@
# SPDX-FileCopyrightText: 2023 Hoang Nguyen <folliekazetani@protonmail.com>
# SPDX-FileCopyrightText: 2024 Hoang Nguyen <folliekazetani@protonmail.com>
#
# SPDX-License-Identifier: Apache-2.0
_: {
projectRootFile = "flake.lock";
projectRootFile = "nixpkgs.nix";
programs = {
buildifier.enable = true;
buildifier = {
enable = true;
includes = [ "BUILD.bazel" "MODULE.bazel" "*.bzl" ];
};
# NOTE: https://github.com/cue-lang/cue/issues/2523
# cue.enable = true;

View file

@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: 2024 Hoang Nguyen <folliekazetani@protonmail.com>
#
# SPDX-License-Identifier: Apache-2.0
{ lib, ... }:
let
templates = lib.filterAttrs (name: type: type == "directory") (builtins.readDir ./.);
in
{
flake.templates = lib.mapAttrs
(dir: _: {
path = ./${dir};
description = "${dir} project template using cuelumi";
})
templates;
}

View file

@ -5,13 +5,13 @@
load("@rules_go//go:def.bzl", "go_library")
go_library(
name = "schema",
name = "pulumi",
srcs = [
"metadata.go",
"schema.go",
],
embedsrcs = ["providers.toml"],
importpath = "gitlab.com/FollieHiyuki/cuelumi/internal/schema",
importpath = "gitlab.com/FollieHiyuki/cuelumi/internal/schema/pulumi",
visibility = ["//:__subpackages__"],
deps = [
"@com_github_goccy_go_json//:go-json",

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
package schema
package pulumi
import (
_ "embed"

View file

@ -234,7 +234,7 @@ schema_file_path = "provider/cmd/pulumi-resource-cloudamqp/schema.json"
[cloudflare]
type = "github"
version = "v5.16.0"
version = "v5.17.0"
repo_slug = "pulumi/pulumi-cloudflare"
schema_file_path = "provider/cmd/pulumi-resource-cloudflare/schema.json"

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
package schema
package pulumi
import (
"github.com/goccy/go-json"

3
nogo_config.json.license Normal file
View file

@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 Hoang Nguyen <folliekazetani@protonmail.com>
SPDX-License-Identifier: CC0-1.0