From 3ed43b1b8afa4cbe7170d9175252fc0c37bb8b53 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 1 Feb 2025 15:45:58 -0500 Subject: [PATCH] Configure rustup toolchain, cargo credentials, and put dependencies under cargo. --- nix/configuration/roles/rust/default.nix | 93 ++++++++++++++++++- .../roles/rust/files/rustup_settings.toml | 5 + 2 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 nix/configuration/roles/rust/files/rustup_settings.toml diff --git a/nix/configuration/roles/rust/default.nix b/nix/configuration/roles/rust/default.nix index 1a97976..a2853f5 100644 --- a/nix/configuration/roles/rust/default.nix +++ b/nix/configuration/roles/rust/default.nix @@ -1,3 +1,6 @@ +# MANUAL: rustup target add x86_64-unknown-linux-musl +# MANUAL: rustup target add wasm32-unknown-unknown +# MANUAL: rustup component add rustc-codegen-cranelift { config, lib, @@ -5,6 +8,14 @@ ... }: +let + cargo_wrapped = + package: prog: + pkgs.writeShellScriptBin "${prog}" '' + export PATH="$PATH:${lib.makeBinPath [ pkgs.clang ]}" + exec ${package}/bin/${prog} "''${@}" + ''; +in { imports = [ ]; @@ -37,17 +48,89 @@ ".cargo/config.toml" = { source = ./files/cargo_config.toml; }; - # # TODO: Figure out what to do with credentials. - # ".cargo/credentials.toml" = { - # source = ./files/cargo_credentials.toml; - # }; + ".rustup/settings.toml" = { + source = ./files/rustup_settings.toml; + }; }; }; + environment.persistence."/state" = lib.mkIf (!config.me.buildingIso) { + hideMounts = true; + users.talexander = { + directories = [ + { + directory = ".rustup"; + user = "talexander"; + group = "talexander"; + mode = "0755"; + } + { + directory = ".cargo/registry"; + user = "talexander"; + group = "talexander"; + mode = "0755"; + } + ]; + }; + }; + + systemd.services.link-rust-creds = { + # Contains credentials so it cannot be added to the nix store + enable = true; + description = "link-rust-creds"; + wantedBy = [ "multi-user.target" ]; + wants = [ "multi-user.target" ]; + after = [ "multi-user.target" ]; + # path = with pkgs; [ + # zfs + # ]; + unitConfig.DefaultDependencies = "no"; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = "yes"; + }; + script = '' + if [ -e /persist/manual/rust/cargo_credentials.toml ]; then + install --directory --owner talexander --group talexander --mode 0755 /home/talexander/.cargo + ln -s /persist/manual/rust/cargo_credentials.toml /home/talexander/.cargo/credentials.toml + fi + ''; + preStop = '' + rm -f /home/talexander/.cargo/credentials.toml + ''; + }; + + nixpkgs.overlays = [ + (final: prev: { + rustup = pkgs.symlinkJoin { + name = "rustup"; + paths = + (builtins.map (cargo_wrapped prev.rustup) [ + "cargo" + "cargo-clippy" + "cargo-fmt" + "cargo-miri" + "clippy-driver" + "rls" + "rust-analyzer" + "rust-gdb" + "rust-gdbgui" + "rust-lldb" + "rustc" + "rustdoc" + "rustfmt" + "rustup" + ]) + ++ [ + prev.rustup + ]; + buildInputs = [ pkgs.makeWrapper ]; + }; + }) + ]; } ] ); } # TODO: Install clippy, cranelift, rust-src -# TODO: Install rust targets x86_64-unknown-linux-musl and wasm32-unknown-unknown diff --git a/nix/configuration/roles/rust/files/rustup_settings.toml b/nix/configuration/roles/rust/files/rustup_settings.toml new file mode 100644 index 0000000..22f2e5c --- /dev/null +++ b/nix/configuration/roles/rust/files/rustup_settings.toml @@ -0,0 +1,5 @@ +default_toolchain = "nightly-x86_64-unknown-linux-gnu" +profile = "default" +version = "12" + +[overrides]