1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-08-16 22:31:03 +02:00
ironbar/flake.nix
74k1 5affad3400
refactor(nix): use flake-parts and flake-compat
- redefine `{default,shell}.nix` to derive from `flake.nix` (using
  `flake-compat`)
- use `flake-parts`' `_module.args.pkgs` machinery to apply overlays
  (instead of `pkgsFor`)
- extract `homeManagerModule` to `nix/module.nix`
- rename package at `nix/default.nix` to `nix/package.nix`

Co-authored-by: reo101 <pavel.atanasov2001@gmail.com>
2025-05-06 21:46:12 +02:00

139 lines
3.4 KiB
Nix

{
description = "Nix Flake for ironbar";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-compat.url = "github:edolstra/flake-compat";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
naersk.url = "github:nix-community/naersk";
};
outputs = inputs @ {
self,
nixpkgs,
rust-overlay,
crane,
naersk,
flake-parts,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} (let
mkRustToolchain = pkgs:
pkgs.rust-bin.stable.latest.default.override {
extensions = ["rust-src"];
};
in {
systems = [
"aarch64-linux"
"x86_64-linux"
];
imports = [
./nix/devshell.nix
];
perSystem = {
system,
config,
pkgs,
lib,
...
}: {
_module.args.pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlays.default
rust-overlay.overlays.default
];
};
# Packages
packages = {
ironbar = pkgs.ironbar;
default = pkgs.ironbar;
};
# Apps
apps = {
ironbar = {
type = "app";
program = lib.getExe pkgs.ironbar;
};
default = config.apps.ironbar;
};
};
flake = {
overlays.default = final: prev: let
inherit (nixpkgs) lib;
rust = mkRustToolchain final;
craneLib = (crane.mkLib final).overrideToolchain rust;
naersk' = prev.callPackage naersk {
cargo = rust;
rustc = rust;
};
rustPlatform = prev.makeRustPlatform {
cargo = rust;
rustc = rust;
};
props = builtins.fromTOML (builtins.readFile ./Cargo.toml);
mkDate = longDate: (lib.concatStringsSep "-" [
(builtins.substring 0 4 longDate)
(builtins.substring 4 2 longDate)
(builtins.substring 6 2 longDate)
]);
builder = "naersk";
in {
ironbar = let
version =
props.package.version
+ "+date="
+ (mkDate (self.lastModifiedDate or "19700101"))
+ "_"
+ (self.shortRev or "dirty");
in
if builder == "crane"
then
prev.callPackage ./nix/package.nix {
inherit version;
inherit rustPlatform;
builderName = builder;
builder = craneLib;
}
else if builder == "naersk"
then
prev.callPackage ./nix/package.nix {
inherit version;
inherit rustPlatform;
builderName = builder;
builder = naersk';
}
else
prev.callPackage ./nix/package.nix {
inherit version;
inherit rustPlatform;
builderName = builder;
};
};
homeManagerModules.default = import ./nix/module.nix self;
};
});
nixConfig = {
extra-substituters = ["https://cache.garnix.io"];
extra-trusted-public-keys = ["cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g="];
};
}