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": { "nodes": {
"naersk": { "crane": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs" "nixpkgs": [
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1698420672, "lastModified": 1716745752,
"narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=", "narHash": "sha256-8K1R9Yg4r08rYk86Yq+lu3E9L3uRUb4xMqYHgl0VGS0=",
"owner": "nix-community", "owner": "ipetkov",
"repo": "naersk", "repo": "crane",
"rev": "aeb58d5e8faead8980a807c840232697982d47b9", "rev": "19ca94ec2d288de334ae932107816b4a97736cd8",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nix-community", "owner": "ipetkov",
"ref": "master", "repo": "crane",
"repo": "naersk", "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" "type": "github"
} }
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1707907779, "lastModified": 1716715802,
"narHash": "sha256-dtktfFJn+36yBkZ1mnQGdiDsqnzC9pXt/Ecpsui0hiY=", "narHash": "sha256-usk0vE7VlxPX8jOavrtpOqphdfqEQpf9lgedlY/r66c=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "c5e9528855e4e6feda2b16dec28de880ce774b93", "rev": "e2dd4e18cc1c7314e24154331bae07df76eb582f",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1707907779,
"narHash": "sha256-dtktfFJn+36yBkZ1mnQGdiDsqnzC9pXt/Ecpsui0hiY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c5e9528855e4e6feda2b16dec28de880ce774b93",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -51,9 +56,9 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"naersk": "naersk", "crane": "crane",
"nixpkgs": "nixpkgs_2", "flake-utils": "flake-utils",
"utils": "utils" "nixpkgs": "nixpkgs"
} }
}, },
"systems": { "systems": {
@ -70,24 +75,6 @@
"repo": "default", "repo": "default",
"type": "github" "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", "root": "root",

103
flake.nix
View File

@ -1,38 +1,89 @@
{ {
description = "My own sheet-organizer using rust and relm4 (and nix)";
inputs = { inputs = {
naersk.url = "github:nix-community/naersk/master";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 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 }: outputs = { self, nixpkgs, crane, flake-utils, ... }:
utils.lib.eachDefaultSystem (system: flake-utils.lib.eachDefaultSystem (system:
let let
pkgs = import nixpkgs { inherit system; }; pkgs = nixpkgs.legacyPackages.${system};
naersk-lib = pkgs.callPackage naersk { };
# Needed at compile time (on build system) craneLib = crane.mkLib pkgs;
nativeBuildInputs = with pkgs; [
gtk4 dbMigrationsFilter = path: _type: builtins.match ".*sql$" path != null;
pkg-config dbMigrationsOrCargoFilter = path: type:
# wrapGAppsHook (dbMigrationsFilter path type)
]; || (craneLib.filterCargoSources path type);
# Needed at runtime (on run system)
buildInputs = with pkgs; [ ]; dbMigrations = pkgs.lib.cleanSourceWith {
in rec { src = craneLib.path ./db-migrations; # The original, unfiltered source
defaultPackage = naersk-lib.buildPackage { filter = dbMigrationsFilter;
src = ./.;
inherit buildInputs;
inherit nativeBuildInputs;
}; };
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
];
};
}); });
} }