-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initial version of the flake module #1
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
61ff758
Initial commit
srid 6a3c532
readme
srid 30ec57b
readme, more
srid 5abe916
Add lock file
srid 30a08fc
oh
srid 472ac3a
Add overlays
srid f00bddd
factor out
srid 1c2d168
fix
srid a6d3998
we
srid 4f08d2d
cleanup
srid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
# rust-flake | ||
|
||
WIP: Like the famous `haskell-flake`, but for Rust. | ||
|
||
## Progress | ||
|
||
- [x] Simple module that works with single-create projects | ||
- [ ] Multi-crate workspaces | ||
- [ ] Multiple projects | ||
- [ ] Examples & tests |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
description = "A `flake-parts` module for Rust development"; | ||
inputs = { | ||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; | ||
rust-overlay.url = "github:oxalica/rust-overlay"; | ||
# https://github.com/ipetkov/crane/issues/527 | ||
crane.url = "github:ipetkov/crane/2c653e4478476a52c6aa3ac0495e4dea7449ea0e"; # Cargo.toml parsing is broken in newer crane (Mar 24) | ||
crane.inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
outputs = { rust-overlay, crane, ... }: { | ||
flakeModules = { | ||
default = import ./nix/modules/flake-module.nix { inherit rust-overlay crane; }; | ||
nixpkgs = import ./nix/modules/nixpkgs.nix; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
inputs: | ||
{ self, lib, flake-parts-lib, ... }: | ||
|
||
let | ||
inherit (flake-parts-lib) | ||
mkPerSystemOption; | ||
in | ||
{ | ||
options = { | ||
perSystem = mkPerSystemOption | ||
({ config, self', pkgs, system, ... }: { | ||
options = { | ||
# TODO: Multiple projects | ||
# TODO: Workspace crates | ||
rust-project.crane.args.buildInputs = lib.mkOption { | ||
type = lib.types.listOf lib.types.package; | ||
default = [ ]; | ||
description = "(Runtime) buildInputs for the cargo package"; | ||
}; | ||
rust-project.crane.args.nativeBuildInputs = lib.mkOption { | ||
type = lib.types.listOf lib.types.package; | ||
default = with pkgs; [ | ||
pkg-config | ||
makeWrapper | ||
]; | ||
description = "nativeBuildInputs for the cargo package"; | ||
}; | ||
rust-project.crane.lib = lib.mkOption { | ||
type = lib.types.lazyAttrsOf lib.types.raw; | ||
default = (inputs.crane.mkLib pkgs).overrideToolchain config.rust-project.toolchain; | ||
}; | ||
|
||
rust-project.toolchain = lib.mkOption { | ||
type = lib.types.package; | ||
description = "Rust toolchain to use for the rust-project package"; | ||
default = (pkgs.rust-bin.fromRustupToolchainFile (self + /rust-toolchain.toml)).override { | ||
extensions = [ | ||
"rust-src" | ||
"rust-analyzer" | ||
"clippy" | ||
]; | ||
}; | ||
}; | ||
|
||
rust-project.src = lib.mkOption { | ||
type = lib.types.path; | ||
description = "Source directory for the rust-project package"; | ||
default = lib.cleanSourceWith { | ||
src = self; # The original, unfiltered source | ||
filter = path: type: | ||
# Default filter from crane (allow .rs files) | ||
(config.rust-project.crane.lib.filterCargoSources path type) | ||
; | ||
}; | ||
}; | ||
}; | ||
config = | ||
let | ||
cargoToml = builtins.fromTOML (builtins.readFile (self + /Cargo.toml)); | ||
inherit (cargoToml.package) name version; | ||
inherit (config.rust-project) toolchain crane src; | ||
|
||
# Crane builder | ||
craneBuild = rec { | ||
args = { | ||
inherit src; | ||
inherit (crane.args) buildInputs nativeBuildInputs; | ||
pname = name; | ||
version = version; | ||
# glib-sys fails to build on linux without this | ||
# cf. https://github.com/ipetkov/crane/issues/411#issuecomment-1747533532 | ||
strictDeps = true; | ||
}; | ||
cargoArtifacts = crane.lib.buildDepsOnly args; | ||
buildArgs = args // { | ||
inherit cargoArtifacts; | ||
}; | ||
package = crane.lib.buildPackage buildArgs; | ||
|
||
check = crane.lib.cargoClippy (args // { | ||
inherit cargoArtifacts; | ||
cargoClippyExtraArgs = "--all-targets --all-features -- --deny warnings"; | ||
}); | ||
|
||
doc = crane.lib.cargoDoc (args // { | ||
inherit cargoArtifacts; | ||
}); | ||
}; | ||
|
||
rustDevShell = pkgs.mkShell { | ||
shellHook = '' | ||
# For rust-analyzer 'hover' tooltips to work. | ||
export RUST_SRC_PATH="${toolchain}/lib/rustlib/src/rust/library"; | ||
''; | ||
buildInputs = [ | ||
pkgs.libiconv | ||
] ++ config.rust-project.crane.args.buildInputs; | ||
packages = [ | ||
toolchain | ||
]; | ||
}; | ||
in | ||
{ | ||
# See nix/modules/nixpkgs.nix (the user must import it) | ||
nixpkgs.overlays = [ | ||
inputs.rust-overlay.overlays.default | ||
]; | ||
|
||
# Rust package | ||
packages.${name} = craneBuild.package; | ||
packages."${name}-doc" = craneBuild.doc; | ||
|
||
checks."${name}-clippy" = craneBuild.check; | ||
|
||
# Rust dev environment | ||
devShells.${name} = pkgs.mkShell { | ||
inputsFrom = [ | ||
rustDevShell | ||
]; | ||
}; | ||
}; | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# https://github.com/hercules-ci/flake-parts/issues/74#issuecomment-1513708722 | ||
{ inputs, flake-parts-lib, ... }: { | ||
options.perSystem = flake-parts-lib.mkPerSystemOption ({ pkgs, system, ... }: { | ||
imports = [ | ||
"${inputs.nixpkgs}/nixos/modules/misc/nixpkgs.nix" | ||
]; | ||
nixpkgs.hostPlatform = system; | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to @Atry
hercules-ci/flake-parts#74 (comment)