Switch to crane over cargo2nix

This commit is contained in:
Jack O'Sullivan 2024-08-02 18:26:30 +01:00
parent 6794f6c238
commit a9a06cd03d
5 changed files with 397 additions and 2173 deletions

3
.envrc
View File

@ -1,2 +1 @@
watch_file Cargo.nix use flake . --override-input rootdir "file+file://"<(printf %s "$PWD")
use flake

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
/target /target
/result-bin /result
/.direnv/ /.direnv/
/.devenv/

2071
Cargo.nix

File diff suppressed because it is too large Load Diff

383
flake.lock generated
View File

@ -1,48 +1,127 @@
{ {
"nodes": { "nodes": {
"cargo2nix": { "cachix": {
"inputs": { "inputs": {
"flake-compat": "flake-compat", "devenv": "devenv_2",
"flake-utils": "flake-utils", "flake-compat": [
"nixpkgs": "nixpkgs", "devenv",
"rust-overlay": "rust-overlay" "flake-compat"
],
"nixpkgs": [
"devenv",
"nixpkgs"
],
"pre-commit-hooks": [
"devenv",
"pre-commit-hooks"
]
}, },
"locked": { "locked": {
"lastModified": 1705129117, "lastModified": 1712055811,
"narHash": "sha256-LgdDHibvimzYhxBK3kxCk2gAL7k4Hyigl5KI0X9cijA=", "narHash": "sha256-7FcfMm5A/f02yyzuavJe06zLa9hcMHsagE28ADcmQvk=",
"owner": "cargo2nix", "owner": "cachix",
"repo": "cargo2nix", "repo": "cachix",
"rev": "ae19a9e1f8f0880c088ea155ab66cee1fa001f59", "rev": "02e38da89851ec7fec3356a5c04bc8349cae0e30",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "cargo2nix", "owner": "cachix",
"repo": "cargo2nix", "repo": "cachix",
"type": "github" "type": "github"
} }
}, },
"devshell": { "crane": {
"inputs": { "inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
] ]
}, },
"locked": { "locked": {
"lastModified": 1721986491, "lastModified": 1721842668,
"narHash": "sha256-lVAlUOIPszv5HMYQGscskeGdRIYpTY6xrPfEok0hHgI=", "narHash": "sha256-k3oiD2z2AAwBFLa4+xfU+7G5fisRXfkvrMTCJrjZzXo=",
"owner": "numtide", "owner": "ipetkov",
"repo": "devshell", "repo": "crane",
"rev": "cc8700135fb0740199ac248063f20c6b1a3c7e42", "rev": "529c1a0b1f29f0d78fa3086b8f6a134c71ef3aaf",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "numtide", "owner": "ipetkov",
"repo": "devshell", "repo": "crane",
"type": "github"
}
},
"devenv": {
"inputs": {
"cachix": "cachix",
"flake-compat": "flake-compat_2",
"nix": "nix_2",
"nixpkgs": [
"nixpkgs"
],
"pre-commit-hooks": "pre-commit-hooks"
},
"locked": {
"lastModified": 1722605649,
"narHash": "sha256-T5dzUFRb2ocZ+LB2qBZufewdUFQs0pB4fnLKIWBLd9Y=",
"owner": "cachix",
"repo": "devenv",
"rev": "a07842582c030fdf2ccf07d3b1402b2a46908856",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "devenv",
"type": "github"
}
},
"devenv_2": {
"inputs": {
"flake-compat": [
"devenv",
"cachix",
"flake-compat"
],
"nix": "nix",
"nixpkgs": "nixpkgs",
"poetry2nix": "poetry2nix",
"pre-commit-hooks": [
"devenv",
"cachix",
"pre-commit-hooks"
]
},
"locked": {
"lastModified": 1708704632,
"narHash": "sha256-w+dOIW60FKMaHI1q5714CSibk99JfYxm0CzTinYWr+Q=",
"owner": "cachix",
"repo": "devenv",
"rev": "2ee4450b0f4b95a1b90f2eb5ffea98b90e48c196",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "python-rewrite",
"repo": "devenv",
"type": "github" "type": "github"
} }
}, },
"flake-compat": { "flake-compat": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-compat_2": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1696426674, "lastModified": 1696426674,
@ -81,11 +160,11 @@
"systems": "systems" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1694529238, "lastModified": 1689068808,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384", "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -99,11 +178,11 @@
"systems": "systems_2" "systems": "systems_2"
}, },
"locked": { "locked": {
"lastModified": 1701680307, "lastModified": 1710146030,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725", "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -112,18 +191,117 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs": { "gitignore": {
"inputs": {
"nixpkgs": [
"devenv",
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": { "locked": {
"lastModified": 1705099185, "lastModified": 1709087332,
"narHash": "sha256-SxJenKtvcrKJd0TyJQMO3p6VA7PEp+vmMnmlKFzWMNs=", "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
"owner": "nixos", "owner": "hercules-ci",
"repo": "nixpkgs", "repo": "gitignore.nix",
"rev": "2bce5ccff0ad7abda23e8bb56434b6877a446694", "rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nixos", "owner": "hercules-ci",
"ref": "release-23.11", "repo": "gitignore.nix",
"type": "github"
}
},
"nix": {
"inputs": {
"flake-compat": "flake-compat",
"nixpkgs": [
"devenv",
"cachix",
"devenv",
"nixpkgs"
],
"nixpkgs-regression": "nixpkgs-regression"
},
"locked": {
"lastModified": 1712911606,
"narHash": "sha256-BGvBhepCufsjcUkXnEEXhEVjwdJAwPglCC2+bInc794=",
"owner": "domenkozar",
"repo": "nix",
"rev": "b24a9318ea3f3600c1e24b4a00691ee912d4de12",
"type": "github"
},
"original": {
"owner": "domenkozar",
"ref": "devenv-2.21",
"repo": "nix",
"type": "github"
}
},
"nix-github-actions": {
"inputs": {
"nixpkgs": [
"devenv",
"cachix",
"devenv",
"poetry2nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1688870561,
"narHash": "sha256-4UYkifnPEw1nAzqqPOTL2MvWtm3sNGw1UTYTalkTcGY=",
"owner": "nix-community",
"repo": "nix-github-actions",
"rev": "165b1650b753316aa7f1787f3005a8d2da0f5301",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nix-github-actions",
"type": "github"
}
},
"nix_2": {
"inputs": {
"flake-compat": [
"devenv",
"flake-compat"
],
"nixpkgs": [
"devenv",
"nixpkgs"
],
"nixpkgs-regression": "nixpkgs-regression_2"
},
"locked": {
"lastModified": 1712911606,
"narHash": "sha256-BGvBhepCufsjcUkXnEEXhEVjwdJAwPglCC2+bInc794=",
"owner": "domenkozar",
"repo": "nix",
"rev": "b24a9318ea3f3600c1e24b4a00691ee912d4de12",
"type": "github"
},
"original": {
"owner": "domenkozar",
"ref": "devenv-2.21",
"repo": "nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1692808169,
"narHash": "sha256-x9Opq06rIiwdwGeK2Ykj69dNc2IvUH1fY55Wm7atwrE=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "9201b5ff357e781bf014d0330d18555695df7ba8",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
@ -140,6 +318,54 @@
"url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz"
} }
}, },
"nixpkgs-regression": {
"locked": {
"lastModified": 1643052045,
"narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2",
"type": "github"
}
},
"nixpkgs-regression_2": {
"locked": {
"lastModified": 1643052045,
"narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2",
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1710695816,
"narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "614b4613980a522ba49f0d194531beddbb7220d3",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1722040881, "lastModified": 1722040881,
@ -170,41 +396,82 @@
"type": "github" "type": "github"
} }
}, },
"root": { "poetry2nix": {
"inputs": { "inputs": {
"cargo2nix": "cargo2nix", "flake-utils": "flake-utils",
"devshell": "devshell", "nix-github-actions": "nix-github-actions",
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs_2",
"rust-overlay": "rust-overlay_2"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": [
"cargo2nix",
"flake-utils"
],
"nixpkgs": [ "nixpkgs": [
"cargo2nix", "devenv",
"cachix",
"devenv",
"nixpkgs" "nixpkgs"
] ]
}, },
"locked": { "locked": {
"lastModified": 1705112162, "lastModified": 1692876271,
"narHash": "sha256-IAM0+Uijh/fwlfoeDrOwau9MxcZW3zeDoUHc6Z3xfqM=", "narHash": "sha256-IXfZEkI0Mal5y1jr6IRWMqK8GW2/f28xJenZIPQqkY0=",
"owner": "oxalica", "owner": "nix-community",
"repo": "rust-overlay", "repo": "poetry2nix",
"rev": "9e0af26ffe52bf955ad5575888f093e41fba0104", "rev": "d5006be9c2c2417dafb2e2e5034d83fabd207ee3",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "oxalica", "owner": "nix-community",
"repo": "rust-overlay", "repo": "poetry2nix",
"type": "github" "type": "github"
} }
}, },
"rust-overlay_2": { "pre-commit-hooks": {
"inputs": {
"flake-compat": [
"devenv",
"flake-compat"
],
"flake-utils": "flake-utils_2",
"gitignore": "gitignore",
"nixpkgs": [
"devenv",
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1713775815,
"narHash": "sha256-Wu9cdYTnGQQwtT20QQMg7jzkANKQjwBD9iccfGKkfls=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "2ac4dcbf55ed43f3be0bae15e181f08a57af24a4",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"crane": "crane",
"devenv": "devenv",
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs_2",
"rootdir": "rootdir",
"rust-overlay": "rust-overlay"
}
},
"rootdir": {
"flake": false,
"locked": {
"narHash": "sha256-d6xi4mKdjkX2JFicDIv5niSzpyI0m/Hnm8GGAIU04kY=",
"type": "file",
"url": "file:///dev/null"
},
"original": {
"type": "file",
"url": "file:///dev/null"
}
},
"rust-overlay": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs_3" "nixpkgs": "nixpkgs_3"
}, },

110
flake.nix
View File

@ -2,46 +2,60 @@
inputs = { inputs = {
flake-parts.url = "github:hercules-ci/flake-parts"; flake-parts.url = "github:hercules-ci/flake-parts";
rust-overlay.url = "github:oxalica/rust-overlay"; rust-overlay.url = "github:oxalica/rust-overlay";
cargo2nix.url = "github:cargo2nix/cargo2nix"; crane.url = "github:ipetkov/crane";
devshell.url = "github:numtide/devshell"; crane.inputs.nixpkgs.follows = "nixpkgs";
devshell.inputs.nixpkgs.follows = "nixpkgs"; devenv.url = "github:cachix/devenv";
devenv.inputs.nixpkgs.follows = "nixpkgs";
rootdir = {
url = "file+file:///dev/null";
flake = false;
};
}; };
outputs = inputs@{ nixpkgs, flake-parts, rust-overlay, cargo2nix, devshell, ... }: outputs =
inputs@{
nixpkgs, flake-parts, rust-overlay, crane,
devenv,
rootdir,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } { flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ imports = [
inputs.flake-parts.flakeModules.easyOverlay inputs.flake-parts.flakeModules.easyOverlay
devshell.flakeModule devenv.flakeModule
]; ];
systems = [ "x86_64-linux" ]; systems = [ "x86_64-linux" ];
perSystem = { inputs', system, pkgs, config, ... }:
debug = true;
perSystem = { inputs', system, lib, pkgs, config, ... }:
let let
binlessFuse = pkgs.fuse3.overrideAttrs (old: { inherit (lib) genAttrs;
postFixup = old.postFixup + ''
rm -r "$out"/{,s}bin rustToolchain' = ps: ps.rust-bin.stable."1.80.0".default;
''; rustToolchain = rustToolchain' pkgs;
}); craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain';
rustPkgs = pkgs.rustBuilder.makePackageSet {
rustToolchain = pkgs.rust-bin.stable."1.80.0".default; src = craneLib.cleanCargoSource ./.;
packageFun = import ./Cargo.nix; commonArgs = {
packageOverrides = pkgs: pkgs.rustBuilder.overrides.all ++ [ inherit src;
(pkgs.rustBuilder.rustLib.makeOverride { strictDeps = true;
name = "fuser";
overrideAttrs = drv: { nativeBuildInputs = with pkgs; [
propagatedBuildInputs = drv.propagatedBuildInputs ++ [ pkg-config
binlessFuse ];
]; buildInputs = with pkgs; [
}; fuse3
})
]; ];
}; };
# Build *just* the cargo dependencies, so we can reuse
# all of that work when running in CI
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
in in
{ {
_module.args.pkgs = import nixpkgs { _module.args.pkgs = import nixpkgs {
inherit system; inherit system;
overlays = [ overlays = [
devshell.overlays.default
cargo2nix.overlays.default
rust-overlay.overlays.default rust-overlay.overlays.default
]; ];
}; };
@ -50,25 +64,39 @@
inherit (config.packages) quicfs; inherit (config.packages) quicfs;
}; };
packages = rec { packages = rec {
quicfs = (rustPkgs.workspace.quicfs { }).bin; quicfs = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
});
default = quicfs; default = quicfs;
}; };
devshells.default = { devenv.shells.default = devenvArgs:
imports = [ "${pkgs.devshell.extraModulesDir}/language/c.nix" ]; let
language.c = with pkgs; rec { cfg = devenvArgs.config;
compiler = gcc;
libraries = [ rootdirOpt =
binlessFuse let
]; rootFileContent = builtins.readFile rootdir.outPath;
includes = libraries; in
pkgs.lib.mkIf (rootFileContent != "") rootFileContent;
in
{
devenv.root = rootdirOpt;
packages = with pkgs; [
fuse3
cargo-outdated
];
languages = {
c.enable = true;
rust = {
enable = true;
channel = "nixpkgs";
# HACK: This devenv module expects each component in a separate package,
# but rust-overlay isn't really set up that way
toolchain = genAttrs cfg.languages.rust.components (_: rustToolchain);
};
}; };
packagesFrom = [
(rustPkgs.workspaceShell { })
];
packages = [
inputs'.cargo2nix.packages.default
pkgs.cargo-outdated
];
}; };
}; };
}; };