nix: move dev outputs to subflake

This commit is contained in:
seth 2024-04-10 01:03:45 -04:00
parent 3503dda44d
commit 921540e249
No known key found for this signature in database
GPG key ID: D31BD0D494BBEE86
18 changed files with 461 additions and 331 deletions

2
.envrc
View file

@ -1,5 +1,5 @@
if has nix_direnv_version; then if has nix_direnv_version; then
use flake use flake ./nix/dev
fi fi
dotenv_if_exists dotenv_if_exists

View file

@ -27,7 +27,7 @@ jobs:
- name: Build Docker image - name: Build Docker image
id: build id: build
run: | run: |
nix build --print-build-logs .#container-${{ matrix.arch }} nix build --print-build-logs ./nix/dev#container-${{ matrix.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

@ -48,4 +48,6 @@ jobs:
uses: DeterminateSystems/magic-nix-cache-action@v4 uses: DeterminateSystems/magic-nix-cache-action@v4
- name: Run checks - name: Run checks
run: nix flake check --print-build-logs --show-trace run: |
cd ./nix/dev
nix flake check --print-build-logs --show-trace

View file

@ -8,21 +8,65 @@ on:
jobs: jobs:
update: update:
name: Run update
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: write contents: write
pull-requests: write pull-requests: write
env:
PR_BRANCH: 'update-lockfiles'
steps: steps:
- uses: actions/checkout@v4 - name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix - name: Install Nix
uses: nixbuild/nix-quick-install-action@v27 uses: DeterminateSystems/nix-installer-action@v10
- name: Update and create PR - name: Set Git user info
uses: DeterminateSystems/update-flake-lock@v21 run: |
with: git config user.name 'github-actions[bot]'
commit-msg: 'nix: update flake.lock' git config user.email 'github-actions[bot]@users.noreply.github.com'
pr-title: 'nix: update flake.lock'
token: ${{ github.token }} - name: Create new branch
id: branch
run: |
git switch -c "$PR_BRANCH"
- 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"
- name: Make PR if needed
env:
GH_TOKEN: ${{ github.token }}
run: |
if ! git diff --color=always --exit-code origin/main; then
git fetch origin "$PR_BRANCH" || true
git push --force-with-lease -u origin "$PR_BRANCH"
open_prs="$(gh pr list --base main --head "$PR_BRANCH" | wc -l)"
if [ "$open_prs" -eq 0 ]; then
gh pr create \
--base main \
--head "$PR_BRANCH" \
--title "chore: update lockfiles" \
--fill
fi
fi
- name: Enable auto-merge
shell: bash
run: gh pr merge --auto --squash
env:
GH_TOKEN: ${{ secrets.MERGE_TOKEN }}

171
flake.lock generated
View file

@ -1,64 +1,5 @@
{ {
"nodes": { "nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1709336216,
"narHash": "sha256-Dt/wOWeW6Sqm11Yh+2+t0dfEWxoMxGBvv3JpIocFl9E=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "f7b3c975cf067e56e7cda6cb098ebe3fb4d74ca2",
"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"
}
},
"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": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1711715736, "lastModified": 1711715736,
@ -75,119 +16,9 @@
"type": "github" "type": "github"
} }
}, },
"pre-commit-hooks": {
"inputs": {
"flake-compat": [],
"flake-utils": "flake-utils",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1711850184,
"narHash": "sha256-rs5zMkTO+AlVBzgOaskAtY4zix7q3l8PpawfznHotcQ=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "9fc61b5eb0e50fc42f1d358f5240722907b79726",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"procfile-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1711158989,
"narHash": "sha256-exgncIe/lQIswv2L1M0y+RrHAg5dofLFCOxGu4/yJww=",
"owner": "getchoo",
"repo": "procfile-nix",
"rev": "6388308f9e9c8a8fbfdff54b30adf486fa292cf9",
"type": "github"
},
"original": {
"owner": "getchoo",
"repo": "procfile-nix",
"type": "github"
}
},
"root": { "root": {
"inputs": { "inputs": {
"flake-parts": "flake-parts", "nixpkgs": "nixpkgs"
"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": 1711851236,
"narHash": "sha256-EJ03x3N9ihhonAttkaCrqxb0djDq3URCuDpmVPbNZhA=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "f258266af947599e8069df1c2e933189270f143a",
"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": 1711803027,
"narHash": "sha256-Qic3OvsVLpetchzaIe2hJqgliWXACq2Oee6mBXa/IZQ=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "1810d51a015c1730f2fe05a255258649799df416",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
} }
} }
}, },

View file

@ -1,58 +1,31 @@
{ {
description = "Discord bot for Prism Launcher"; description = "Discord bot for Prism Launcher";
inputs = { inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
pre-commit-hooks = { outputs = {
url = "github:cachix/pre-commit-hooks.nix"; self,
inputs = { nixpkgs,
nixpkgs.follows = "nixpkgs"; ...
nixpkgs-stable.follows = "nixpkgs"; }: let
flake-compat.follows = ""; systems = [
}; "x86_64-linux"
}; "aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
procfile-nix = { forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system});
url = "github:getchoo/procfile-nix"; in {
inputs.nixpkgs.follows = "nixpkgs"; nixosModules.default = import ./nix/module.nix self;
};
rust-overlay = { packages = forAllSystems (pkgs: rec {
url = "github:oxalica/rust-overlay"; refraction = pkgs.callPackage ./nix/derivation.nix {inherit self;};
inputs = { default = refraction;
nixpkgs.follows = "nixpkgs"; });
flake-utils.follows = "pre-commit-hooks/flake-utils";
};
};
treefmt-nix = { overlays.default = _: prev: {
url = "github:numtide/treefmt-nix"; refraction = prev.callPackage ./nix/derivation.nix {inherit self;};
inputs.nixpkgs.follows = "nixpkgs";
}; };
}; };
outputs = {flake-parts, ...} @ inputs:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
./nix/dev.nix
./nix/packages.nix
./nix/deployment
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,69 +0,0 @@
{
perSystem = {
lib,
pkgs,
config,
self',
...
}: {
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 = [self'.packages.refraction];
RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
};
treefmt = {
projectRootFile = "flake.nix";
programs = {
alejandra.enable = true;
deadnix.enable = true;
prettier.enable = true;
rustfmt.enable = true;
};
settings.global = {
excludes = [
"./target"
"./flake.lock"
"./Cargo.lock"
];
};
};
pre-commit.settings.hooks = {
actionlint.enable = true;
nil.enable = true;
statix.enable = true;
treefmt = {
enable = true;
package = config.treefmt.build.wrapper;
};
};
procfiles.daemons.processes = {
redis = lib.getExe' pkgs.redis "redis-server";
};
};
}

11
nix/dev/args.nix Normal file
View file

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

View file

@ -1,14 +1,4 @@
{ {withSystem, ...}: {
flake-parts-lib,
withSystem,
...
}: {
imports = [./static.nix];
flake.nixosModules.default = flake-parts-lib.importApply ./module.nix {
inherit withSystem;
};
perSystem = { perSystem = {
lib, lib,
pkgs, pkgs,

212
nix/dev/flake.lock generated Normal file
View file

@ -0,0 +1,212 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1709336216,
"narHash": "sha256-Dt/wOWeW6Sqm11Yh+2+t0dfEWxoMxGBvv3JpIocFl9E=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "f7b3c975cf067e56e7cda6cb098ebe3fb4d74ca2",
"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",
"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": 1711715736,
"narHash": "sha256-9slQ609YqT9bT/MNX9+5k5jltL9zgpn36DpFB7TkttM=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "807c549feabce7eddbf259dbdcec9e0600a0660d",
"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": 1711850184,
"narHash": "sha256-rs5zMkTO+AlVBzgOaskAtY4zix7q3l8PpawfznHotcQ=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "9fc61b5eb0e50fc42f1d358f5240722907b79726",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"procfile-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1711158989,
"narHash": "sha256-exgncIe/lQIswv2L1M0y+RrHAg5dofLFCOxGu4/yJww=",
"owner": "getchoo",
"repo": "procfile-nix",
"rev": "6388308f9e9c8a8fbfdff54b30adf486fa292cf9",
"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": 1711851236,
"narHash": "sha256-EJ03x3N9ihhonAttkaCrqxb0djDq3URCuDpmVPbNZhA=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "f258266af947599e8069df1c2e933189270f143a",
"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": 1711803027,
"narHash": "sha256-Qic3OvsVLpetchzaIe2hJqgliWXACq2Oee6mBXa/IZQ=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "1810d51a015c1730f2fe05a255258649799df416",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

65
nix/dev/flake.nix Normal file
View file

@ -0,0 +1,65 @@
{
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";
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"
];
};
}

20
nix/dev/pre-commit.nix Normal file
View file

@ -0,0 +1,20 @@
{
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;
};
};
};
};
}

11
nix/dev/procfiles.nix Normal file
View file

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

36
nix/dev/shell.nix Normal file
View file

@ -0,0 +1,36 @@
{
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

@ -3,7 +3,7 @@
lib, lib,
pkgs, pkgs,
inputs', inputs',
self', refraction',
... ...
}: let }: let
targets = with pkgs.pkgsCross; { targets = with pkgs.pkgsCross; {
@ -26,7 +26,7 @@
targets; targets;
buildWith = rustPlatform: buildWith = rustPlatform:
self'.packages.refraction.override { refraction'.packages.refraction.override {
inherit rustPlatform; inherit rustPlatform;
optimizeSize = true; optimizeSize = true;
}; };

22
nix/dev/treefmt.nix Normal file
View file

@ -0,0 +1,22 @@
{
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"
];
};
};
};
}

View file

@ -1,4 +1,4 @@
{withSystem, ...}: { self: {
config, config,
lib, lib,
pkgs, pkgs,
@ -22,9 +22,7 @@
in { in {
options.services.refraction = { options.services.refraction = {
enable = mkEnableOption "refraction"; enable = mkEnableOption "refraction";
package = mkPackageOption ( package = mkPackageOption self.packages.${pkgs.stdenv.hostPlatform.system} "refraction" {};
withSystem pkgs.stdenv.hostPlatform.system ({self', ...}: self'.packages)
) "refraction" {};
user = mkOption { user = mkOption {
description = mdDoc '' description = mdDoc ''

View file

@ -1,16 +0,0 @@
{self, ...}: {
perSystem = {
pkgs,
self',
...
}: {
packages = {
refraction = pkgs.callPackage ./derivation.nix {inherit self;};
default = self'.packages.refraction;
};
};
flake.overlays.default = _: prev: {
refraction = prev.callPackage ./derivation.nix {inherit self;};
};
}