diff --git a/flake.lock b/flake.lock index ea3ff68..209dad7 100644 --- a/flake.lock +++ b/flake.lock @@ -15,6 +15,24 @@ "type": "github" } }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1749398372, + "narHash": "sha256-tYBdgS56eXYaWVW3fsnPQ/nFlgWi/Z2Ymhyu21zVM98=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9305fe4e5c2a6fcf5ba6a3ff155720fbe4076569", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, "home-manager": { "inputs": { "nixpkgs": "nixpkgs" @@ -49,6 +67,21 @@ "type": "github" } }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1748740939, + "narHash": "sha256-rQaysilft1aVMwF14xIdGS3sj1yHlI6oKQNBRTF40cc=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "656a64127e9d791a334452c6b6606d17539476e2", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, "nixpkgs_2": { "locked": { "lastModified": 1743076231, @@ -84,6 +117,7 @@ "root": { "inputs": { "crane": "crane", + "flake-parts": "flake-parts", "home-manager": "home-manager", "nixpkgs": "nixpkgs_2", "treefmt-nix": "treefmt-nix" diff --git a/flake.nix b/flake.nix index ddce9a5..3ca0f21 100644 --- a/flake.nix +++ b/flake.nix @@ -11,166 +11,175 @@ home-manager.url = "github:nix-community/home-manager"; treefmt-nix.url = "github:numtide/treefmt-nix/"; crane.url = "github:ipetkov/crane"; + flake-parts.url = "github:hercules-ci/flake-parts"; }; outputs = - { + inputs @ { self, nixpkgs, crane, treefmt-nix, home-manager, + flake-parts, ... }: let - system = "x86_64-linux"; - pkgs = import nixpkgs { inherit system; }; - - devInputs = with pkgs; [ - rustc - rustfmt - cargo - clippy - ]; + systems = [ "x86_64-linux" "aarch64-linux" ]; + in + (flake-parts.lib.mkFlake { inherit inputs; } { + inherit systems; + perSystem = { pkgs, system, ... } : + let + devInputs = with pkgs; [ + rustc + rustfmt + cargo + clippy + ]; - nativeBuildInputs = with pkgs; [ - makeWrapper - # wifi plugin - # cargo networkmanager dependency - pkgconf - dbus - ]; + nativeBuildInputs = with pkgs; [ + makeWrapper + # wifi plugin + # cargo networkmanager dependency + pkgconf + dbus + ]; - buildInputs = with pkgs; [ dbus ]; + buildInputs = with pkgs; [ dbus ]; - cargoTOML = builtins.fromTOML (builtins.readFile (./. + "/Cargo.toml")); + cargoTOML = builtins.fromTOML (builtins.readFile (./. + "/Cargo.toml")); - inherit (cargoTOML.workspace.package) version; - pname = "centerpiece"; + 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 - ]; + 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 - // { + in + { + devShells.default = pkgs.mkShell { inherit - cargoArtifacts nativeBuildInputs buildInputs - pname - GIT_REV GIT_DATE + GIT_REV ; - postFixup = pkgs.lib.optional pkgs.stdenv.isLinux '' - rpath=$(patchelf --print-rpath $out/bin/${pname}) - patchelf --set-rpath "$rpath:${libPath}" $out/bin/${pname} - ''; + packages = devInputs ++ [ treefmt.wrapper ]; + LD_LIBRARY_PATH = libPath; + }; + packages = { + 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"; + 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" ]; }; } - ]; - }).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; + ); + index-git-repositories = craneLib.buildPackage ( + commonArgs + // rec { + inherit cargoArtifacts; + pname = "index-git-repositories"; + cargoExtraArgs = "-p ${pname}"; + meta.mainProgram = pname; + } + ); + }; + checks = { + 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 { + inherit system; + modules = [ + home-manager.nixosModules.home-manager + { + home-manager.users.alice = { + imports = [ self.outputs.hmModules.${system}.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; + }; + formatter = treefmt.wrapper; + }; + }) // { + hmModules = (nixpkgs.lib.attrsets.genAttrs systems (system: { + default = import ./home-manager-module.nix { + centerpiece = self.outputs.packages.${system}.default; + inherit (self.outputs.packages.${system}) index-git-repositories; + }; + })); }; }