heavily refactor nix flake (#532)

* heavily refactor nix flake

* move from legacy rust-toolchain to rust-toolchain.toml
This commit is contained in:
moni 2022-08-22 05:09:54 +08:00 committed by GitHub
parent 25105c7c4f
commit 6657ef493e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 90 additions and 135 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
/target /target
/**/target /**/target
/result
/result-*

102
flake.lock generated
View file

@ -1,26 +1,5 @@
{ {
"nodes": { "nodes": {
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1654237591,
"narHash": "sha256-+uOzx9fuo3CBHO7aGI+SKxDXpf/7NTOXi0g4UxOdk9k=",
"owner": "nix-community",
"repo": "fenix",
"rev": "8dccfbe51a8adea643ec29a4ec516499a5a081c6",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"flake-compat": { "flake-compat": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -39,11 +18,11 @@
}, },
"flake-utils": { "flake-utils": {
"locked": { "locked": {
"lastModified": 1653893745, "lastModified": 1656928814,
"narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", "narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", "rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -52,76 +31,47 @@
"type": "github" "type": "github"
} }
}, },
"naersk": {
"inputs": {
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1653413650,
"narHash": "sha256-wojDHjb+eU80MPH+3HQaK0liUy8EgR95rvmCl24i58Y=",
"owner": "nmattia",
"repo": "naersk",
"rev": "69daaceebe12c070cd5ae69ba38f277bbf033695",
"type": "github"
},
"original": {
"owner": "nmattia",
"repo": "naersk",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1654126564, "lastModified": 1660639432,
"narHash": "sha256-sgDXDKGmUG4h7OPDOHyQggFQ08ZqVzUIPi8351yhugY=", "narHash": "sha256-2WDiboOCfB0LhvnDVMXOAr8ZLDfm3WdO54CkoDPwN1A=",
"owner": "NixOS", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "f1c9c23aad972787f00f175651e4cb0d7c7fd5ea", "rev": "6c6409e965a6c883677be7b9d87a95fab6c3472e",
"type": "github" "type": "github"
}, },
"original": { "original": {
"id": "nixpkgs", "owner": "nixos",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1654126564,
"narHash": "sha256-sgDXDKGmUG4h7OPDOHyQggFQ08ZqVzUIPi8351yhugY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "f1c9c23aad972787f00f175651e4cb0d7c7fd5ea",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixpkgs-unstable", "ref": "nixpkgs-unstable",
"type": "indirect" "repo": "nixpkgs",
"type": "github"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"fenix": "fenix",
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
"flake-utils": "flake-utils", "nixpkgs": "nixpkgs",
"naersk": "naersk", "rust-overlay": "rust-overlay"
"nixpkgs": "nixpkgs_2"
} }
}, },
"rust-analyzer-src": { "rust-overlay": {
"flake": false, "inputs": {
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
]
},
"locked": { "locked": {
"lastModified": 1654178556, "lastModified": 1660791450,
"narHash": "sha256-LG8J9E/wMBolkWS3VstuvhgQ4jOp3Nk328EXlCYY24U=", "narHash": "sha256-I3q06x8HkjavfzvQm2nlGjYwclKfYRYjo3x9jqKBSgA=",
"owner": "rust-lang", "owner": "oxalica",
"repo": "rust-analyzer", "repo": "rust-overlay",
"rev": "88024c7ec2d44a8be8bf05a6580409200cf726fc", "rev": "98db932adeee26ea311ba4bbbdf4e0e5c3569fc4",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "rust-lang", "owner": "oxalica",
"ref": "nightly", "repo": "rust-overlay",
"repo": "rust-analyzer",
"type": "github" "type": "github"
} }
} }

110
flake.nix
View file

@ -1,76 +1,76 @@
{ {
inputs = { inputs = {
fenix = { flake-compat = { url = "github:edolstra/flake-compat"; flake = false; };
url = "github:nix-community/fenix"; rust-overlay.url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs"; nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
}; };
flake-compat = { outputs = { self, nixpkgs, rust-overlay, flake-compat, ... }:
url = "github:edolstra/flake-compat";
flake = false;
};
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "nixpkgs/nixpkgs-unstable";
naersk.url = "github:nmattia/naersk";
};
outputs = { self, flake-utils, fenix, nixpkgs, naersk, flake-compat, ... }:
flake-utils.lib.eachSystem [ "aarch64-linux" "x86_64-linux" ] (system:
let let
pkgs = import nixpkgs { inherit system; }; pkgsFor = system: import nixpkgs {
toolchain = fenix.packages.${system}.latest; inherit system;
naersk-lib = (naersk.lib."${system}".override { overlays = [
inherit (toolchain) cargo rustc; self.overlays.default
}); rust-overlay.overlays.default
mkEww = { wayland ? false }:
naersk-lib.buildPackage {
pname = "eww";
src = builtins.path { name = "eww"; path = ./.; };
nativeBuildInputs = with pkgs; [ pkg-config gtk3 ];
buildInputs = pkgs.lib.optional wayland pkgs.gtk-layer-shell;
cargoBuildOptions = opts: opts ++ pkgs.lib.optionals wayland [
"--no-default-features"
"--features=wayland"
]; ];
}; };
targetSystems = [ "aarch64-linux" "x86_64-linux" ];
mkRustToolchain = pkgs: pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
in
{
overlays.default = final: prev:
let
rust = mkRustToolchain final;
rustPlatform = prev.makeRustPlatform {
cargo = rust;
rustc = rust;
};
in in
{ {
apps = rec { eww = (prev.eww.override { inherit rustPlatform; }).overrideAttrs (old: {
default = eww; version = self.rev or "dirty";
eww = flake-utils.lib.mkApp { drv = self.packages.${system}.eww; }; src = builtins.path { name = "eww"; path = prev.lib.cleanSource ./.; };
eww-wayland = flake-utils.lib.mkApp { drv = self.packages.${system}.eww-wayland; }; cargoDeps = rustPlatform.importCargoLock { lockFile = ./Cargo.lock; };
patches = [ ];
});
eww-wayland = final.eww.override { withWayland = true; };
}; };
packages = rec { packages = nixpkgs.lib.genAttrs targetSystems (system:
default = eww; let
eww = mkEww { }; pkgs = pkgsFor system;
eww-wayland = mkEww { wayland = true; }; in
}; (self.overlays.default pkgs pkgs) // {
default = self.packages.${system}.eww;
}
);
devShells.default = pkgs.mkShell { devShells = nixpkgs.lib.genAttrs targetSystems (system:
packages = builtins.attrValues { let
inherit (toolchain) pkgs = pkgsFor system;
cargo rust = mkRustToolchain pkgs;
rustc in
rust-src {
clippy-preview default = pkgs.mkShell {
rustfmt-preview; packages = with pkgs; [
rust
inherit (pkgs) rust-analyzer-unwrapped
rust-analyzer
gcc gcc
gtk3 gtk3
gtk-layer-shell gtk-layer-shell
pkg-config pkg-config
deno deno
mdbook; mdbook
}; ];
RUST_SRC_PATH = "${toolchain.rust-src}/lib/rustlib/src/rust/library"; RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library";
};
}
);
}; };
});
} }

View file

@ -1 +0,0 @@
nightly-2022-04-13

4
rust-toolchain.toml Normal file
View file

@ -0,0 +1,4 @@
[toolchain]
channel = "nightly-2022-04-13"
components = [ "rust-src" ]
profile = "default"