Skip to content

Commit

Permalink
chore: cleanup the Nix in prep for CI setup
Browse files Browse the repository at this point in the history
  • Loading branch information
nrdxp committed Sep 19, 2023
1 parent f267df8 commit 958de7c
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 125 deletions.
73 changes: 31 additions & 42 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{
description = "A very basic flake for Rust development";
description = "CI framework, devshell, and package for the Cloudflare Dynamic DNS Client";

inputs.std.url = "github:divnix/std/v0.24.0-1";
inputs.std.inputs.nixpkgs.follows = "nixpkgs";
inputs.std.inputs.devshell.follows = "devshell";

inputs.fenix.url = "github:nix-community/fenix";

inputs.crane.url = "github:ipetkov/crane";
inputs.crane.inputs.nixpkgs.follows = "nixpkgs";
inputs.crane.inputs.flake-compat.follows = "";
inputs.crane.inputs.rust-overlay.follows = "";

inputs.std.inputs.devshell.url = "github:numtide/devshell";
inputs.devshell.url = "github:numtide/devshell";
inputs.devshell.inputs.nixpkgs.follows = "nixpkgs";

inputs.nixpkgs.follows = "fenix/nixpkgs";

Expand All @@ -24,9 +27,8 @@
systems = ["x86_64-linux"];
cellsFrom = ./nix;
cellBlocks = with std.blockTypes; [
(installables "packages")
# Contribution Environment
(devshells "shells")
(installables "packages" {ci.build = true;})
(devshells "shells" {ci.build = true;})
(pkgs "rust")
];
} {
Expand Down
9 changes: 5 additions & 4 deletions nix/bin/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
inherit (inputs.nixpkgs) pkgs;

crane = inputs.crane.lib.overrideToolchain cells.repo.rust.toolchain;
in {
# sane default for a binary package
default = crane.buildPackage {
in rec {
default = cfdyndns;
cfdyndns = crane.buildPackage {
src = std.incl self [
"${self}/Cargo.lock"
"${self}/Cargo.toml"
"${self}/src"
];

buildInputs = [pkgs.openssl pkgs.pkgconfig];
buildInputs = [pkgs.openssl pkgs.pkg-config];
meta.description = "CloudFlare Dynamic DNS Client";
};
}
148 changes: 74 additions & 74 deletions nix/repo/shells.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,86 +7,86 @@
inherit (inputs.cells) bin;

l = nixpkgs.lib // builtins;
in rec {
default = dev;
dev = derivation ((lib.dev.mkShell {
packages = [
nixpkgs.pkg-config
];
language.rust = {
packageSet = cell.rust;
enableDefaultToolchain = true;
tools = ["toolchain"]; # fenix collates them all in a convenience derivation
};

dev = lib.dev.mkShell {
packages = [
nixpkgs.pkg-config
];
language.rust = {
packageSet = cell.rust;
enableDefaultToolchain = true;
tools = ["toolchain"]; # fenix collates them all in a convenience derivation
};

devshell.startup.link-cargo-home = {
deps = [];
text = ''
# ensure CARGO_HOME is populated
mkdir -p $PRJ_DATA_DIR/cargo
ln -snf -t $PRJ_DATA_DIR/cargo $(ls -d ${cell.rust.toolchain}/*)
'';
};

env = [
{
# ensures subcommands are picked up from the right place
# but also needs to be writable; see link-cargo-home above
name = "CARGO_HOME";
eval = "$PRJ_DATA_DIR/cargo";
}
{
# ensure we know where rustup_home will be
name = "RUSTUP_HOME";
eval = "$PRJ_DATA_DIR/rustup";
}
{
name = "RUST_SRC_PATH";
# accessing via toolchain doesn't fail if it's not there
# and rust-analyzer is graceful if it's not set correctly:
# https://github.com/rust-lang/rust-analyzer/blob/7f1234492e3164f9688027278df7e915bc1d919c/crates/project-model/src/sysroot.rs#L196-L211
value = "${cell.rust.toolchain}/lib/rustlib/src/rust/library";
}
{
name = "PKG_CONFIG_PATH";
value = l.makeSearchPath "lib/pkgconfig" bin.packages.default.buildInputs;
}
];
imports = [
"${inputs.std.inputs.devshell}/extra/language/rust.nix"
];
devshell.startup.link-cargo-home = {
deps = [];
text = ''
# ensure CARGO_HOME is populated
mkdir -p $PRJ_DATA_DIR/cargo
ln -snf -t $PRJ_DATA_DIR/cargo $(ls -d ${cell.rust.toolchain}/*)
'';
};

commands = let
rustCmds =
l.map (name: {
inherit name;
package = cell.rust.toolchain; # has all bins
category = "rust dev";
# fenix doesn't include package descriptions, so pull those out of their equivalents in nixpkgs
help = nixpkgs.${name}.meta.description;
}) [
"rustc"
"cargo"
"rustfmt"
"rust-analyzer"
];
in
[
env = [
{
package = nixpkgs.treefmt;
category = "repo tools";
# ensures subcommands are picked up from the right place
# but also needs to be writable; see link-cargo-home above
name = "CARGO_HOME";
eval = "$PRJ_DATA_DIR/cargo";
}
{
package = nixpkgs.alejandra;
category = "repo tools";
# ensure we know where rustup_home will be
name = "RUSTUP_HOME";
eval = "$PRJ_DATA_DIR/rustup";
}
{
package = std.cli.default;
category = "std";
name = "RUST_SRC_PATH";
# accessing via toolchain doesn't fail if it's not there
# and rust-analyzer is graceful if it's not set correctly:
# https://github.com/rust-lang/rust-analyzer/blob/7f1234492e3164f9688027278df7e915bc1d919c/crates/project-model/src/sysroot.rs#L196-L211
value = "${cell.rust.toolchain}/lib/rustlib/src/rust/library";
}
]
++ rustCmds;
};
in {
inherit dev;
default = dev;
{
name = "PKG_CONFIG_PATH";
value = l.makeSearchPath "lib/pkgconfig" bin.packages.default.buildInputs;
}
];
imports = [
"${inputs.std.inputs.devshell}/extra/language/rust.nix"
];

commands = let
rustCmds =
l.map (name: {
inherit name;
package = cell.rust.toolchain; # has all bins
category = "rust dev";
# fenix doesn't include package descriptions, so pull those out of their equivalents in nixpkgs
help = nixpkgs.${name}.meta.description;
}) [
"rustc"
"cargo"
"rustfmt"
"rust-analyzer"
];
in
[
{
package = nixpkgs.treefmt;
category = "repo tools";
}
{
package = nixpkgs.alejandra;
category = "repo tools";
}
{
package = std.cli.default;
category = "std";
}
]
++ rustCmds;
})
.drvAttrs
// {meta.description = "rust devshell for working on `cfdyndns`";});
}

0 comments on commit 958de7c

Please sign in to comment.