~toastal/klossi

~toastal/klossi/flake.nix
 ..
0 # SPDX-FileCopyrightText: 2021–2024 toastal <toastal@posteo.net>
1 # SPDX-License-Identifier: MPL-2.0
2
3 {
4 description = "A very basic flake";
5
6 inputs = {
7 nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
8 };
9
10 outputs =
11 { self, nixpkgs, ... }@inputs:
12 let
13 supportedSystems = [
14 "aarch64-linux"
15 "x86_64-linux"
16 ];
17
18 nixpkgsFor = nixpkgs.lib.genAttrs supportedSystems (
19 system:
20 import nixpkgs {
21 inherit system;
22 overlays = [
23 self.overlays.default
24 self.overlays.tools
25 ];
26 }
27 );
28
29 forAllSystems =
30 fn:
31 nixpkgs.lib.genAttrs supportedSystems (
32 system:
33 fn rec {
34 inherit system;
35 pkgs = nixpkgsFor.${system};
36 inherit (pkgs) lib;
37 fs = lib.fileset;
38 }
39 );
40 in
41 {
42 overlays = {
43 default = final: prev: { leafpeep = self.packages.${prev.system}.leafpeep; };
44 tools = final: prev: {
45 nixfmt-3-space = prev.nixfmt-rfc-style.overrideAttrs (
46 finalAttrs: prevAttrs: {
47 name = "nixfmt-3-space";
48 patches = (prev.patches or [ ]) ++ [
49 (final.fetchpatch {
50 url = "https://codeberg.org/toastal/nixfmt/commit/8217f229e04b9ce68fcc5018fce650ca58525db9.patch";
51 hash = "sha256-N8O23sOI/jen7hXND+JgQlyOImI0happ7AUAaxic93k=";
52 })
53 (final.fetchpatch {
54 url = "https://codeberg.org/toastal/nixfmt/commit/4b15a8a67fd6f1cfc0df61ced9df9f14e7413b90.patch";
55 hash = "sha256-G8kYM6ojvWkwG+WguiNWwc7C3r8bPOAkfuCFXCLEj6o=";
56 })
57 ];
58 }
59 );
60 };
61 };
62
63 packages = forAllSystems (
64 {
65 system,
66 pkgs,
67 lib,
68 fs,
69 ...
70 }:
71 {
72 default = self.packages.${system}.klossi;
73
74 klossi = pkgs.stdenv.mkDerivation (finalAttrs: {
75 name = "klossi";
76 version = "0.0.0";
77
78 src = fs.toSource {
79 root = ./.;
80 fileset = fs.unions [
81 ./Makefile
82 ./bin
83 ./lib
84 ];
85 };
86
87 buildInputs = with pkgs; [ ncurses ];
88
89 nativeBuildInputs = with pkgs; [ ats2 ];
90
91 CFLAGS = "-O2 -flto";
92
93 installPhase = ''
94 make PREFIX=$out install
95 '';
96
97 meta = {
98 license = lib.licenses.mpl20;
99 mainProgram = "klossi";
100 };
101 });
102 }
103 );
104
105 devShells = forAllSystems (
106 { system, pkgs, ... }:
107 {
108 default = self.devShells.${system}.klossi;
109
110 klossi = pkgs.mkShell {
111 inputsFrom = builtins.attrValues self.packages.${system};
112 name = "klossi";
113 nativeBuildInputs = with pkgs; [
114 ats2
115 nixfmt-3-space
116 ];
117 env = {
118 LD_LIBRARY_PATH = "${pkgs.ncurses}/lib";
119 };
120 };
121 }
122 );
123
124 formatter = forAllSystems ({ pkgs, ... }: pkgs.nixfmt-3-space);
125 };
126 }