Switch over to nix-cargo-integration (dream2nix)

This commit is contained in:
Sridhar Ratnakumar 2022-05-08 17:00:33 -04:00
parent bc84c6744d
commit 4bd40b51f0
3 changed files with 141 additions and 137 deletions

View file

@ -9,3 +9,15 @@ version = "0.1.0"
[dependencies] [dependencies]
clap = "2.33.3" 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,18 +1,90 @@
{ {
"nodes": { "nodes": {
"crate2nix": { "crane": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1650460722, "lastModified": 1644785799,
"narHash": "sha256-jk4SZ8iOnfJEceVULjyOAq4MrX9CfU5bCWMyZP9nJVA=", "narHash": "sha256-VpAJO1L0XeBvtCuNGK4IDKp6ENHIpTrlaZT7yfBCvwo=",
"owner": "kolloch", "owner": "ipetkov",
"repo": "crate2nix", "repo": "crane",
"rev": "78258f27fc3121562a44eb02c652a5ec77cf8d02", "rev": "fc7a94f841347c88f2cb44217b2a3faa93e2a0b2",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "kolloch", "owner": "ipetkov",
"repo": "crate2nix", "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" "type": "github"
} }
}, },
@ -34,11 +106,11 @@
}, },
"flake-utils": { "flake-utils": {
"locked": { "locked": {
"lastModified": 1637014545, "lastModified": 1642700792,
"narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=", "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4", "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -47,6 +119,29 @@
"type": "github" "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": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1651558728, "lastModified": 1651558728,
@ -63,42 +158,21 @@
"type": "github" "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": { "root": {
"inputs": { "inputs": {
"crate2nix": "crate2nix",
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
"nixpkgs": "nixpkgs", "nci": "nci",
"rust-overlay": "rust-overlay", "nixpkgs": "nixpkgs"
"utils": "utils"
} }
}, },
"rust-overlay": { "rustOverlay": {
"inputs": { "flake": false,
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs_2"
},
"locked": { "locked": {
"lastModified": 1651632340, "lastModified": 1651977622,
"narHash": "sha256-Kq1yghXZxJ12Sw1nbzoO2Ag8/AxqbbD84wiz8go159o=", "narHash": "sha256-M3vm6mz+ypilmw3hkA6/GyDHH7ID85jWqeE9rtPWe8k=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "88991ffbd57e10b474ea768ec0b54c4f379c566c", "rev": "c66fab76467a5df683ef50724a7bde54c315f967",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -106,21 +180,6 @@
"repo": "rust-overlay", "repo": "rust-overlay",
"type": "github" "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", "root": "root",

View file

@ -6,93 +6,26 @@
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; 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 = { flake-compat = {
url = "github:edolstra/flake-compat"; url = "github:edolstra/flake-compat";
flake = false; flake = false;
}; };
nci.url = "github:yusdacra/nix-cargo-integration";
nci.inputs.nixpkgs.follows = "nixpkgs";
}; };
outputs = { self, nixpkgs, utils, rust-overlay, crate2nix, ... }: outputs = { self, nixpkgs, nci, ... }:
let nci.lib.makeOutputs {
# If you change the name here, you must also do it in Cargo.toml # Documentation and examples:
name = "rust-nix-template"; # https://github.com/yusdacra/rust-nix-templater/blob/master/template/flake.nix
# Rust release channel to use. root = ./.;
# https://rust-lang.github.io/rustup/concepts/channels.html overrides = {
rustChannel = "stable"; shell = common: prev: {
in packages = prev.packages ++ [
utils.lib.eachDefaultSystem common.pkgs.rust-analyzer
(system: common.pkgs.cargo-watch
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";
};
}
);
} }