flake: use flake-parts (#1208)

Link: https://github.com/danth/stylix/pull/1208

Reviewed-by: Matt Sturgeon <matt@sturgeon.me.uk>
Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
This commit is contained in:
awwpotato 2025-05-16 11:52:15 -07:00 committed by GitHub
parent 49b1eb9371
commit 8b015b5fa0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 273 additions and 241 deletions

View file

@ -31,7 +31,7 @@ jobs:
with:
token: ${{ steps.generate-token.outputs.token }}
branch: update_flake_lock_action_${{ matrix.branch }}
commit-msg: "stylix: update all flake inputs"
commit-msg: "flake: update all inputs"
pr-title: "${{ startsWith(matrix.branch, 'release') && format('[{0}] ', matrix.branch) || '' }}stylix: update all flake inputs" # yamllint disable-line rule:line-length
pr-labels: dependencies
# yamllint disable rule:line-length

View file

@ -11,13 +11,14 @@ To keep things consistent, commit messages should follow a format
Where the scope is one of:
| Scope | Purpose |
|----------------|------------------------------------------------------------------------|
| `ci` | Changes to GitHub Actions workflows. |
| `doc` | Changes to the website, `README.md`, and so on. |
| `stylix` | Changes in the `stylix` directory, `flake.nix`, and other global code. |
| Name of target | Changes to code for a particular target. |
| `treewide` | Changes across many targets. |
| Scope | Purpose |
|----------------|------------------------------------------------------------------|
| `ci` | Changes to GitHub Actions workflows. |
| `doc` | Changes to the website, `README.md`, and so on. |
| `flake` | Changes in the `flake` directory, `flake.nix`, and `flake.lock`. |
| `stylix` | Changes in the `stylix` directory and other global code. |
| Name of target | Changes to code for a particular target. |
| `treewide` | Changes across many targets. |
The scope is meant to indicate which area of the code was changed. Specifying
the type of change, such as `feat` or `fix`, is not necessary. Dependency

27
flake.lock generated
View file

@ -101,7 +101,6 @@
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
"nur",
"nixpkgs"
]
},
@ -119,26 +118,6 @@
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": [
"systems"
]
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"fromYaml": {
"flake": false,
"locked": {
@ -255,7 +234,9 @@
},
"nur": {
"inputs": {
"flake-parts": "flake-parts",
"flake-parts": [
"flake-parts"
],
"nixpkgs": [
"nixpkgs"
],
@ -283,7 +264,7 @@
"base16-vim": "base16-vim",
"firefox-gnome-theme": "firefox-gnome-theme",
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"flake-parts": "flake-parts",
"git-hooks": "git-hooks",
"gnome-shell": "gnome-shell",
"home-manager": "home-manager",

222
flake.nix
View file

@ -4,9 +4,9 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils = {
url = "github:numtide/flake-utils";
inputs.systems.follows = "systems";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
systems.url = "github:nix-systems/default";
@ -67,7 +67,10 @@
nur = {
url = "github:nix-community/NUR";
inputs.nixpkgs.follows = "nixpkgs";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-parts.follows = "flake-parts";
};
};
tinted-foot = {
@ -112,211 +115,10 @@
};
outputs =
{
nixpkgs,
base16,
self,
...
}@inputs:
inputs.flake-utils.lib.eachDefaultSystem (
system:
let
inherit (nixpkgs) lib;
pkgs = nixpkgs.legacyPackages.${system};
in
{
checks = lib.attrsets.unionOfDisjoint {
git-hooks = inputs.git-hooks.lib.${system}.run {
hooks = {
deadnix.enable = true;
editorconfig-checker.enable = true;
hlint.enable = true;
{ flake-parts, systems, ... }@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ ./flake ];
treefmt = {
enable = true;
package = self.formatter.${system};
};
statix.enable = true;
typos = {
enable = true;
settings.configuration = ''
[default.extend-identifiers]
MrSom3body="MrSom3body"
'';
};
yamllint.enable = true;
};
src = ./.;
};
} self.packages.${system};
devShells = {
default =
let
check = pkgs.writeShellApplication {
name = "stylix-check";
runtimeInputs = with pkgs; [
nix
nix-fast-build
];
text = ''
cores="$(nproc)"
system="$(nix eval --expr builtins.currentSystem --impure --raw)"
nix-fast-build \
--eval-max-memory-size 512 \
--eval-workers "$cores" \
--flake ".#checks.$system" \
--no-link \
--skip-cached \
"$@"
'';
};
in
pkgs.mkShell {
inherit (self.checks.${system}.git-hooks) shellHook;
packages = [
check
inputs.home-manager.packages.${system}.default
self.checks.${system}.git-hooks.enabledPackages
self.formatter.${system}
] ++ self.formatter.${system}.runtimeInputs;
};
ghc = pkgs.mkShell {
inputsFrom = [ self.devShells.${system}.default ];
packages = [ pkgs.ghc ];
};
};
formatter = pkgs.treefmt.withConfig {
runtimeInputs = with pkgs; [
nixfmt-rfc-style
stylish-haskell
keep-sorted
];
settings = {
on-unmatched = "info";
tree-root-file = "flake.nix";
formatter = {
stylish-haskell = {
command = "stylish-haskell";
includes = [ "*.hx" ];
};
nixfmt = {
command = "nixfmt";
options = [ "--width=80" ];
includes = [ "*.nix" ];
};
keep-sorted = {
command = "keep-sorted";
includes = [ "*" ];
};
};
};
};
packages =
let
universalPackages = {
docs = import ./docs { inherit pkgs inputs lib; };
palette-generator = pkgs.callPackage ./palette-generator { };
};
# Testbeds are virtual machines based on NixOS, therefore they are
# only available for Linux systems.
testbedPackages = lib.optionalAttrs (lib.hasSuffix "-linux" system) (
import ./stylix/testbed.nix { inherit pkgs inputs lib; }
);
# Discord is not available on arm64. This workaround filters out
# testbeds using that package, until we have a better way to handle
# this.
testbedPackages' =
if system == "aarch64-linux" then
lib.filterAttrs (
name: _: !lib.hasPrefix "testbed:discord:vencord" name
) testbedPackages
else
testbedPackages;
in
universalPackages // testbedPackages';
}
)
// {
nixosModules.stylix =
{ pkgs, ... }@args:
{
imports = [
(import ./stylix/nixos inputs)
{
stylix = {
inherit inputs;
paletteGenerator =
self.packages.${pkgs.stdenv.hostPlatform.system}.palette-generator;
base16 = base16.lib args;
homeManagerIntegration.module = self.homeModules.stylix;
};
}
];
};
homeModules.stylix =
{ pkgs, ... }@args:
{
imports = [
(import ./stylix/hm inputs)
{
stylix = {
inherit inputs;
paletteGenerator =
self.packages.${pkgs.stdenv.hostPlatform.system}.palette-generator;
base16 = base16.lib args;
};
}
];
};
darwinModules.stylix =
{ pkgs, ... }@args:
{
imports = [
(import ./stylix/darwin inputs)
{
stylix = {
inherit inputs;
paletteGenerator =
self.packages.${pkgs.stdenv.hostPlatform.system}.palette-generator;
base16 = base16.lib args;
homeManagerIntegration.module = self.homeModules.stylix;
};
}
];
};
nixOnDroidModules.stylix =
{ pkgs, ... }@args:
{
imports = [
(import ./stylix/droid inputs)
{
stylix = {
paletteGenerator =
self.packages.${pkgs.stdenv.hostPlatform.system}.palette-generator;
base16 = base16.lib args;
homeManagerIntegration.module = self.homeModules.stylix;
};
}
];
};
}
//
# Drop this alias after 25.11
nixpkgs.lib.optionalAttrs (!nixpkgs.lib.oldestSupportedReleaseIsAtLeast 2511) {
homeManagerModules = builtins.warn "stylix: flake output `homeManagerModules` has been renamed to `homeModules`" self.homeModules;
};
systems = import systems;
};
}

43
flake/default.nix Normal file
View file

@ -0,0 +1,43 @@
{
imports = [
./dev-shell.nix
./modules.nix
./packages.nix
./pre-commit.nix
];
perSystem =
{ pkgs, ... }:
{
# TODO: consider using https://flake.parts/options/treefmt-nix.html once
# dev flake is partitioned
formatter = pkgs.treefmt.withConfig {
runtimeInputs = with pkgs; [
nixfmt-rfc-style
stylish-haskell
keep-sorted
];
settings = {
on-unmatched = "info";
tree-root-file = "flake.nix";
formatter = {
stylish-haskell = {
command = "stylish-haskell";
includes = [ "*.hx" ];
};
nixfmt = {
command = "nixfmt";
options = [ "--width=80" ];
includes = [ "*.nix" ];
};
keep-sorted = {
command = "keep-sorted";
includes = [ "*" ];
};
};
};
};
};
}

51
flake/dev-shell.nix Normal file
View file

@ -0,0 +1,51 @@
{
perSystem =
{
pkgs,
config,
inputs',
...
}:
let
stylix-check = pkgs.writeShellApplication {
name = "stylix-check";
runtimeInputs = with pkgs; [
nix
nix-fast-build
];
text = ''
cores="$(nproc)"
system="$(nix eval --expr builtins.currentSystem --impure --raw)"
nix-fast-build \
--eval-max-memory-size 512 \
--eval-workers "$cores" \
--flake ".#checks.$system" \
--no-link \
--skip-cached \
"$@"
'';
};
in
{
devShells = {
default = pkgs.mkShell {
# Install git-hooks when activating the shell
shellHook = config.pre-commit.installationScript;
packages =
[
stylix-check
inputs'.home-manager.packages.default
config.formatter
]
++ config.pre-commit.settings.enabledPackages
++ config.formatter.runtimeInputs;
};
ghc = pkgs.mkShell {
inputsFrom = [ config.devShells.default ];
packages = [ pkgs.ghc ];
};
};
};
}

80
flake/modules.nix Normal file
View file

@ -0,0 +1,80 @@
{
inputs,
self,
lib,
...
}:
{
flake = {
nixosModules.stylix =
{ pkgs, ... }@args:
{
imports = [
(import "${self}/stylix/nixos" inputs)
{
stylix = {
inherit inputs;
paletteGenerator =
self.packages.${pkgs.stdenv.hostPlatform.system}.palette-generator;
base16 = inputs.base16.lib args;
homeManagerIntegration.module = self.homeModules.stylix;
};
}
];
};
# Drop this alias after 26.05
homeManagerModules = lib.mkIf (lib.oldestSupportedReleaseIsAtLeast 2511) (
builtins.warn "stylix: flake output `homeManagerModules` has been renamed to `homeModules`" self.homeModules
);
homeModules.stylix =
{ pkgs, ... }@args:
{
imports = [
(import "${self}/stylix/hm" inputs)
{
stylix = {
inherit inputs;
paletteGenerator =
self.packages.${pkgs.stdenv.hostPlatform.system}.palette-generator;
base16 = inputs.base16.lib args;
};
}
];
};
darwinModules.stylix =
{ pkgs, ... }@args:
{
imports = [
(import "${self}/stylix/darwin" inputs)
{
stylix = {
inherit inputs;
paletteGenerator =
self.packages.${pkgs.stdenv.hostPlatform.system}.palette-generator;
base16 = inputs.base16.lib args;
homeManagerIntegration.module = self.homeModules.stylix;
};
}
];
};
nixOnDroidModules.stylix =
{ pkgs, ... }@args:
{
imports = [
(import "${self}/stylix/droid" inputs)
{
stylix = {
paletteGenerator =
self.packages.${pkgs.stdenv.hostPlatform.system}.palette-generator;
base16 = inputs.base16.lib args;
homeManagerIntegration.module = self.homeModules.stylix;
};
}
];
};
};
}

39
flake/packages.nix Normal file
View file

@ -0,0 +1,39 @@
{
lib,
inputs,
self,
...
}:
{
perSystem =
{ pkgs, system, ... }:
{
packages =
let
# Testbeds are virtual machines based on NixOS, therefore they are
# only available for Linux systems.
testbedPackages = lib.mkIf (lib.hasSuffix "-linux" system) (
import "${self}/stylix/testbed.nix" { inherit pkgs inputs lib; }
);
# Discord is not available on arm64. This workaround filters out
# testbeds using that package, until we have a better way to handle
# this.
testbedPackages' =
if system == "aarch64-linux" then
lib.filterAttrs (
name: _: !lib.hasPrefix "testbed:discord:vencord" name
) testbedPackages
else
testbedPackages;
in
lib.mkMerge [
testbedPackages'
{
docs = import "${self}/docs" { inherit pkgs inputs lib; };
palette-generator = pkgs.callPackage "${self}/palette-generator" { };
}
];
};
}

35
flake/pre-commit.nix Normal file
View file

@ -0,0 +1,35 @@
{ inputs, ... }:
{
imports = [
inputs.git-hooks.flakeModule
];
perSystem =
{ config, ... }:
{
pre-commit = {
check.enable = true;
settings.hooks = {
deadnix.enable = true;
editorconfig-checker.enable = true;
hlint.enable = true;
treefmt = {
enable = true;
package = config.formatter;
};
statix.enable = true;
typos = {
enable = true;
settings.configuration = ''
[default.extend-identifiers]
MrSom3body="MrSom3body"
'';
};
yamllint.enable = true;
};
};
};
}