1

After moving to NixOS from Arch Linux, I installed asdf-vm (using git; commit 0adc6c1). However, I noticed that installing any rust binary fails:

$ LC_ALL=C asdf install rust stable
info: downloading installer
main: line 494: /tmp/tmp.XmUYT687x4/rustup-init: cannot execute: required file not found

This also happens trying to install a binary for python:

$ asdf install python 3.11.3
python-build 3.11.3 /home/jorge/.asdf/installs/python/3.11.3
Downloading Python-3.11.3.tar.xz...
-> https://www.python.org/ftp/python/3.11.3/Python-3.11.3.tar.xz
Installing Python-3.11.3...

BUILD FAILED (NixOS 23.05 using python-build 2.3.17-10-g920ef145)

Inspect or clean up the working tree at /tmp/python-build.20230513230601.298920
Results logged to /tmp/python-build.20230513230601.298920.log

Last 10 log lines:
  File "/tmp/python-build.20230513230601.298920/Python-3.11.3/Lib/ensurepip/__init__.py", line 202, in _bootstrap
    return _run_pip([*args, *_PACKAGE_NAMES], additional_paths)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/python-build.20230513230601.298920/Python-3.11.3/Lib/ensurepip/__init__.py", line 103, in _run_pip
    return subprocess.run(cmd, check=True).returncode
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/python-build.20230513230601.298920/Python-3.11.3/Lib/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/tmp/python-build.20230513230601.298920/Python-3.11.3/python', '-W', 'ignore::DeprecationWarning', '-c', '\nimport runpy\nimport sys\nsys.path = [\'/tmp/tmplx6zl6yc/setuptools-65.5.0-py3-none-any.whl\', \'/tmp/tmplx6zl6yc/pip-22.3.1-py3-none-any.whl\'] + sys.path\nsys.argv[1:] = [\'install\', \'--no-cache-dir\', \'--no-index\', \'--find-links\', \'/tmp/tmplx6zl6yc\', \'--root\', \'/\', \'--upgrade\', \'setuptools\', \'pip\']\nrunpy.run_module("pip", run_name="__main__", alter_sys=True)\n']' returned non-zero exit status 1.
make: *** [Makefile:1858: install] Error 1

Installing binaries for Go works fine, but executing go fails:

$ LC_ALL=C go
/home/jorge/.asdf/lib/commands/command-exec.bash: line 28: /home/jorge/.asdf/installs/golang/1.19/go/bin/go: cannot execute: required file not found

Same thing for NodeJS' npm:

$ LC_ALL=C npm
/home/jorge/.asdf/lib/commands/command-exec.bash: line 28: /home/jorge/.asdf/installs/nodejs/20.1.0/bin/node: cannot execute: required file not found

you may wonder if the files missing truly exists at the locations shown in the errors, and well, they do:

$ tree -L 5
.
├── golang
│   └── 1.19
│       └── go
│           ├── api
│           ├── bin
│           │   ├── go
│           │   └── gofmt
...
├── nodejs
│   └── 20.1.0
│       ├── bin
│       │   ├── corepack -> ../lib/node_modules/corepack/dist/corepack.js
│       │   ├── node
│       │   ├── npm -> ../lib/node_modules/npm/bin/npm-cli.js
│       │   └── npx -> ../lib/node_modules/npm/bin/npx-cli.js
...
│       ├── lib
│       │   └── node_modules
│       │       ├── corepack
│       │       └── npm
│       ├── LICENSE
│       ├── README.md
│       └── share
│           ├── doc
│           │   └── node
│           └── man
│               └── man1
├── python // empty
└── rust
    ├── 1.69.0 // empty
    └── stable // empty

117 directories, 457 files

I'm not sure what's wrong. I manage my configuration with home-manager and install some packages system-wide changing things in /etc/nixos/configuration.nix, maybe I'm missing something important in my installation?

# home.nix, for home-manager:
{ pkgs, lib, config, ... }:
let
  inherit (pkgs) stdenv;
  inherit (lib) mkIf;

  # verifica si estamos en macOS
  onMac = stdenv.isDarwin;

  # verifica si `yay` esta instalado y existe en PATH
  hasYay = pkgs.runCommand "yay-in-path" { } "command -v yay > /dev/null" == 0;

  # obtiene el nombre del host
  hostname = builtins.getEnv "HOSTNAME";

  # revisa si estamos usando la compu del trabajo XD
  atWork = lib.strings.hasInfix "CR-400" hostname;
in {
  # Home Manager needs a bit of information about you and the paths it should
  # manage.
  home.username = "jorge";
  home.homeDirectory =
    if (stdenv.isDarwin) then "/Users/jorge" else "/home/jorge";
  nixpkgs.config.allowUnfree = true;

  # This value determines the Home Manager release that your configuration is
  # compatible with. This helps avoid breakage when a new Home Manager release
  # introduces backwards incompatible changes.
  #
  # You should not change this value, even if you update Home Manager. If you do
  # want to update the value, then make sure to first check the Home Manager
  # release notes.
  home.stateVersion = "22.11"; # Please read the comment before changing.

  # The home.packages option allows you to install Nix packages into your
  # environment.
  home.packages = with pkgs; [
    # fuentes
    noto-fonts
    noto-fonts-cjk
    noto-fonts-emoji
    mplus-outline-fonts.githubRelease
    (nerdfonts.override { fonts = [ "FiraCode" "DroidSansMono" "Iosevka" ]; })
    iosevka-comfy.comfy
    iosevka-comfy.comfy-motion-duo
    emacs-all-the-icons-fonts

    # linea de comandos
    xcp
    ripgrep
    thefuck
    tree
    fd
    jq
    d2

    # git
    git-crypt

    # dependencias de Emacs
    aspell
    aspellDicts.en
    aspellDicts.en-computers
    aspellDicts.es
    ccls
    nixfmt
    shellcheck

    # dependencias de Doom Emacs
    python311Packages.grip
    rust-analyzer
    plantuml
    html-tidy
    nodePackages_latest.stylelint
    nodePackages_latest.js-beautify
    nodePackages.prettier
  ];

  # Home Manager is pretty good at managing dotfiles. The primary way to manage
  # plain files is through 'home.file'.
  home.file = {
    "zellij-layouts-41" = {
      enable = true;
      target = ".config/zellij/layouts/41.kdl";
      text = ''
        layout {
               pane size=1 borderless=true {
                    plugin location="zellij:compact-bar"
               }
               pane split_direction="horizontal" {
                    pane split_direction="vertical" {
                         pane name="main"
                         pane split_direction="horizontal" {
                              pane name="aux. alpha"
                              pane name="aux. bravo"
                              pane name="aux. charlie"
                         }
                    }
                    pane size="20%" name="command-line" focus=true
               }
               pane size=2 borderless=true {
                    plugin location="zellij:status-bar"
               }
        }
      '';
    };
  };

  home = {
    sessionVariables = { EDITOR = "emacs"; };
    # ajusta $PATH
    sessionPath =
      [ "$HOME/.asdf/shims" "$HOME/.config/emacs/bin" "$HOME/.emacs.d/bin" ];
  };

  fonts.fontconfig.enable = true;

  programs.starship = {
    enable = true;
    # Configuration written to ~/.config/starship.toml
    settings = {
      add_newline = true;

      character = {
        success_symbol = "[➜](bold green) ";
        error_symbol = "[](bold red) ";
      };
    };
  };

  programs.zsh = {
    enable = true;
    history = {
      size = 10000;
      save = 100000;
      path = "${config.xdg.dataHome}/zsh/history";
      ignoreDups = true;
      ignorePatterns = [ "rm *" "pkill *" "killall *" "cd *" "mv *" ];
      ignoreSpace = true;
    };
    shellAliases = {
      ip = "ip --color=auto";
      cp = "xcp";
      mv = "mv -i";
      rm = " rm -v";
      ln = "ln -i";
      chown = "chown --preserve-root";
      chmod = "chmod --preserve-root";
      chgrp = "chgrp --preserve-root";
      cls = ''
        echo -ne "\033c"
      '';

    } // lib.optionalAttrs (hasYay) {
      yay = ''
        env PATH="''${PATH//~\/.asdf\/shims:/}" yay
      '';
    };

    enableCompletion = true;
    enableAutosuggestions = true;
    enableSyntaxHighlighting = true;
    dirHashes = {
      dev = "$HOME/code";
      gamedev = "$HOME/sotsfgs/proyectos";
      tmp = "/tmp";
    };

    zplug = {
      enable = true;
      plugins = [
        { name = "zsh-users/zsh-autosuggestions"; }
        { name = "marlonrichert/zsh-autocomplete"; }
        {
          name = "plugins/asdf";
          tags = [ "from:oh-my-zsh" ];
        }
        {
          name = "plugins/brew";
          tags = [ "from:oh-my-zsh" ''if:"[[ $OSTYPE == *darwin* ]]"'' ];
        }
      ];
    };
  };

  programs.fzf = {
    enable = true;
    enableZshIntegration = true;
    defaultOptions =
      [ "--height 40%" "--layout=reverse" "--border" "--inline-info" ];
  };

  programs.bat = {
    enable = true;
    config = { tabs = "8"; };
  };

  programs.git = {
    enable = true;
    package = pkgs.gitAndTools.gitFull;
    userEmail = "jorge@esavara.cr";
    userName = "Jorge Javier Araya Navarro";
    signing = mkIf (!atWork) {
      key = "F15FE636C8AEC2D9";
      signByDefault = false;
    };

    extraConfig = {
      core = { whitespace = "trailing-space,space-before-tab"; };
      color = { ui = "auto"; };
      rerere = { enabled = "true"; };
      rebase = { autoSquash = "true"; };
      github = { user = "shackra"; };
      init.defaultBranch = "master"; # a classic
      url = mkIf atWork {
        "ssh://git@github.com/" = { insteadOf = "https://github.com/"; };
      };
    };

    lfs = { enable = true; };

    ignores = [
      "*~"
      "*.swp"
      ".ccls-cache"
      "compile_commands.json"
      "shell.nix"
      ".tool-versions"
      ".DS_Store"
    ];
  };

  programs.exa = {
    enable = true;
    enableAliases = true;
    icons = true;
    extraOptions = [ "--group-directories-first" "--header" ];
    git = true;
  };

  services.gpg-agent = {
    enable = stdenv.isLinux;

    defaultCacheTtl = 86400;
    defaultCacheTtlSsh = 86400;
    maxCacheTtl = 86400;
    maxCacheTtlSsh = 86400;
    enableSshSupport = true;
  };

  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;
}
# configuration.nix, for the system configuration

# Edit this configuration file to define what should be installed on
# your system.  Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).

{ config, pkgs, ... }:
let

  # truco de https://discourse.nixos.org/t/gdm-monitor-configuration/6356/4
  monitorsXmlContent = builtins.readFile /home/jorge/.config/monitors.xml;
  monitorsConfig = pkgs.writeText "gdm_monitors.xml" monitorsXmlContent;
in {
  imports = [ # Include the results of the hardware scan.
    ./hardware-configuration.nix
  ];

  # Bootloader.
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;
  boot.loader.efi.efiSysMountPoint = "/boot/efi";
  # Copied from virtualisation.lxd.recommendedSysctlSettings
  boot.kernel.sysctl = {
    "fs.inotify.max_queued_events" = 1048576;
    "fs.inotify.max_user_instances" = 1048576;
    "fs.inotify.max_user_watches" = 1048576;
    "vm.max_map_count" = 2147483642; # use by Steam Deck
    "kernel.dmesg_restrict" = 1;
    "net.ipv4.neigh.default.gc_thresh3" = 8192;
    "net.ipv6.neigh.default.gc_thresh3" = 8192;
    "kernel.keys.maxkeys" = 2000;
  };

  systemd.tmpfiles.rules =
    [ "L+ /run/gdm/.config/monitors.xml - - - - ${monitorsConfig}" ];

  networking.hostName = "woody"; # Define your hostname.
  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.

  # Configure network proxy if necessary
  # networking.proxy.default = "http://user:password@proxy:port/";
  # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";

  # Enable networking
  networking.networkmanager.enable = true;

  # Set your time zone.
  time.timeZone = "America/Costa_Rica";

  # Select internationalisation properties.
  i18n.defaultLocale = "es_CR.UTF-8";

  i18n.extraLocaleSettings = {
    LC_ADDRESS = "es_CR.UTF-8";
    LC_IDENTIFICATION = "es_CR.UTF-8";
    LC_MEASUREMENT = "es_CR.UTF-8";
    LC_MONETARY = "es_CR.UTF-8";
    LC_NAME = "es_CR.UTF-8";
    LC_NUMERIC = "es_CR.UTF-8";
    LC_PAPER = "es_CR.UTF-8";
    LC_TELEPHONE = "es_CR.UTF-8";
    LC_TIME = "es_CR.UTF-8";
  };

  # Enable the X11 windowing system.
  services.xserver.enable = true;
  services.xserver.videoDrivers = [ "nvidia" ];

  # Enable the GNOME Desktop Environment.
  services.xserver.displayManager.gdm.enable = true;
  services.xserver.desktopManager.gnome.enable = true;

  # Configure keymap in X11
  services.xserver = {
    layout = "us";
    xkbVariant = "";
  };

  # Enable CUPS to print documents.
  services.printing.enable = true;
  services.printing.drivers = [ pkgs.hplip ];
  services.avahi.enable = true;
  services.avahi.nssmdns = true;
  # for a WiFi printer
  services.avahi.openFirewall = true;

  # activa accesorios para Xbox one
  hardware.xone.enable = true;

  # Steam
  hardware.steam-hardware.enable = true;
  programs.steam = {
    enable = true;
    remotePlay.openFirewall = true;
  };

  # Enable sound with pipewire.
  sound.enable = true;
  hardware.pulseaudio.enable = false;
  security.rtkit.enable = true;
  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
    # If you want to use JACK applications, uncomment this
    #jack.enable = true;

    # use the example session manager (no others are packaged yet so this is enabled by default,
    # no need to redefine it in your config for now)
    #media-session.enable = true;
  };

  # Enable touchpad support (enabled default in most desktopManager).
  # services.xserver.libinput.enable = true;

  # Ledger
  hardware.ledger.enable = true;

  # habilita ZSH
  programs.zsh.enable = true;

  # habilita kdeconnect
  programs.kdeconnect.enable = true;

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.jorge = {
    isNormalUser = true;
    description = "Jorge Javier Araya Navarro";
    extraGroups = [ "networkmanager" "wheel" "docker" "libvirtd" ];
    shell = pkgs.zsh;
    packages = with pkgs; [ firefox nextcloud-client brave bitwarden-cli ];
  };

  # Allow unfree packages
  nixpkgs.config.allowUnfree = true;
  nixpkgs.config.permittedInsecurePackages =
    [ "electron-11.5.0" "electron-21.4.0" "python-2.7.18.6" ];

  # List packages installed in system profile. To search, run:
  # $ nix search wget
  environment.systemPackages = with pkgs; [
    # otros
    bindfs

    # fuentes
    noto-fonts
    noto-fonts-cjk
    noto-fonts-emoji
    mplus-outline-fonts.githubRelease
    (nerdfonts.override { fonts = [ "FiraCode" "DroidSansMono" "Iosevka" ]; })
    iosevka
    iosevka-comfy.comfy
    iosevka-comfy.comfy-motion-duo
    fira
    fira-code

    # linea de comandos
    aspell
    aspellDicts.en
    aspellDicts.en-computers
    aspellDicts.es
    bitwarden
    bitwarden-cli
    bitwarden-menu
    butler
    ccls
    clang
    cmake
    cmake-format
    cmake-language-server
    coreutils
    curl
    d2
    dig
    emacs
    evince
    fd
    firefox-devedition
    git
    git-crypt
    gnumake
    html-tidy
    hunspell
    hunspellDicts.en_US
    hunspellDicts.es_CR
    hunspellDicts.es_ES
    jq
    libreoffice-fresh
    nixfmt
    nodePackages.prettier
    nodePackages_latest.js-beautify
    nodePackages_latest.stylelint
    plantuml
    python311Packages.grip
    ripgrep
    rust-analyzer
    shellcheck
    stow
    thefuck
    tree
    wget
    xcp
    libtool
    clipgrab
    texlive.combined.scheme-full
    texlab
    lua53Packages.digestif

    alacritty
    firefox
    gimp
    inkscape
    notion-app-enhanced
    signal-desktop-beta
    smplayer
    spotify
    tdesktop
    teams
    todoist-electron
    discord
    slack
    vlc
    zoom-us
    pdfarranger
    hplip
    newsflash
    avidemux
    audacity
    libsForQt5.kdenlive
    mediainfo
    # davinci-resolve
    deluge
    xsane

    # entretenimiento y juegos
    itch
    prismlauncher
    protonup-qt
    rpcs3
    heroic

    # Gnome
    gnomeExtensions.auto-move-windows
    gnomeExtensions.clipman
    gnomeExtensions.gnome-bedtime
    gnomeExtensions.memento-mori
    gnomeExtensions.no-overview
    gnomeExtensions.pop-shell
    gnomeExtensions.stonks
    gnomeExtensions.time-awareness
    gnomeExtensions.wallpaper-switcher
    gnomeExtensions.weather
    gnomeExtensions.weather-oclock
    gnomeExtensions.zilence
    gnomeExtensions.appindicator
    gnome.gnome-tweaks

    # privacidad
    protonmail-bridge
    protonvpn-gui

    # docker
    # el paquete docker ya es activado como servicio más abajo
    kubecolor
    kubectl
    kubectx
    docker-compose

    # virtualization
    virt-manager

    # dependencias para construir Python
    gcc
    zlib
    libffi
    openssl
    bzip2
    readline
    sqlite
    xz

    # Android
    scrcpy

    # cripto
    ledger-live-desktop
  ];

  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  # programs.mtr.enable = true;
  # programs.gnupg.agent = {
  #   enable = true;
  #   enableSSHSupport = true;
  # };

  # List services that you want to enable:

  # Enable the OpenSSH daemon.
  services.openssh.enable = true;
  virtualisation.docker = {
    enable = true;
    autoPrune.enable = true;
  };
  virtualisation.libvirtd.enable = true;
  programs.dconf.enable = true;

  # Open ports in the firewall.
  networking.firewall.allowedTCPPorts = [ 22 ];
  # networking.firewall.allowedUDPPorts = [ ... ];
  # Or disable the firewall altogether.
  # networking.firewall.enable = false;

  # This value determines the NixOS release from which the default
  # settings for stateful data, like file locations and database versions
  # on your system were taken. It‘s perfectly fine and recommended to leave
  # this value at the release version of the first install of this system.
  # Before changing this value read the documentation for this option
  # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
  system.stateVersion = "23.05"; # Did you read the comment?

}
shackra
  • 277
  • 3
  • 16
  • 56
  • were you able to figure this one out? I'm in exactly the same situation: installed `asdf-vm` via Home Manager, and I can add the plugins and install the packages, but they aren't successfully _registered_ (in `NixOS`) when I add them to `$HOME/.tool-versions`. – x80486 Jun 27 '23 at 20:17
  • @x80486 that's because compiled binaries from outside NixOS don't work well with the OS. What I did was abandoning the idea completely and installing what I needed from NixOS repos. Some people use direnv and flakes to cater whatever need their projects may have without screwing their "system-wide" installation of tools (like Go version, Node version, etc), you may want to see https://dev.jmgilman.com/environment/tools/direnv/ – shackra Jun 28 '23 at 21:09

2 Answers2

0

The file that are missing are not the binaries that you are executing, but some of their dinamically linked libraries which are not stored in the usual place in NixOS.

This makes it, in general, quite inconvenient to download pre-compiled binaries on NixOS.

The solution here would be to install asdf-vm through nix, rather than by hand, because packages in the repo are duly patched to find the libraries where they actually are.

jthulhu
  • 7,223
  • 2
  • 16
  • 33
  • I now installed asdf from the NixOS repositories, removed `~/.asdf` and restarted. Installed the Go plugin, installed Go version 1.20.4 and put it as the global version, I even used `asdf reshim` but despite all that got `/nix/store/jzblglwgwnwvnnh5zq6rh4v2d35npk58-asdf-vm-0.11.3/share/asdf-vm/lib/commands/command-exec.bash: line 28: /home/jorge/.asdf/installs/golang/1.20.4/go/bin/go: cannot execute: required file not found` asdf is located at `/home/jorge/.nix-profile/bin/asdf` – shackra May 14 '23 at 06:10
  • @shackra I am not too familiar with the `asdf` tool, but from what I read it seems that each plugin has some specific dependencies. Did you install these dependencies with Nix? – jthulhu May 14 '23 at 08:01
0

TLDR

Add this to your ~/.zshrc

# effectively this file (https://github.com/asdf-vm/asdf/blob/v0.11.3/asdf.sh)
# from inside /nix/store 
. $(dirname $(dirname $(readlink -f $(which asdf))))/share/asdf-vm/asdf.sh

Explanation

If you look at the official asdf installation instructions, they say:

  • clone the repo to ~/.asdf
  • source ~/.asdf/asdf.sh (e.g. this file)

Now, if you install asdf-vm from nix:

  • the asdf repo is cloned in /nix/store
    • this is how nix works, everything gets cloned to /nix/store, rather than in your $HOME
  • and you get a nice command (asdf) in ~/.nix-profile/bin, which is part of your $PATH

If you poke around /nix/store, you'll realise the asdf repo is in there, so source the asdf.sh file with the command I used above.

jb007
  • 243
  • 1
  • 5
  • 17