Merge pull request #14 from srid/dream2nix

Switch to nix-cargo-integration (dream2nix)
This commit is contained in:
Sridhar Ratnakumar 2022-05-08 17:06:22 -04:00 committed by GitHub
commit d2187b8dd8
Failed to generate hash of commit
5 changed files with 144 additions and 142 deletions

1
.gitattributes vendored Normal file
View file

@ -0,0 +1 @@
flake.lock linguist-generated=true

View file

@ -9,3 +9,15 @@ version = "0.1.0"
[dependencies]
clap = "2.33.3"
[package.metadata.nix]
app = true
build = true
library = true
systems = [
"aarch64-linux",
"aarch64-darwin",
"i686-linux",
"x86_64-darwin",
"x86_64-linux",
]

View file

@ -1,6 +1,6 @@
A template Rust project with fully functional and no-frills Nix support, as well as builtin VSCode configuration to get IDE experience without any manual setup (just open in VSCode and accept the suggestions).
A template Rust project with fully functional and no-frills Nix support, as well as builtin VSCode configuration to get IDE experience without any manual setup (just open in VSCode and accept the suggestions). Based on `dream2nix` and [nix-cargo-integration](https://github.com/yusdacra/nix-cargo-integration).
See [Nix-ifying Rust projects](https://srid.ca/rust-nix) for details.
Note: If you are looking for the original template based on [this blog post](https://srid.ca/rust-nix)'s use of `crate2nix`, you [this tag](https://github.com/srid/rust-nix-template/tree/crate2nix).
## Adapting this template
@ -17,9 +17,6 @@ This repo uses [Flakes](https://nixos.wiki/wiki/Flakes) from the get-go, but com
# Dev shell
nix develop
# or just run directly
nix run
# or run via cargo
nix develop -c cargo run

167
flake.lock generated
View file

@ -1,18 +1,90 @@
{
"nodes": {
"crate2nix": {
"crane": {
"flake": false,
"locked": {
"lastModified": 1650460722,
"narHash": "sha256-jk4SZ8iOnfJEceVULjyOAq4MrX9CfU5bCWMyZP9nJVA=",
"owner": "kolloch",
"repo": "crate2nix",
"rev": "78258f27fc3121562a44eb02c652a5ec77cf8d02",
"lastModified": 1644785799,
"narHash": "sha256-VpAJO1L0XeBvtCuNGK4IDKp6ENHIpTrlaZT7yfBCvwo=",
"owner": "ipetkov",
"repo": "crane",
"rev": "fc7a94f841347c88f2cb44217b2a3faa93e2a0b2",
"type": "github"
},
"original": {
"owner": "kolloch",
"repo": "crate2nix",
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"devshell": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": [
"nci",
"nixpkgs"
]
},
"locked": {
"lastModified": 1650900878,
"narHash": "sha256-qhNncMBSa9STnhiLfELEQpYC1L4GrYHNIzyCZ/pilsI=",
"owner": "numtide",
"repo": "devshell",
"rev": "d97df53b5ddaa1cfbea7cddbd207eb2634304733",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "devshell",
"type": "github"
}
},
"dream2nix": {
"inputs": {
"alejandra": [
"nci",
"nixpkgs"
],
"crane": "crane",
"flake-utils-pre-commit": [
"nci",
"nixpkgs"
],
"gomod2nix": [
"nci",
"nixpkgs"
],
"mach-nix": [
"nci",
"nixpkgs"
],
"nixpkgs": [
"nci",
"nixpkgs"
],
"node2nix": [
"nci",
"nixpkgs"
],
"poetry2nix": [
"nci",
"nixpkgs"
],
"pre-commit-hooks": [
"nci",
"nixpkgs"
]
},
"locked": {
"lastModified": 1651844867,
"narHash": "sha256-a+bAmmeIudRVY23ZkEB5W5xJumBY3ydsiDIGN/56NmQ=",
"owner": "nix-community",
"repo": "dream2nix",
"rev": "e5d0e9cdb00695b0b63d1f52ff3b39c0e3035fe3",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "dream2nix",
"type": "github"
}
},
@ -34,11 +106,11 @@
},
"flake-utils": {
"locked": {
"lastModified": 1637014545,
"narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=",
"lastModified": 1642700792,
"narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4",
"rev": "846b2ae0fc4cc943637d3d1def4454213e203cba",
"type": "github"
},
"original": {
@ -47,6 +119,29 @@
"type": "github"
}
},
"nci": {
"inputs": {
"devshell": "devshell",
"dream2nix": "dream2nix",
"nixpkgs": [
"nixpkgs"
],
"rustOverlay": "rustOverlay"
},
"locked": {
"lastModified": 1651990362,
"narHash": "sha256-Yw32A18l9hx/+19PcUhuoOLuBXtlrFoea7OAM3R4pzs=",
"owner": "yusdacra",
"repo": "nix-cargo-integration",
"rev": "d187cd7b1e8c85521c3bad633a79fd25f584f42e",
"type": "github"
},
"original": {
"owner": "yusdacra",
"repo": "nix-cargo-integration",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1651558728,
@ -63,42 +158,21 @@
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1637453606,
"narHash": "sha256-Gy6cwUswft9xqsjWxFYEnx/63/qzaFUwatcbV5GF/GQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "8afc4e543663ca0a6a4f496262cd05233737e732",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"crate2nix": "crate2nix",
"flake-compat": "flake-compat",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay",
"utils": "utils"
"nci": "nci",
"nixpkgs": "nixpkgs"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs_2"
},
"rustOverlay": {
"flake": false,
"locked": {
"lastModified": 1651632340,
"narHash": "sha256-Kq1yghXZxJ12Sw1nbzoO2Ag8/AxqbbD84wiz8go159o=",
"lastModified": 1651977622,
"narHash": "sha256-M3vm6mz+ypilmw3hkA6/GyDHH7ID85jWqeE9rtPWe8k=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "88991ffbd57e10b474ea768ec0b54c4f379c566c",
"rev": "c66fab76467a5df683ef50724a7bde54c315f967",
"type": "github"
},
"original": {
@ -106,21 +180,6 @@
"repo": "rust-overlay",
"type": "github"
}
},
"utils": {
"locked": {
"lastModified": 1649676176,
"narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",

View file

@ -6,93 +6,26 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
crate2nix = {
url = "github:kolloch/crate2nix";
flake = false;
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
nci.url = "github:yusdacra/nix-cargo-integration";
nci.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, utils, rust-overlay, crate2nix, ... }:
let
# If you change the name here, you must also do it in Cargo.toml
name = "rust-nix-template";
# Rust release channel to use.
# https://rust-lang.github.io/rustup/concepts/channels.html
rustChannel = "stable";
in
utils.lib.eachDefaultSystem
(system:
let
# Imports
pkgs = import nixpkgs {
inherit system;
overlays = [
rust-overlay.overlay
(self: super: {
# Because rust-overlay bundles multiple rust packages into one
# derivation, specify that mega-bundle here, so that crate2nix
# will use them automatically.
rustc = self.rust-bin.${rustChannel}.latest.default;
cargo = self.rust-bin.${rustChannel}.latest.default;
})
];
};
# cf. https://github.com/kolloch/crate2nix/issues/110
inherit (import "${crate2nix}/tools.nix" { inherit pkgs; })
generatedCargoNix;
# Create the cargo2nix project
project = pkgs.callPackage
(generatedCargoNix {
inherit name;
src = ./.;
})
{
inherit pkgs;
buildRustCrate = null; # https://github.com/kolloch/crate2nix/pull/178#issuecomment-820692187
# Individual crate overrides go here
# Example: https://github.com/balsoft/simple-osd-daemons/blob/6f85144934c0c1382c7a4d3a2bbb80106776e270/flake.nix#L28-L50
defaultCrateOverrides = pkgs.defaultCrateOverrides // {
# The himalaya crate itself is overriden here. Typically we
# configure non-Rust dependencies (see below) here.
${name} = oldAttrs: {
inherit buildInputs nativeBuildInputs;
};
};
};
# Configuration for the non-Rust dependencies
buildInputs = with pkgs; [ openssl.dev ];
nativeBuildInputs = with pkgs; [ rustc cargo pkgconfig ];
in
rec {
packages.${name} = project.rootCrate.build;
# `nix build`
defaultPackage = packages.${name};
# `nix develop`
devShell = pkgs.mkShell
{
inputsFrom = builtins.attrValues self.packages.${system};
buildInputs = buildInputs ++ (with pkgs;
# Tools you need for development go here.
[
nixpkgs-fmt
cargo-watch
pkgs.rust-bin.${rustChannel}.latest.rust-analysis
pkgs.rust-bin.${rustChannel}.latest.rls
]);
RUST_SRC_PATH = "${pkgs.rust-bin.${rustChannel}.latest.rust-src}/lib/rustlib/src/rust/library";
};
}
);
outputs = { self, nixpkgs, nci, ... }:
nci.lib.makeOutputs {
# Documentation and examples:
# https://github.com/yusdacra/rust-nix-templater/blob/master/template/flake.nix
root = ./.;
overrides = {
shell = common: prev: {
packages = prev.packages ++ [
common.pkgs.rust-analyzer
common.pkgs.cargo-watch
];
};
};
};
}