Skip to content

Commit

Permalink
➕ move to flake-parts
Browse files Browse the repository at this point in the history
  • Loading branch information
a-kenji committed Oct 15, 2024
1 parent eb9f84f commit 5bb4852
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 172 deletions.
31 changes: 31 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

162 changes: 2 additions & 160 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
home-manager.url = "github:nix-community/home-manager";
treefmt-nix.url = "github:numtide/treefmt-nix/";
crane = {
Expand All @@ -16,164 +17,5 @@
};
};

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

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

nativeBuildInputs = with pkgs; [
makeWrapper
# wifi plugin
# cargo networkmanager dependency
pkgconf
dbus
];

buildInputs = with pkgs; [ dbus ];

cargoTOML = builtins.fromTOML (builtins.readFile (./. + "/Cargo.toml"));

inherit (cargoTOML.workspace.package) version;
pname = "centerpiece";

craneLib = crane.mkLib nixpkgs.legacyPackages.${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);
commonArgs = {
src = pkgs.lib.cleanSourceWith {
src = craneLib.path ./.;
filter = assetOrCargo;
};
inherit
pname
version
buildInputs
nativeBuildInputs
;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
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}";
GIT_REV = self.shortRev or "Not committed yet.";
treefmt = (treefmt-nix.lib.evalModule pkgs ./formatter.nix).config.build;
libPath = pkgs.lib.makeLibraryPath [
pkgs.wayland
pkgs.libxkbcommon
pkgs.vulkan-loader
pkgs.libGL
];

in
{
devShells.${system}.default = pkgs.mkShell {
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}
'';

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;
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 = {
enable = true;
interval = "3hours";
};
};
home.stateVersion = "23.11";
};
users.users.alice = {
isNormalUser = true;
uid = 1000;
home = "/home/alice";
};
}
];
}).config.system.build.vm;
};
hmModules.${system}.default = import ./home-manager-module.nix {
centerpiece = self.outputs.packages.${system}.default;
inherit (self.outputs.packages.${system}) index-git-repositories;
};
formatter.${system} = treefmt.wrapper;
};
outputs = args: import ./nix args;
}
12 changes: 0 additions & 12 deletions formatter.nix

This file was deleted.

16 changes: 16 additions & 0 deletions nix/checks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ self, ... }:
{
perSystem =
{ pkgs, ... }:
{
checks = {
inherit ((pkgs.callPackage ./crane.nix { inherit self; }))
centerpiece
index-git-repositories
cargoArtifacts
cargoClippy
cargoTest
;
};
};
}
83 changes: 83 additions & 0 deletions nix/crane.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
self,
lib,
pkgs,
makeWrapper,
pkgconf,
dbus,
}:
let
cargoTOML = builtins.fromTOML (builtins.readFile (self + "/Cargo.toml"));
inherit (cargoTOML.workspace.package) version;
pname = "centerpiece";
meta = import ./meta.nix { inherit lib; };
craneLib = self.inputs.crane.mkLib pkgs;
commonArgs = {
nativeBuildInputs = [
makeWrapper
# wifi plugin
# cargo networkmanager dependency
pkgconf
dbus
];
buildInputs = [ dbus ];
inherit
meta
version
pname
;
src =
let
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);
in
lib.cleanSourceWith {
src = craneLib.path ../.;
filter = assetOrCargo;
};
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
cargoClippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets --all-features";
}
);
cargoTest = craneLib.cargoNextest (commonArgs // { inherit cargoArtifacts; });
in
{
centerpiece = craneLib.buildPackage (
commonArgs
// {
env = import ./env.nix { inherit self; };
postFixup = pkgs.lib.optional pkgs.stdenv.isLinux ''
rpath=$(patchelf --print-rpath $out/bin/${pname})
patchelf --set-rpath "$rpath:${pkgs.callPackage ./lib.nix { }}" $out/bin/${pname}
'';
doCheck = false;
inherit
cargoArtifacts
;
}
);
index-git-repositories = craneLib.buildPackage (
commonArgs
// {
cargoExtraArgs = "-p index-git-repositories";
pname = "index-git-repositories";
doCheck = false;
inherit
cargoArtifacts
;
}
);
inherit
cargoClippy
cargoArtifacts
cargoTest
;
}
15 changes: 15 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ flake-parts, ... }@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
];

imports = [
./devshells.nix
./formatter.nix
./packages.nix
./checks.nix
];

}
19 changes: 19 additions & 0 deletions nix/devshells.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{ self, ... }:
{
perSystem =
{ pkgs, self', ... }:
{
devShells = {
default = pkgs.mkShellNoCC {
name = "centerpiece";
inputsFrom = [ self'.packages.default ];
packages = [
pkgs.clippy
self'.formatter.outPath
];
env = import ./env.nix { inherit self; };
LD_LIBRARY_PATH = pkgs.callPackage ./lib.nix { };
};
};
};
}
7 changes: 7 additions & 0 deletions nix/env.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ self, ... }:
{
GIT_DATE = "${builtins.substring 0 4 self.lastModifiedDate}-${
builtins.substring 4 2 self.lastModifiedDate
}-${builtins.substring 6 2 self.lastModifiedDate}";
GIT_REV = self.shortRev or self.dirtyShortRev;
}
Loading

0 comments on commit 5bb4852

Please sign in to comment.