chore: reorganize flake

This commit is contained in:
Tobias Berger 2024-05-09 12:31:57 +02:00
parent 9ea84d3555
commit 710aedfe20
Signed by: toby
GPG key ID: 2D05EFAB764D6A88
7 changed files with 183 additions and 89 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/target /target
.direnv .direnv
result

View file

@ -1,38 +0,0 @@
{pkgs ? import <nixpkgs> {}}: let
manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
packages = with pkgs; [
pkg-config
libGLU
libGL
libxkbcommon
wayland
];
in
pkgs.rustPlatform.buildRustPackage {
pname = manifest.name;
version = manifest.version;
cargoLock.lockFile = ./Cargo.lock;
src = pkgs.lib.cleanSource ./.;
meta = {
description = manifest.description ? null;
};
postBuild = ''
patchelf --add-needed libxkbcommon.so target/x86_64-unknown-linux-gnu/release/todoodoo
patchelf --add-needed libwayland-client.so target/x86_64-unknown-linux-gnu/release/todoodoo
patchelf --add-needed libGLU.so target/x86_64-unknown-linux-gnu/release/todoodoo
patchelf --add-needed libEGL.so target/x86_64-unknown-linux-gnu/release/todoodoo
old_rpath=$(patchelf --print-rpath target/x86_64-unknown-linux-gnu/release/todoodoo)
if [[ -z "$old_rpath" ]]; then
patchelf --set-rpath "${pkgs.lib.makeLibraryPath packages}" target/x86_64-unknown-linux-gnu/release/todoodoo
else
patchelf --set-rpath "${pkgs.lib.makeLibraryPath packages}:$old_rpath" target/x86_64-unknown-linux-gnu/release/todoodoo
fi
'';
postInstall = ''
mkdir -p $out/share/applications/
cp todoodoo.desktop $out/share/applications/todoodoo.desktop
substituteInPlace $out/share/applications/todoodoo.desktop --replace /usr/bin/todoodoo $out/bin/todoodoo
'';
}

View file

@ -1,12 +1,33 @@
{ {
"nodes": { "nodes": {
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1715063087,
"narHash": "sha256-cktPkcCmJ2sR0V/FaWEuCWmKuGPbwoMltih/EfF0mXg=",
"owner": "nix-community",
"repo": "fenix",
"rev": "f8f16c1f2c83bea4e51e6522d988ec8bfcc8420e",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1706913249, "lastModified": 1715087517,
"narHash": "sha256-x3M7iV++CsvRXI1fpyFPduGELUckZEhSv0XWnUopAG8=", "narHash": "sha256-CLU5Tsg24Ke4+7sH8azHWXKd0CFd4mhLWfhYgUiDBpQ=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "e92b6015881907e698782c77641aa49298330223", "rev": "b211b392b8486ee79df6cdfb1157ad2133427a29",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -18,7 +39,46 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs" "fenix": "fenix",
"nixpkgs": "nixpkgs",
"treefmt-nix": "treefmt-nix"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1714936835,
"narHash": "sha256-M+PpgfRMBfHo8Jb2ou/s3maAZbps0XnuHXQU9Hv9vL0=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "c4618fe14d39992fbbb85c2d6cad028a232c13d2",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1714058656,
"narHash": "sha256-Qv4RBm4LKuO4fNOfx9wl40W2rBbv5u5m+whxRYUMiaA=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "c6aaf729f34a36c445618580a9f95a48f5e4e03f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
} }
} }
}, },

117
flake.nix
View file

@ -1,22 +1,113 @@
{ {
description = "ToDooDoo"; description = "ToDooDoo";
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
}; };
outputs = {
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self, self,
nixpkgs, nixpkgs,
}: let treefmt-nix,
supportedSystems = ["x86_64-linux"]; fenix,
forAllSystems = nixpkgs.lib.genAttrs supportedSystems; }:
pkgsFor = nixpkgs.legacyPackages; let
in { supportedSystems = [
formatter = forAllSystems (system: pkgsFor.${system}.alejandra); "x86_64-linux"
packages = forAllSystems (system: { "aarch64-linux"
default = pkgsFor.${system}.callPackage ./default.nix {}; "x86_64-darwin"
}); "aarch64-darwin"
devShells = forAllSystems (system: { ];
default = pkgsFor.${system}.callPackage ./shell.nix {}; forEachSupportedSystem =
}); f:
nixpkgs.lib.genAttrs supportedSystems (
system:
f (
let
pkgs = import nixpkgs { inherit system; };
fenix' = (import fenix { inherit system pkgs; });
toolchain = fenix'.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-opUgs6ckUQCyDxcB9Wy51pqhd0MPGHUVbwRKKPGiwZU=";
};
buildInputs = with pkgs; [
rust-analyzer
rustfmt
clippy
clang
mold
pkg-config
libGLU
libGL
libxkbcommon
wayland
];
in
{
inherit pkgs toolchain buildInputs;
}
)
);
in
{
formatter = forEachSupportedSystem (
{ pkgs, ... }: (treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build.wrapper
);
devShells = forEachSupportedSystem (
{
pkgs,
toolchain,
buildInputs,
}:
{
default = pkgs.mkShell {
buildInputs = buildInputs ++ [ toolchain ];
env = {
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath (buildInputs)}";
};
};
}
);
packages = forEachSupportedSystem (
{
pkgs,
toolchain,
buildInputs,
}:
{
default = (
let
manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
rustPlatform = pkgs.makeRustPlatform {
cargo = toolchain;
rustc = toolchain;
};
in
rustPlatform.buildRustPackage {
inherit buildInputs;
pname = manifest.name;
version = manifest.version;
cargoLock.lockFile = ./Cargo.lock;
src = pkgs.lib.cleanSource ./.;
}
);
}
);
}; };
} }

3
rust-toolchain.toml Normal file
View file

@ -0,0 +1,3 @@
[toolchain]
channel = "stable"
components = ["rustfmt", "cargo", "rustc", "rust-src"]

View file

@ -1,31 +0,0 @@
{
pkgs ? import <nixpkgs> {},
lib,
}: let
packages = with pkgs; [
rust-analyzer
rustfmt
clippy
clang
mold
pkg-config
libGLU
libGL
libxkbcommon
wayland
];
in
pkgs.mkShell {
# Get dependencies from the main package
inputsFrom = [(pkgs.callPackage ./default.nix {})];
nativeBuildInputs = packages;
buildInputs = packages;
env = {
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
LD_LIBRARY_PATH = "${lib.makeLibraryPath packages}";
};
}

8
treefmt.nix Normal file
View file

@ -0,0 +1,8 @@
{ ... }:
{
projectRootFile = "flake.nix";
programs = {
nixfmt-rfc-style.enable = true;
rustfmt.enable = true;
};
}