sealme/flake.nix

97 lines
2.6 KiB
Nix
Raw Normal View History

2023-09-03 16:03:23 +00:00
{
description = "Utility to run kubeseal against *.sealme.* files";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
2023-09-03 16:12:24 +00:00
gomod2nix.url = "github:nix-community/gomod2nix";
2023-09-03 16:03:23 +00:00
treefmt-nix.url = "github:numtide/treefmt-nix";
};
outputs = inputs @ {flake-parts, ...}:
2023-09-03 16:34:56 +00:00
flake-parts.lib.mkFlake {inherit inputs;} ({withSystem, ...}: {
2023-09-03 16:03:23 +00:00
imports = [
inputs.treefmt-nix.flakeModule
];
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
2023-09-03 16:34:56 +00:00
2023-09-03 16:03:23 +00:00
perSystem = {
config,
self',
inputs',
pkgs,
system,
...
}: {
2023-09-03 16:12:24 +00:00
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
inputs.gomod2nix.overlays.default
];
config = {};
};
packages.default = pkgs.buildGoApplication {
pname = "sealme";
2023-09-03 17:39:38 +00:00
version = "0.2.0";
2023-09-03 16:12:24 +00:00
pwd = ./.;
src = ./.;
modules = ./gomod2nix.toml;
};
2023-09-03 16:34:56 +00:00
packages.sealme = config.packages.default;
2023-09-03 17:39:38 +00:00
packages.ksecret = let
build-inputs = with pkgs; [kubectl yq-go];
script = (pkgs.writeScriptBin "ksecret" (builtins.readFile ./scripts/ksecret.sh)).overrideAttrs (old: {
buildComamnd = "${old.buildCommand}\n patchShebangs $out";
});
completion-zsh =
pkgs.writeTextDir "share/zsh/site-functions/_ksecret"
''
compdef _ksecret ksecret
_ksecret() {
service=kubectl
CURRENT+=2
words="kubectl get secrets ''${words[@]:1}"
_kubectl
}
'';
in
pkgs.symlinkJoin {
name = "ksecret";
paths = [script completion-zsh];
buildInputs = [pkgs.makeWrapper];
postBuild = "wrapProgram $out/bin/ksecret --prefix PATH : ${pkgs.lib.makeBinPath build-inputs}";
};
2023-09-03 16:03:23 +00:00
treefmt = {
projectRootFile = ".git/config";
programs = {
alejandra.enable = true;
gofumpt.enable = true;
};
};
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
# Go tools
go
gopls
2023-09-03 16:12:24 +00:00
gomod2nix
2023-09-03 16:03:23 +00:00
];
};
};
2023-09-03 16:34:56 +00:00
2023-09-03 16:03:23 +00:00
flake = {
2023-09-03 16:34:56 +00:00
overlays.default = final: prev:
withSystem prev.stdenv.hostPlatform.system (
{config, ...}: {
sealme = config.packages.sealme;
2023-09-03 17:39:38 +00:00
ksecret = config.packages.ksecret;
2023-09-03 16:34:56 +00:00
}
);
2023-09-03 16:03:23 +00:00
};
2023-09-03 16:34:56 +00:00
});
2023-09-03 16:03:23 +00:00
}