nix: remove subflake

This commit is contained in:
seth 2024-04-30 18:03:34 -04:00 committed by Sefa Eyeoglu
parent 5f5f399c8f
commit 203dad0703
16 changed files with 185 additions and 459 deletions

View file

@ -53,8 +53,6 @@ jobs:
- name: Run Clippy - name: Run Clippy
continue-on-error: true continue-on-error: true
run: | run: |
set -euo pipefail
cargo clippy \ cargo clippy \
--all-features \ --all-features \
--all-targets \ --all-targets \

View file

@ -26,8 +26,10 @@ jobs:
- name: Build Docker image - name: Build Docker image
id: build id: build
env:
ARCH: ${{ matrix.arch }}
run: | run: |
nix build --print-build-logs ./nix/dev#container-${{ matrix.arch }} nix build --print-build-logs .#container-"$ARCH"
[ ! -L result ] && exit 1 [ ! -L result ] && exit 1
echo "path=$(readlink -f result)" >> "$GITHUB_OUTPUT" echo "path=$(readlink -f result)" >> "$GITHUB_OUTPUT"

View file

@ -49,5 +49,4 @@ jobs:
- name: Run checks - name: Run checks
run: | run: |
cd ./nix/dev
nix flake check --print-build-logs --show-trace nix flake check --print-build-logs --show-trace

View file

@ -32,12 +32,6 @@ jobs:
- name: Update flake inputs - name: Update flake inputs
run: | run: |
pushd nix/dev
nix flake update \
--commit-lock-file \
--commit-lockfile-summary "nix: update dev flake.lock"
popd
nix flake update \ nix flake update \
--commit-lock-file \ --commit-lock-file \
--commit-lockfile-summary "nix: update flake.lock" --commit-lockfile-summary "nix: update flake.lock"

73
flake.lock generated
View file

@ -1,5 +1,38 @@
{ {
"nodes": { "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": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1714314149, "lastModified": 1714314149,
@ -18,7 +51,45 @@
}, },
"root": { "root": {
"inputs": { "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"
} }
} }
}, },

View file

@ -1,12 +1,22 @@
{ {
description = "Discord bot for Prism Launcher"; 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 = { outputs = {
self, self,
nixpkgs, nixpkgs,
... flake-checks,
rust-overlay,
}: let }: let
systems = [ systems = [
"x86_64-linux" "x86_64-linux"
@ -17,11 +27,80 @@
forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system}); forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system});
in { 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; 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;}; 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: { overlays.default = _: prev: {

View file

@ -1,11 +0,0 @@
{inputs, ...}: {
perSystem = {
lib,
system,
...
}: {
_module.args = {
refraction' = lib.mapAttrs (lib.const (v: v.${system} or v)) (inputs.get-flake ../../.);
};
};
}

View file

@ -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";
};
};
}

213
nix/dev/flake.lock generated
View file

@ -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
}

View file

@ -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"
];
};
}

View file

@ -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;
};
};
};
};
}

View file

@ -1,11 +0,0 @@
{
perSystem = {
lib,
pkgs,
...
}: {
procfiles.daemons.processes = {
redis = lib.getExe' pkgs.redis "redis-server";
};
};
}

View file

@ -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}";
};
};
}

View file

@ -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;
};
}

View file

@ -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"
];
};
};
};
}

27
nix/static.nix Normal file
View file

@ -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;
}