Skip to content

Commit

Permalink
🎨 Run treefmt with the updated inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
a-kenji committed Jul 18, 2024
1 parent a76e0a8 commit 620c71b
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 100 deletions.
5 changes: 2 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
commit-message:
prefix: ⬆️
prefix: "⬆️ "
schedule:
interval: "monthly"

- package-ecosystem: "cargo"
directory: "/"
commit-message:
prefix: ⬆️
prefix: "⬆️ "
schedule:
interval: "monthly"
34 changes: 16 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
name: "ci"

on:
workflow_dispatch: # allows manual triggering
pull_request:
branches: [ main ]
branches: [main]
paths-ignore:
- '**.md'
push:
branches: [ main ]
branches: [main]
paths-ignore:
- '**.md'
merge_group:

jobs:
flake-check:
runs-on: ubuntu-latest
environment: cachix
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Nix Flakes doesn't work on shallow clones
- uses: cachix/install-nix-action@V27
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v15
with:
name: friedow
# If you chose API tokens for write access OR if you have a private cache
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: "flake check"
run: nix flake check -Lvv --no-update-lock-file
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Nix Flakes doesn't work on shallow clones
- uses: cachix/install-nix-action@V27
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v15
with:
name: friedow
# If you chose API tokens for write access OR if you have a private cache
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: "flake check"
run: nix flake check -Lvv --no-update-lock-file
161 changes: 99 additions & 62 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

nixConfig = {
extra-substituters = [ "https://friedow.cachix.org" ];
extra-trusted-public-keys =
[ "friedow.cachix.org-1:JDEaYMqNgGu+bVPOca7Zu4Cp8QDMkvQpArKuwPKa29A=" ];
extra-trusted-public-keys = [ "friedow.cachix.org-1:JDEaYMqNgGu+bVPOca7Zu4Cp8QDMkvQpArKuwPKa29A=" ];
};

inputs = {
Expand All @@ -17,12 +16,24 @@
};
};

outputs = { self, nixpkgs, crane, treefmt-nix, home-manager, ... }:
outputs =
{
self,
nixpkgs,
crane,
treefmt-nix,
home-manager,
...
}:
let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };

devInputs = with pkgs; [ rustc rustfmt cargo ];
devInputs = with pkgs; [
rustc
rustfmt
cargo
];

nativeBuildInputs = with pkgs; [
makeWrapper
Expand All @@ -42,24 +53,32 @@
craneLib = crane.lib.${system};
fontFilter = path: _type: builtins.match ".*ttf$" path != null;
configFilter = path: _type: builtins.match ".*config.yml$" path != null;
assetOrCargo = path: type:
(configFilter path type) || (fontFilter path type)
|| (craneLib.filterCargoSources path type);
assetOrCargo =
path: type:
(configFilter path type) || (fontFilter path type) || (craneLib.filterCargoSources path type);
commonArgs = {
src = pkgs.lib.cleanSourceWith {
src = craneLib.path ./.;
filter = assetOrCargo;
};
inherit pname version buildInputs nativeBuildInputs;
inherit
pname
version
buildInputs
nativeBuildInputs
;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
cargoClippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets --all-features";
});
cargoClippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets --all-features";
}
);
GIT_DATE = "${builtins.substring 0 4 self.lastModifiedDate}-${
builtins.substring 4 2 self.lastModifiedDate
}-${builtins.substring 6 2 self.lastModifiedDate}";
builtins.substring 4 2 self.lastModifiedDate
}-${builtins.substring 6 2 self.lastModifiedDate}";
GIT_REV = self.shortRev or "Not committed yet.";
treefmt = (treefmt-nix.lib.evalModule pkgs ./formatter.nix).config.build;
libPath = pkgs.lib.makeLibraryPath [
Expand All @@ -69,68 +88,86 @@
pkgs.libGL
];

in {
in
{
devShells.${system}.default = pkgs.mkShell {
inherit nativeBuildInputs buildInputs GIT_DATE GIT_REV;
inherit
nativeBuildInputs
buildInputs
GIT_DATE
GIT_REV
;
packages = devInputs ++ [ treefmt.wrapper ];
LD_LIBRARY_PATH = libPath;
};
packages.${system} = {
default = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts nativeBuildInputs buildInputs pname GIT_REV
GIT_DATE;
postFixup = pkgs.lib.optional pkgs.stdenv.isLinux ''
rpath=$(patchelf --print-rpath $out/bin/${pname})
patchelf --set-rpath "$rpath:${libPath}" $out/bin/${pname}
'';
default = craneLib.buildPackage (
commonArgs
// {
inherit
cargoArtifacts
nativeBuildInputs
buildInputs
pname
GIT_REV
GIT_DATE
;
postFixup = pkgs.lib.optional pkgs.stdenv.isLinux ''
rpath=$(patchelf --print-rpath $out/bin/${pname})
patchelf --set-rpath "$rpath:${libPath}" $out/bin/${pname}
'';

meta = with pkgs.lib; {
description = "Your trusty omnibox search.";
homepage = "https://github.com/friedow/centerpiece";
platforms = platforms.linux;
license = licenses.mit;
mainProgram = pname;
maintainers = [ "friedow" ];
};
});
index-git-repositories = craneLib.buildPackage (commonArgs // rec {
inherit cargoArtifacts;
pname = "index-git-repositories";
cargoExtraArgs = "-p ${pname}";
meta.mainProgram = pname;
});
meta = with pkgs.lib; {
description = "Your trusty omnibox search.";
homepage = "https://github.com/friedow/centerpiece";
platforms = platforms.linux;
license = licenses.mit;
mainProgram = pname;
maintainers = [ "friedow" ];
};
}
);
index-git-repositories = craneLib.buildPackage (
commonArgs
// rec {
inherit cargoArtifacts;
pname = "index-git-repositories";
cargoExtraArgs = "-p ${pname}";
meta.mainProgram = pname;
}
);
};
checks.${system} = {
inherit (self.outputs.packages.${system})
default index-git-repositories;
inherit (self.outputs.packages.${system}) default index-git-repositories;
shell = self.outputs.devShells.${system}.default;
treefmt = treefmt.check self;
inherit cargoClippy;
hmModule = (nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
home-manager.nixosModules.home-manager
{
home-manager.users.alice = {
imports = [ self.outputs.hmModules."x86_64-linux".default ];
programs.centerpiece = {
enable = true;
config.plugin.git_repositories.commands = [ [ "alacritty" ] ];
services.index-git-repositories = {
hmModule =
(nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
home-manager.nixosModules.home-manager
{
home-manager.users.alice = {
imports = [ self.outputs.hmModules."x86_64-linux".default ];
programs.centerpiece = {
enable = true;
interval = "3hours";
config.plugin.git_repositories.commands = [ [ "alacritty" ] ];
services.index-git-repositories = {
enable = true;
interval = "3hours";
};
};
home.stateVersion = "23.11";
};
users.users.alice = {
isNormalUser = true;
uid = 1000;
home = "/home/alice";
};
home.stateVersion = "23.11";
};
users.users.alice = {
isNormalUser = true;
uid = 1000;
home = "/home/alice";
};
}
];
}).config.system.build.vm;
}
];
}).config.system.build.vm;
};
hmModules.${system}.default = import ./home-manager-module.nix {
centerpiece = self.outputs.packages.${system}.default;
Expand Down
64 changes: 47 additions & 17 deletions home-manager-module.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{ index-git-repositories, centerpiece }:
{ lib, pkgs, config, ... }:
{
lib,
pkgs,
config,
...
}:
let
cfg = config.programs.centerpiece;
git-index-name = "index-git-repositories";
in {
in
{
options.programs.centerpiece = {
enable = lib.mkEnableOption (lib.mdDoc "Centerpiece");

Expand Down Expand Up @@ -77,8 +83,17 @@ in {
};
commands = lib.mkOption {
default = [
[ "alacritty" "--command" "nvim" "$GIT_DIRECTORY" ]
[ "alacritty" "--working-directory" "$GIT_DIRECTORY" ]
[
"alacritty"
"--command"
"nvim"
"$GIT_DIRECTORY"
]
[
"alacritty"
"--working-directory"
"$GIT_DIRECTORY"
]
];
type = lib.types.listOf (lib.types.listOf lib.types.str);
description = lib.mdDoc ''
Expand All @@ -87,9 +102,23 @@ in {
Use the $GIT_DIRECTORY_NAME variable to pass in the selected directory name.
'';
example = [
[ "code" "--new-window" "$GIT_DIRECTORY" ]
[ "alacritty" "--command" "lazygit" "--path" "$GIT_DIRECTORY" ]
[ "alacritty" "--working-directory" "$GIT_DIRECTORY" ]
[
"code"
"--new-window"
"$GIT_DIRECTORY"
]
[
"alacritty"
"--command"
"lazygit"
"--path"
"$GIT_DIRECTORY"
]
[
"alacritty"
"--working-directory"
"$GIT_DIRECTORY"
]
];
};
};
Expand Down Expand Up @@ -163,8 +192,7 @@ in {
enable = lib.mkOption {
default = true;
type = lib.types.bool;
description =
lib.mdDoc "Enable / disable the git repositories indexer service.";
description = lib.mdDoc "Enable / disable the git repositories indexer service.";
};
interval = lib.mkOption {
default = "5min";
Expand All @@ -184,8 +212,7 @@ in {
(lib.mkIf cfg.enable { home.packages = [ centerpiece ]; })

(lib.mkIf cfg.enable {
home.file.".config/centerpiece/config.yml".text =
lib.generators.toYAML { } cfg.config;
home.file.".config/centerpiece/config.yml".text = lib.generators.toYAML { } cfg.config;
})

(lib.mkIf cfg.services.index-git-repositories.enable {
Expand All @@ -198,18 +225,21 @@ in {
};

Service = {
ExecStart = "${pkgs.writeShellScript
"${git-index-name}-service-ExecStart" ''
exec ${lib.getExe index-git-repositories}
''}";
ExecStart = "${pkgs.writeShellScript "${git-index-name}-service-ExecStart" ''
exec ${lib.getExe index-git-repositories}
''}";
Type = "oneshot";
};
};
};
timers = {
index-git-repositories-timer = {
Unit = { Description = "Activate the git repository indexer"; };
Install = { WantedBy = [ "timers.target" ]; };
Unit = {
Description = "Activate the git repository indexer";
};
Install = {
WantedBy = [ "timers.target" ];
};
Timer = {
OnUnitActiveSec = cfg.services.index-git-repositories.interval;
OnBootSec = "0min";
Expand Down

0 comments on commit 620c71b

Please sign in to comment.