From 203dad0703953117c1663bfe45c6a2cadcfef94b Mon Sep 17 00:00:00 2001 From: seth Date: Tue, 30 Apr 2024 18:03:34 -0400 Subject: [PATCH] nix: remove subflake --- .github/workflows/check.yml | 2 - .github/workflows/docker.yml | 4 +- .github/workflows/nix.yml | 1 - .github/workflows/update-flake.yml | 6 - flake.lock | 73 +++++++++- flake.nix | 87 +++++++++++- nix/dev/args.nix | 11 -- nix/dev/docker.nix | 25 ---- nix/dev/flake.lock | 213 ----------------------------- nix/dev/flake.nix | 65 --------- nix/dev/pre-commit.nix | 20 --- nix/dev/procfiles.nix | 11 -- nix/dev/shell.nix | 36 ----- nix/dev/static.nix | 41 ------ nix/dev/treefmt.nix | 22 --- nix/static.nix | 27 ++++ 16 files changed, 185 insertions(+), 459 deletions(-) delete mode 100644 nix/dev/args.nix delete mode 100644 nix/dev/docker.nix delete mode 100644 nix/dev/flake.lock delete mode 100644 nix/dev/flake.nix delete mode 100644 nix/dev/pre-commit.nix delete mode 100644 nix/dev/procfiles.nix delete mode 100644 nix/dev/shell.nix delete mode 100644 nix/dev/static.nix delete mode 100644 nix/dev/treefmt.nix create mode 100644 nix/static.nix diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 09bab7e..ced6425 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -53,8 +53,6 @@ jobs: - name: Run Clippy continue-on-error: true run: | - set -euo pipefail - cargo clippy \ --all-features \ --all-targets \ diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index b4bb06f..de04a9e 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -26,8 +26,10 @@ jobs: - name: Build Docker image id: build + env: + ARCH: ${{ matrix.arch }} run: | - nix build --print-build-logs ./nix/dev#container-${{ matrix.arch }} + nix build --print-build-logs .#container-"$ARCH" [ ! -L result ] && exit 1 echo "path=$(readlink -f result)" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index e038910..44b1203 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -49,5 +49,4 @@ jobs: - name: Run checks run: | - cd ./nix/dev nix flake check --print-build-logs --show-trace diff --git a/.github/workflows/update-flake.yml b/.github/workflows/update-flake.yml index 6eb5fb0..18914bf 100644 --- a/.github/workflows/update-flake.yml +++ b/.github/workflows/update-flake.yml @@ -32,12 +32,6 @@ jobs: - name: Update flake inputs run: | - pushd nix/dev - nix flake update \ - --commit-lock-file \ - --commit-lockfile-summary "nix: update dev flake.lock" - popd - nix flake update \ --commit-lock-file \ --commit-lockfile-summary "nix: update flake.lock" diff --git a/flake.lock b/flake.lock index b9c339e..52a8d77 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,38 @@ { "nodes": { + "flake-checks": { + "locked": { + "lastModified": 1714464432, + "narHash": "sha256-MYeWsW8BDA3KO17wwuc8D+7l8PSidbdQIv64QNNVEcI=", + "owner": "getchoo", + "repo": "flake-checks", + "rev": "a711dab545e8b964914ac01ed06971a5a37ae22b", + "type": "github" + }, + "original": { + "owner": "getchoo", + "repo": "flake-checks", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1714314149, @@ -18,7 +51,45 @@ }, "root": { "inputs": { - "nixpkgs": "nixpkgs" + "flake-checks": "flake-checks", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1714443211, + "narHash": "sha256-lKTA3XqRo4aVgkyTSCtpcALpGXdmkilHTtN00eRg0QU=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "ce35c36f58f82cee6ec959e0d44c587d64281b6f", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index e575b27..15211ef 100644 --- a/flake.nix +++ b/flake.nix @@ -1,12 +1,22 @@ { description = "Discord bot for Prism Launcher"; - inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + + flake-checks.url = "github:getchoo/flake-checks"; + + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; outputs = { self, nixpkgs, - ... + flake-checks, + rust-overlay, }: let systems = [ "x86_64-linux" @@ -17,11 +27,80 @@ forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system}); in { + checks = forAllSystems (pkgs: let + flake-checks' = flake-checks.lib.mkChecks { + inherit pkgs; + root = ./.; + }; + in { + check-actionlint = flake-checks'.actionlint; + check-alejandra = flake-checks'.alejandra; + check-deadnix = flake-checks'.deadnix; + check-rustfmt = flake-checks'.rustfmt; + check-statix = flake-checks'.statix; + }); + + devShells = forAllSystems (pkgs: { + default = pkgs.mkShell { + packages = with pkgs; [ + redis + + # linters & formatters + actionlint + nodePackages.prettier + + # rust tools + clippy + rustfmt + rust-analyzer + + # nix tools + self.formatter.${system} + deadnix + nil + statix + ]; + + inputsFrom = [self.packages.${pkgs.system}.refraction]; + RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; + }; + }); + + formatter = forAllSystems (pkgs: pkgs.alejandra); + nixosModules.default = import ./nix/module.nix self; - packages = forAllSystems (pkgs: rec { + packages = forAllSystems ({ + lib, + pkgs, + system, + ... + }: let + packages' = self.packages.${system}; + + mkStatic = pkgs.callPackage ./nix/static.nix { + inherit (self.packages.${pkgs.system}) refraction; + rust-overlay = rust-overlay.packages.${system}; + }; + + mkContainerFor = refraction: let + architecture = refraction.stdenv.hostPlatform.ubootArch; + in + pkgs.dockerTools.buildLayeredImage { + name = "refraction"; + tag = "latest-${architecture}"; + config.Cmd = [(lib.getExe refraction)]; + inherit architecture; + }; + in { refraction = pkgs.callPackage ./nix/derivation.nix {inherit self;}; - default = refraction; + + static-x86_64 = mkStatic {arch = "x86_64";}; + static-aarch64 = mkStatic {arch = "aarch64";}; + container-x86_64 = mkContainerFor packages'.static-x86_64; + container-aarch64 = mkContainerFor packages'.static-aarch64; + + default = packages'.refraction; }); overlays.default = _: prev: { diff --git a/nix/dev/args.nix b/nix/dev/args.nix deleted file mode 100644 index 42b60e2..0000000 --- a/nix/dev/args.nix +++ /dev/null @@ -1,11 +0,0 @@ -{inputs, ...}: { - perSystem = { - lib, - system, - ... - }: { - _module.args = { - refraction' = lib.mapAttrs (lib.const (v: v.${system} or v)) (inputs.get-flake ../../.); - }; - }; -} diff --git a/nix/dev/docker.nix b/nix/dev/docker.nix deleted file mode 100644 index f778070..0000000 --- a/nix/dev/docker.nix +++ /dev/null @@ -1,25 +0,0 @@ -{withSystem, ...}: { - perSystem = { - lib, - pkgs, - self', - ... - }: let - containerFor = arch: - pkgs.dockerTools.buildLayeredImage { - name = "refraction"; - tag = "latest-${arch}"; - contents = [pkgs.dockerTools.caCertificates]; - config.Cmd = [ - (lib.getExe self'.packages."refraction-static-${arch}") - ]; - - architecture = withSystem "${arch}-linux" ({pkgs, ...}: pkgs.pkgsStatic.go.GOARCH); - }; - in { - packages = { - container-x86_64 = containerFor "x86_64"; - container-aarch64 = containerFor "aarch64"; - }; - }; -} diff --git a/nix/dev/flake.lock b/nix/dev/flake.lock deleted file mode 100644 index 78e4f52..0000000 --- a/nix/dev/flake.lock +++ /dev/null @@ -1,213 +0,0 @@ -{ - "nodes": { - "flake-parts": { - "inputs": { - "nixpkgs-lib": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1712014858, - "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "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" - } - }, - "get-flake": { - "locked": { - "lastModified": 1694475786, - "narHash": "sha256-s5wDmPooMUNIAAsxxCMMh9g68AueGg63DYk2hVZJbc8=", - "owner": "ursi", - "repo": "get-flake", - "rev": "ac54750e3b95dab6ec0726d77f440efe6045bec1", - "type": "github" - }, - "original": { - "owner": "ursi", - "repo": "get-flake", - "rev": "ac54750e3b95dab6ec0726d77f440efe6045bec1", - "type": "github" - } - }, - "gitignore": { - "inputs": { - "nixpkgs": [ - "pre-commit-hooks", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1709087332, - "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", - "owner": "hercules-ci", - "repo": "gitignore.nix", - "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "gitignore.nix", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1714314149, - "narHash": "sha256-yNAevSKF4krRWacmLUsLK7D7PlfuY3zF0lYnGYNi9vQ=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "cf8cc1201be8bc71b7cbbbdaf349b22f4f99c7ae", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "pre-commit-hooks": { - "inputs": { - "flake-compat": [], - "flake-utils": "flake-utils", - "gitignore": "gitignore", - "nixpkgs": [ - "nixpkgs" - ], - "nixpkgs-stable": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1714478972, - "narHash": "sha256-q//cgb52vv81uOuwz1LaXElp3XAe1TqrABXODAEF6Sk=", - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "2849da033884f54822af194400f8dff435ada242", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "type": "github" - } - }, - "procfile-nix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1714465080, - "narHash": "sha256-GeLqyVPS485iLawJVgA/CmvDgeRQcMh8RkSvBp9dp9U=", - "owner": "getchoo", - "repo": "procfile-nix", - "rev": "be0f7c40dab3cf93ffc61d8736c5a63c67efd78a", - "type": "github" - }, - "original": { - "owner": "getchoo", - "repo": "procfile-nix", - "type": "github" - } - }, - "root": { - "inputs": { - "flake-parts": "flake-parts", - "get-flake": "get-flake", - "nixpkgs": "nixpkgs", - "pre-commit-hooks": "pre-commit-hooks", - "procfile-nix": "procfile-nix", - "rust-overlay": "rust-overlay", - "treefmt-nix": "treefmt-nix" - } - }, - "rust-overlay": { - "inputs": { - "flake-utils": [ - "pre-commit-hooks", - "flake-utils" - ], - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1714443211, - "narHash": "sha256-lKTA3XqRo4aVgkyTSCtpcALpGXdmkilHTtN00eRg0QU=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "ce35c36f58f82cee6ec959e0d44c587d64281b6f", - "type": "github" - }, - "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "type": "github" - } - }, - "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": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1714058656, - "narHash": "sha256-Qv4RBm4LKuO4fNOfx9wl40W2rBbv5u5m+whxRYUMiaA=", - "owner": "numtide", - "repo": "treefmt-nix", - "rev": "c6aaf729f34a36c445618580a9f95a48f5e4e03f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "treefmt-nix", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/nix/dev/flake.nix b/nix/dev/flake.nix deleted file mode 100644 index ac316d7..0000000 --- a/nix/dev/flake.nix +++ /dev/null @@ -1,65 +0,0 @@ -{ - description = "Discord bot for Prism Launcher"; - - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; - flake-parts = { - url = "github:hercules-ci/flake-parts"; - inputs.nixpkgs-lib.follows = "nixpkgs"; - }; - - get-flake.url = "github:ursi/get-flake/ac54750e3b95dab6ec0726d77f440efe6045bec1"; - - pre-commit-hooks = { - url = "github:cachix/pre-commit-hooks.nix"; - inputs = { - nixpkgs.follows = "nixpkgs"; - nixpkgs-stable.follows = "nixpkgs"; - flake-compat.follows = ""; - }; - }; - - procfile-nix = { - url = "github:getchoo/procfile-nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - - rust-overlay = { - url = "github:oxalica/rust-overlay"; - inputs = { - nixpkgs.follows = "nixpkgs"; - flake-utils.follows = "pre-commit-hooks/flake-utils"; - }; - }; - - treefmt-nix = { - url = "github:numtide/treefmt-nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - }; - - outputs = {flake-parts, ...} @ inputs: - flake-parts.lib.mkFlake {inherit inputs;} { - debug = true; - imports = [ - ./args.nix - ./docker.nix - ./pre-commit.nix - ./procfiles.nix - ./shell.nix - ./static.nix - ./treefmt.nix - - inputs.pre-commit-hooks.flakeModule - inputs.procfile-nix.flakeModule - inputs.treefmt-nix.flakeModule - ]; - - systems = [ - "x86_64-linux" - "aarch64-linux" - "x86_64-darwin" - "aarch64-darwin" - ]; - }; -} diff --git a/nix/dev/pre-commit.nix b/nix/dev/pre-commit.nix deleted file mode 100644 index 39d6e9e..0000000 --- a/nix/dev/pre-commit.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ - perSystem = { - config, - lib, - ... - }: { - pre-commit.settings = { - rootSrc = lib.mkForce ../../.; - hooks = { - actionlint.enable = true; - nil.enable = true; - statix.enable = true; - treefmt = { - enable = true; - package = config.treefmt.build.wrapper; - }; - }; - }; - }; -} diff --git a/nix/dev/procfiles.nix b/nix/dev/procfiles.nix deleted file mode 100644 index c8c8c2e..0000000 --- a/nix/dev/procfiles.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ - perSystem = { - lib, - pkgs, - ... - }: { - procfiles.daemons.processes = { - redis = lib.getExe' pkgs.redis "redis-server"; - }; - }; -} diff --git a/nix/dev/shell.nix b/nix/dev/shell.nix deleted file mode 100644 index e0adb94..0000000 --- a/nix/dev/shell.nix +++ /dev/null @@ -1,36 +0,0 @@ -{ - perSystem = { - pkgs, - config, - self', - refraction', - ... - }: { - devShells.default = pkgs.mkShell { - shellHook = '' - ${config.pre-commit.installationScript} - ''; - - packages = with pkgs; [ - # general - actionlint - nodePackages.prettier - config.procfiles.daemons.package - - # rust - clippy - rustfmt - rust-analyzer - - # nix - self'.formatter - deadnix - nil - statix - ]; - - inputsFrom = [refraction'.packages.refraction]; - RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; - }; - }; -} diff --git a/nix/dev/static.nix b/nix/dev/static.nix deleted file mode 100644 index 3a1c470..0000000 --- a/nix/dev/static.nix +++ /dev/null @@ -1,41 +0,0 @@ -{ - perSystem = { - lib, - pkgs, - inputs', - refraction', - ... - }: let - targets = with pkgs.pkgsCross; { - x86_64 = musl64.pkgsStatic; - aarch64 = aarch64-multiplatform.pkgsStatic; - }; - - toolchain = inputs'.rust-overlay.packages.rust.minimal.override { - extensions = ["rust-std"]; - targets = map (pkgs: pkgs.stdenv.hostPlatform.config) (lib.attrValues targets); - }; - - rustPlatforms = - lib.mapAttrs ( - lib.const (pkgs: - pkgs.makeRustPlatform ( - lib.genAttrs ["cargo" "rustc"] (lib.const toolchain) - )) - ) - targets; - - buildWith = rustPlatform: - refraction'.packages.refraction.override { - inherit rustPlatform; - optimizeSize = true; - }; - in { - packages = - lib.mapAttrs' ( - target: rustPlatform: - lib.nameValuePair "refraction-static-${target}" (buildWith rustPlatform) - ) - rustPlatforms; - }; -} diff --git a/nix/dev/treefmt.nix b/nix/dev/treefmt.nix deleted file mode 100644 index 13a1675..0000000 --- a/nix/dev/treefmt.nix +++ /dev/null @@ -1,22 +0,0 @@ -{ - perSystem = { - treefmt = { - projectRootFile = ".git/config"; - - programs = { - alejandra.enable = true; - deadnix.enable = true; - prettier.enable = true; - rustfmt.enable = true; - }; - - settings.global = { - excludes = [ - "./target" - "./flake.lock" - "./Cargo.lock" - ]; - }; - }; - }; -} diff --git a/nix/static.nix b/nix/static.nix new file mode 100644 index 0000000..5d2c2be --- /dev/null +++ b/nix/static.nix @@ -0,0 +1,27 @@ +{ + lib, + refraction, + rust-overlay, + pkgsCross, +}: {arch}: let + targets = with pkgsCross; { + x86_64 = musl64.pkgsStatic; + aarch64 = aarch64-multiplatform.pkgsStatic; + }; + + getRustcTarget = pkgs: pkgs.stdenv.hostPlatform.rust.rustcTarget; + toolchain = rust-overlay.rust.minimal.override { + extensions = ["rust-std"]; + targets = lib.mapAttrsToList (lib.const getRustcTarget) targets; + }; + + mkRustPlatformWith = pkgs: + pkgs.makeRustPlatform ( + lib.genAttrs ["cargo" "rustc"] (lib.const toolchain) + ); + rustPlatforms = lib.mapAttrs (lib.const mkRustPlatformWith) targets; +in + refraction.override { + rustPlatform = rustPlatforms.${arch}; + optimizeSize = true; + }