diff --git a/.envrc b/.envrc index 28a7fd8c8..95c258d8f 100644 --- a/.envrc +++ b/.envrc @@ -20,13 +20,10 @@ fi # make .direnv if it doesn't exist mkdir -p "$(direnv_layout_dir)" -watch_file shell.nix -watch_file flake.nix # as outputs can change at anytime watch_file flake.lock - -# we need to watch the rust-toolchain.toml file so if any edits occur, -# then direnv can react to it and change the environment. -watch_file rust-toolchain.toml +watch_file nix/devshell.nix +watch_file nix/packages/charted.nix +watch_file nix/packages/helm-plugin.nix # try to use flakes, if it fails use normal nix (ie. shell.nix) use flake || use nix diff --git a/.gitignore b/.gitignore index 3ab5b21a2..e22f887e2 100644 --- a/.gitignore +++ b/.gitignore @@ -110,12 +110,8 @@ coverage # nyc test coverage .nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components +name: Checkout repository + s # node-waf configuration .lock-wscript @@ -692,6 +688,7 @@ FodyWeavers.xsd !crates/helm-charts/__fixtures__/*.tgz crates/database/data.db +!nix/packages/*.nix !hack/release/ !crates/bin/ !Cargo.lock diff --git a/flake.lock b/flake.lock index e950febee..c63a2a3df 100644 --- a/flake.lock +++ b/flake.lock @@ -16,24 +16,6 @@ "type": "github" } }, - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1724748588, @@ -53,9 +35,9 @@ "root": { "inputs": { "flake-compat": "flake-compat", - "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" + "rust-overlay": "rust-overlay", + "systems": "systems" } }, "rust-overlay": { diff --git a/flake.nix b/flake.nix index 19526f322..2e6a827b6 100644 --- a/flake.nix +++ b/flake.nix @@ -13,10 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. { - description = "charted is a free, open, and reliable way to distribute Helm charts"; + description = "🐻‍❄️📦 Free, open-source way to distribute Helm charts across the world"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - flake-utils.url = "github:numtide/flake-utils"; + systems.url = "github:nix-systems/default"; rust-overlay = { url = "github:oxalica/rust-overlay"; inputs.nixpkgs = { @@ -32,143 +32,32 @@ outputs = { nixpkgs, - flake-utils, rust-overlay, + systems, ... - }: - flake-utils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { - inherit system; - overlays = [(import rust-overlay)]; - }; - - cargoTOML = builtins.fromTOML (builtins.readFile ./Cargo.toml); - rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; - rustflags = - if pkgs.stdenv.isLinux - then ''-C link-arg=-fuse-ld=mold -C target-cpu=native $RUSTFLAGS'' - else ''$RUSTFLAGS''; - - # We use Rust nightly for all crates, so we want to match it. - rustPlatform = pkgs.makeRustPlatform { - cargo = rust; - rustc = rust; - }; - - charted = rustPlatform.buildRustPackage { - nativeBuildInputs = with pkgs; [pkg-config installShellFiles]; - buildInputs = with pkgs; - [openssl sqlite postgresql] - ++ (lib.optional stdenv.isDarwin (with darwin.apple_sdk.frameworks; [CoreFoundation Security SystemConfiguration])); - - version = "${cargoTOML.workspace.package.version}"; - name = "charted"; - src = ./.; - - env.CHARTED_DISTRIBUTION_KIND = "nix"; - cargoBuildFlags = ["--package" "charted"]; - cargoLock = { - lockFile = ./Cargo.lock; - outputHashes = { - "azalia-0.1.0" = "sha256-b0C26qCYQ1aLqgbVXwM+j8WCJxKA19a3lMfveVxSrFs="; - }; - }; - - postInstall = '' - installShellCompletion --cmd charted \ - --bash <($out/bin/charted completions bash) \ - --fish <($out/bin/charted completions fish) \ - --zsh <($out/bin/charted completions zsh) - ''; - - useNextest = true; - meta = with pkgs.lib; { - description = "charted is a free, open, and reliable way to distribute Helm charts"; - homepage = "https://charts.noelware.org"; - license = with licenses; [asl20]; - maintainers = with maintainers; [auguwu spotlightishere noelware]; - mainProgram = "charted"; - }; - }; - - helm-plugin = rustPlatform.buildRustPackage { - nativeBuildInputs = with pkgs; [pkg-config protobuf]; - buildInputs = with pkgs; - [openssl sqlite postgresql] - ++ (lib.optional stdenv.isDarwin (with darwin.apple_sdk.frameworks; [CoreFoundation Security SystemConfiguration])); - cargoSha256 = pkgs.lib.fakeSha256; - version = "${cargoTOML.workspace.package.version}"; - name = "charted-helm-plugin"; - src = ./.; - - env.CHARTED_DISTRIBUTION_KIND = "nix"; - - cargoBuildFlags = ["--package" "charted-helm-plugin"]; - cargoLock = { - lockFile = ./Cargo.lock; - outputHashes = { - "azalia-0.1.0" = "sha256-b0C26qCYQ1aLqgbVXwM+j8WCJxKA19a3lMfveVxSrFs="; - }; - }; - - postPatch = '' - sed -i '/^hooks:/,+2 d' plugin.yaml - ''; - - postInstall = '' - install -Dm644 plugin.yaml $out/charted-helm-plugin/plugin.yaml - mv $out/bin $out/charted-helm-plugin - ''; - - useNextest = true; - meta = with pkgs.lib; { - description = "Helm plugin to help aid developing Helm charts with charted"; - homepage = "https://charts.noelware.org"; - license = with licenses; [asl20]; - maintainers = with maintainers; [auguwu spotlightishere noelware]; - }; + }: let + eachSystem = nixpkgs.lib.genAttrs (import systems); + overlays = [(import rust-overlay)]; + nixpkgsFor = system: + import nixpkgs { + inherit system overlays; }; + in { + formatter = eachSystem (system: (nixpkgsFor system).alejandra); + packages = eachSystem (system: let + pkgs = nixpkgsFor system; + charted = pkgs.callPackage ./nix/packages/charted.nix {}; + helm-plugin = pkgs.callPackage ./nix/packages/helm-plugin.nix {}; in { - packages = { - inherit charted helm-plugin; - - default = charted; - all = pkgs.symlinkJoin { - name = "charted-${cargoTOML.workspace.package.version}"; - paths = [charted helm-plugin]; - }; - }; - - devShells.default = pkgs.mkShell { - LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (with pkgs; [openssl sqlite postgresql]); - nativeBuildInputs = with pkgs; - [pkg-config sqlite postgresql.lib] - ++ (lib.optional stdenv.isLinux [mold lldb]) - ++ (lib.optional stdenv.isDarwin (with darwin.apple_sdk.frameworks; [CoreFoundation Security SystemConfiguration])); - - buildInputs = with pkgs; - [ - cargo-nextest - cargo-machete - cargo-deny + inherit charted helm-plugin; - # I don't plan to add MySQL support and probably never will. - (diesel-cli.override { - mysqlSupport = false; - postgresqlSupport = true; - sqliteSupport = true; - }) - - openssl - git - - rust - ] - ++ (lib.optional stdenv.isLinux [glibc]); + default = charted; + }); - shellHook = '' - export RUSTFLAGS="--cfg tokio_unstable ${rustflags}" - ''; - }; + devShells = eachSystem (system: let + pkgs = nixpkgsFor system; + in { + default = import ./nix/devshell.nix {inherit pkgs;}; }); + }; } diff --git a/nix/common.nix b/nix/common.nix new file mode 100644 index 000000000..cc5672369 --- /dev/null +++ b/nix/common.nix @@ -0,0 +1,32 @@ +# 🐻‍❄️📦 charted-server: Free, open source, and reliable Helm Chart registry made in Rust +# Copyright 2022-2024 Noelware, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +{ + cargoTOML = builtins.fromTOML (builtins.readFile ../Cargo.toml); + outputHashes = { + "azalia-0.1.0" = "sha256-b0C26qCYQ1aLqgbVXwM+j8WCJxKA19a3lMfveVxSrFs="; + }; + + rustflags = stdenv: + if stdenv.isLinux + then ''-C link-arg=-fuse-ld=mold -C target-cpu=native $RUSTFLAGS'' + else ''$RUSTFLAGS''; + + mkRustPlatform = rust: rust.fromRustupToolchainFile ../rust-toolchain.toml; + mkNixpkgsRustPlatform = pkgs: toolchain: + pkgs.makeRustPlatform { + rustc = toolchain; + cargo = toolchain; + }; +} diff --git a/nix/devshell.nix b/nix/devshell.nix new file mode 100644 index 000000000..ee571a727 --- /dev/null +++ b/nix/devshell.nix @@ -0,0 +1,54 @@ +# 🐻‍❄️📦 charted-server: Free, open source, and reliable Helm Chart registry made in Rust +# Copyright 2022-2024 Noelware, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +{pkgs}: +with pkgs; let + common = import ./common.nix; + toolchain = common.mkRustPlatform pkgs.rust-bin; + rustflags = common.rustflags stdenv; +in + mkShell { + LD_LIBRARY_PATH = lib.makeLibraryPath [openssl sqlite postgresql]; + nativeBuildInputs = + [pkg-config sqlite postgresql.lib] + ++ (lib.optional stdenv.isLinux [mold lldb]) + ++ (lib.optional stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ + CoreFoundation + Security + SystemConfiguration + ])); + + buildInputs = + [ + cargo-nextest # replacement for `cargo test` + cargo-machete # used to validate dependencies + cargo-deny # used to validate licenses, vulns, etc. + + # I don't plan to add MySQL support and probably never will. + (diesel-cli.override { + mysqlSupport = false; + postgresqlSupport = true; + sqliteSupport = true; + }) + + toolchain # rust toolchain + openssl + git + ] + ++ (lib.optional stdenv.isLinux [glibc]); + + shellHook = '' + export RUSTFLAGS="--cfg tokio_unstable ${rustflags}" + ''; + } diff --git a/nix/packages/charted.nix b/nix/packages/charted.nix new file mode 100644 index 000000000..e11d71df7 --- /dev/null +++ b/nix/packages/charted.nix @@ -0,0 +1,71 @@ +# 🐻‍❄️📦 charted-server: Free, open source, and reliable Helm Chart registry made in Rust +# Copyright 2022-2024 Noelware, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +{ + makeRustPlatform, + pkg-config, + installShellFiles, + openssl, + sqlite, + postgresql, + darwin, + stdenv, + rust-bin, + lib, +}: let + common = import ../common.nix; + rust-toolchain = common.mkRustPlatform rust-bin; + rustPlatform = common.mkNixpkgsRustPlatform {inherit makeRustPlatform;} rust-toolchain; + version = common.cargoTOML.workspace.package.version; +in + rustPlatform.buildRustPackage { + inherit version; + + pname = "charted"; + src = ../../.; + + useNextest = true; + cargoBuildFlags = ["--package" "charted"]; + cargoLock = { + lockFile = ../../Cargo.lock; + outputHashes = common.outputHashes; + }; + + nativeBuildInputs = [pkg-config installShellFiles]; + buildInputs = + [openssl sqlite postgresql] + ++ (lib.optional stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ + CoreFoundation + Security + SystemConfiguration + ])); + + env.CHARTED_DISTRIBUTION_KIND = "nix"; + + postInstall = '' + installShellCompletion --cmd charted \ + --bash <($out/bin/charted completions bash) \ + --fish <($out/bin/charted completions fish) \ + --zsh <($out/bin/charted completions zsh) + ''; + + meta = with lib; { + description = "🐻‍❄️📦 Free, open-source way to distribute Helm charts across the world"; + maintainers = with maintainers; [auguwu spotlightishere noelware]; + mainProgram = "charted"; + changelog = "https://charts.noelware.org/changelogs/charted#v${version}"; + homepage = "https://charts.noelware.org"; + license = with licenses; [asl20]; + }; + } diff --git a/nix/packages/helm-plugin.nix b/nix/packages/helm-plugin.nix new file mode 100644 index 000000000..c9b9ad235 --- /dev/null +++ b/nix/packages/helm-plugin.nix @@ -0,0 +1,73 @@ +# 🐻‍❄️📦 charted-server: Free, open source, and reliable Helm Chart registry made in Rust +# Copyright 2022-2024 Noelware, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +{ + makeRustPlatform, + pkg-config, + installShellFiles, + openssl, + sqlite, + postgresql, + darwin, + stdenv, + rust-bin, + lib, +}: let + common = import ../common.nix; + rust-toolchain = common.mkRustPlatform rust-bin; + rustPlatform = common.mkNixpkgsRustPlatform {inherit makeRustPlatform;} rust-toolchain; + version = common.cargoTOML.workspace.package.version; +in + rustPlatform.buildRustPackage { + inherit version; + + pname = "charted-helm-plugin"; + src = ../../.; + + useNextest = true; + cargoBuildFlags = ["--package" "charted-helm-plugin"]; + cargoLock = { + lockFile = ../../Cargo.lock; + outputHashes = common.outputHashes; + }; + + nativeBuildInputs = [pkg-config installShellFiles]; + buildInputs = + [openssl sqlite postgresql] + ++ (lib.optional stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ + CoreFoundation + Security + SystemConfiguration + ])); + + env.CHARTED_DISTRIBUTION_KIND = "nix"; + + postPatch = '' + sed -i '/^hooks:/,+2 d' plugin.yaml + ''; + + postInstall = '' + install -Dm644 plugin.yaml $out/charted-helm-plugin/plugin.yaml + mv $out/bin $out/charted-helm-plugin + ''; + + meta = with lib; { + description = "🐻‍❄️📦 Free, open-source way to distribute Helm charts across the world"; + maintainers = with maintainers; [auguwu spotlightishere noelware]; + mainProgram = "charted"; + changelog = "https://charts.noelware.org/changelogs/charted#v${version}"; + homepage = "https://charts.noelware.org"; + license = with licenses; [asl20]; + }; + }