Use crane instead of naersk fixing issues of relm4-icons

This commit is contained in:
Julian Mutter 2024-05-27 12:38:27 +02:00
parent b01c08bdbe
commit 367997839c
2 changed files with 112 additions and 74 deletions

83
flake.lock generated
View File

@ -1,45 +1,50 @@
{
"nodes": {
"naersk": {
"crane": {
"inputs": {
"nixpkgs": "nixpkgs"
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1698420672,
"narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=",
"owner": "nix-community",
"repo": "naersk",
"rev": "aeb58d5e8faead8980a807c840232697982d47b9",
"lastModified": 1716745752,
"narHash": "sha256-8K1R9Yg4r08rYk86Yq+lu3E9L3uRUb4xMqYHgl0VGS0=",
"owner": "ipetkov",
"repo": "crane",
"rev": "19ca94ec2d288de334ae932107816b4a97736cd8",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "master",
"repo": "naersk",
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1707907779,
"narHash": "sha256-dtktfFJn+36yBkZ1mnQGdiDsqnzC9pXt/Ecpsui0hiY=",
"lastModified": 1716715802,
"narHash": "sha256-usk0vE7VlxPX8jOavrtpOqphdfqEQpf9lgedlY/r66c=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c5e9528855e4e6feda2b16dec28de880ce774b93",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1707907779,
"narHash": "sha256-dtktfFJn+36yBkZ1mnQGdiDsqnzC9pXt/Ecpsui0hiY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c5e9528855e4e6feda2b16dec28de880ce774b93",
"rev": "e2dd4e18cc1c7314e24154331bae07df76eb582f",
"type": "github"
},
"original": {
@ -51,9 +56,9 @@
},
"root": {
"inputs": {
"naersk": "naersk",
"nixpkgs": "nixpkgs_2",
"utils": "utils"
"crane": "crane",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
@ -70,24 +75,6 @@
"repo": "default",
"type": "github"
}
},
"utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",

103
flake.nix
View File

@ -1,38 +1,89 @@
{
description = "My own sheet-organizer using rust and relm4 (and nix)";
inputs = {
naersk.url = "github:nix-community/naersk/master";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, utils, naersk }:
utils.lib.eachDefaultSystem (system:
outputs = { self, nixpkgs, crane, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
naersk-lib = pkgs.callPackage naersk { };
pkgs = nixpkgs.legacyPackages.${system};
# Needed at compile time (on build system)
nativeBuildInputs = with pkgs; [
gtk4
pkg-config
# wrapGAppsHook
];
# Needed at runtime (on run system)
buildInputs = with pkgs; [ ];
in rec {
defaultPackage = naersk-lib.buildPackage {
src = ./.;
inherit buildInputs;
inherit nativeBuildInputs;
craneLib = crane.mkLib pkgs;
dbMigrationsFilter = path: _type: builtins.match ".*sql$" path != null;
dbMigrationsOrCargoFilter = path: type:
(dbMigrationsFilter path type)
|| (craneLib.filterCargoSources path type);
dbMigrations = pkgs.lib.cleanSourceWith {
src = craneLib.path ./db-migrations; # The original, unfiltered source
filter = dbMigrationsFilter;
};
devShell = with pkgs;
mkShell {
buildInputs =
[ cargo rustc rustfmt pre-commit rustPackages.clippy ];
# Without inheriting nativeBuildinputs, cargo build will fail but that is good since we want to use only nix build
# inherit nativeBuildInputs;
RUST_SRC_PATH = rustPlatform.rustLibSrc;
# Common arguments can be set here to avoid repeating them later
# Note: changes here will rebuild all dependency crates
commonArgs = rec {
src = pkgs.lib.cleanSourceWith {
src = craneLib.path ./.; # The original, unfiltered source
filter = dbMigrationsOrCargoFilter;
};
# src = craneLib.cleanCargoSource (craneLib.path ./.);
# Add icons.toml to $src when compiling dependencies (needed by relm4-icons)
# Add db-migrations to $src when compiling dependencies (needed by sqlx)
extraDummyScript = ''
cp --no-preserve=mode,ownership ${./icons.toml} $out/icons.toml
mkdir -p $out/db-migrations
cp -r --no-preserve=mode,ownership ${dbMigrations} --no-target-dir $out/db-migrations/
'';
nativeBuildInputs = with pkgs; [ pkg-config gtk4 ];
buildInputs = [
# Add additional build inputs here
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
};
my-crate = craneLib.buildPackage (commonArgs // {
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Additional environment variables or build phases/hooks can be set
# here *without* rebuilding all dependency crates
# MY_CUSTOM_VAR = "some value";
});
in {
checks = { inherit my-crate; };
packages.default = my-crate;
apps.default = flake-utils.lib.mkApp { drv = my-crate; };
devShells.default = craneLib.devShell {
# Inherit inputs from checks.
checks = self.checks.${system};
# Additional dev-shell environment variables can be set directly
# MY_CUSTOM_DEVELOPMENT_VAR = "something else";
# Extra inputs can be added here; cargo and rustc are provided by default.
packages = with pkgs;
[
# rustPackages.clippy
# rustfmt
# pre-commit
];
};
});
}