From eee20cba840dc266798fe22c98d02e9a0e450ceb Mon Sep 17 00:00:00 2001 From: Dave Gallant Date: Sun, 31 Jul 2022 01:34:31 +0000 Subject: [PATCH] Add nix-ld and fix for vscode remote wsl extension --- Makefile | 3 +- flake.lock | 52 ++++++++++++++++++++++++++++++- flake.nix | 4 +++ machines/aether/configuration.nix | 3 ++ machines/aether/nix-ld-config.nix | 31 ++++++++++++++++++ packages/common.nix | 1 + 6 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 machines/aether/nix-ld-config.nix diff --git a/Makefile b/Makefile index 9e806cc..52e2626 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,8 @@ HOSTNAME ?= $(shell hostname) UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Linux) - SWITCH_CMD := nixos-rebuild --use-remote-sudo -I nixos-config="machines/$(HOSTNAME)/configuration.nix" switch --flake '.\#' + SWITCH_CMD := nixos-rebuild --use-remote-sudo -I nixos-config="machines/$(HOSTNAME)/configuration.nix" switch --flake '.\#' \ + --impure # Impure because of: https://discourse.nixos.org/t/vscode-remote-wsl-extension-works-on-nixos-without-patching-thanks-to-nix-ld/14615 endif ifeq ($(UNAME_S),Darwin) SWITCH_CMD := exec darwin-rebuild switch --flake . diff --git a/flake.lock b/flake.lock index 84d412e..1029b4c 100644 --- a/flake.lock +++ b/flake.lock @@ -116,6 +116,25 @@ "type": "github" } }, + "nix-ld": { + "inputs": { + "nixpkgs": "nixpkgs_2", + "utils": "utils_2" + }, + "locked": { + "lastModified": 1652641841, + "narHash": "sha256-TTBz20XR2vmvOSDu8hXcbHbOEI0t/IWq8vZuRKyep1E=", + "owner": "Mic92", + "repo": "nix-ld", + "rev": "c25cc4b5ec65f03c2bb96f927ae724a59c51d7ee", + "type": "github" + }, + "original": { + "owner": "Mic92", + "repo": "nix-ld", + "type": "github" + } + }, "nixos-hardware": { "locked": { "lastModified": 1658401027, @@ -149,6 +168,21 @@ } }, "nixpkgs_2": { + "locked": { + "lastModified": 1652536154, + "narHash": "sha256-d+y62beDhz2/l65SBAkxwtvTBzw3hgU1kECogyncKYM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ddfb78791c95019d3d102d9dcb2631112ca7661f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 1658380158, "narHash": "sha256-DBunkegKWlxPZiOcw3/SNIFg93amkdGIy2g0y/jDpHg=", @@ -169,8 +203,9 @@ "darwin": "darwin", "home-manager": "home-manager", "neovim-nightly-overlay": "neovim-nightly-overlay", + "nix-ld": "nix-ld", "nixos-hardware": "nixos-hardware", - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_3" } }, "utils": { @@ -187,6 +222,21 @@ "repo": "flake-utils", "type": "github" } + }, + "utils_2": { + "locked": { + "lastModified": 1652372896, + "narHash": "sha256-lURGussfF3mGrFPQT3zgW7+RC0pBhbHzco0C7I+ilow=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "0d347c56f6f41de822a4f4c7ff5072f3382db121", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 54b2fd0..823b48b 100644 --- a/flake.nix +++ b/flake.nix @@ -13,6 +13,8 @@ neovim-nightly-overlay.url = "github:nix-community/neovim-nightly-overlay"; + nix-ld.url = "github:Mic92/nix-ld"; + darwin = { url = "github:lnl7/nix-darwin"; inputs.nixpkgs.follows = "nixpkgs"; @@ -25,6 +27,7 @@ home-manager, nixpkgs, nixos-hardware, + nix-ld, ... } @ inputs: { nixosConfigurations = let @@ -95,6 +98,7 @@ modules = [ ./machines/aether/configuration.nix + nix-ld.nixosModules.nix-ld ] ++ defaultModules; }; diff --git a/machines/aether/configuration.nix b/machines/aether/configuration.nix index 4422d9d..52e4f27 100644 --- a/machines/aether/configuration.nix +++ b/machines/aether/configuration.nix @@ -10,10 +10,13 @@ with lib; let in { imports = [ "${modulesPath}/profiles/minimal.nix" + ./nix-ld-config.nix nixos-wsl.nixosModules.wsl ]; + nix-ld-config.enable = true; + nixpkgs.config.allowUnfree = true; system.stateVersion = "unstable"; diff --git a/machines/aether/nix-ld-config.nix b/machines/aether/nix-ld-config.nix new file mode 100644 index 0000000..ad10288 --- /dev/null +++ b/machines/aether/nix-ld-config.nix @@ -0,0 +1,31 @@ +{ + lib, + pkgs, + config, + ... +}: +with lib; let + cfg = config.nix-ld-config; + ldEnv = { + NIX_LD_LIBRARY_PATH = with pkgs; + makeLibraryPath [ + stdenv.cc.cc + ]; + NIX_LD = removeSuffix "\n" (builtins.readFile "${pkgs.stdenv.cc}/nix-support/dynamic-linker"); + }; + ldExports = mapAttrsToList (name: value: "export ${name}=${value}") ldEnv; + joinedLdExports = concatStringsSep "\n" ldExports; +in { + options.nix-ld-config = { + enable = mkEnableOption "nix-ld config module"; + user = mkOption { + type = types.str; + description = "The name of user you want to configure for using VSCode's Remote WSL extension."; + default = "dave"; + }; + }; + config = mkIf cfg.enable { + environment.variables = ldEnv; + home-manager.users.${cfg.user}.home.file.".vscode-server/server-env-setup".text = joinedLdExports; + }; +} diff --git a/packages/common.nix b/packages/common.nix index 1aafbe2..c21bd70 100644 --- a/packages/common.nix +++ b/packages/common.nix @@ -21,6 +21,7 @@ in { unzip viddy xclip + wget xdg_utils yq-go zip