Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notes about the buildFHSUserEnv #1

Open
PedroRegisPOAR opened this issue Mar 21, 2021 · 1 comment
Open

Notes about the buildFHSUserEnv #1

PedroRegisPOAR opened this issue Mar 21, 2021 · 1 comment

Comments

@PedroRegisPOAR
Copy link
Contributor

PedroRegisPOAR commented Mar 21, 2021

Some notes

Here I am summarizing some stuff that I found about buildFHSUserEnv and related stuff.

TODOs:

nix \
develop \
--expr \
'
  (
    let
      nixpkgs = (builtins.getFlake "github:NixOS/nixpkgs/683f2f5ba2ea54abb633d0b17bc9f7f6dede5799"); 
      pkgs = import nixpkgs {};
    in
      pkgs.stdenv.mkDerivation {
        name = "python-env";
        dontUnpack = true; 
        buildInputs = with pkgs;[ (python3.withPackages (p: with p; [ pyttsx3 ])) espeak-classic ];
        
        buildPhase = "mkdir $out";
        dontInstall = true;
        LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ 
            pkgs.pythonManylinuxPackages.manylinux1Package
            pkgs.pythonManylinuxPackages.manylinux2010Package                                                                  
            pkgs.pythonManylinuxPackages.manylinux2014Package 
            pkgs.xorg.libX11 
            pkgs.glib 
            pkgs.stdenv.cc.cc.lib 
            pkgs.zlib
        ];
    }
  )
'

Cool:

nix \
shell \
--impure \
--expr \
'
  (
    let 
      pkgs = (builtins.getFlake "github:NixOS/nixpkgs/683f2f5ba2ea54abb633d0b17bc9f7f6dede5799").legacyPackages.${builtins.currentSystem}; 
    in 
      pkgs.buildFHSUserEnv (
        pkgs.appimageTools.defaultFhsEnvArgs 
        // 
        { 
          name = "fhs"; 
          profile = "export FHS=1"; 
          runScript = "bash"; 
          targetPkgs = pkgs: (with pkgs; [ hello cowsay ]); }
      )
    )
' \
--command fhs -c 'hello | cowsay'

Refs. :

# export NIXPKGS_ALLOW_INSECURE=1

nix shell --impure --expr \
'(let pkgs = (builtins.getFlake "github:NixOS/nixpkgs").legacyPackages.${builtins.currentSystem}; in pkgs.buildFHSUserEnv (pkgs.appimageTools.defaultFhsEnvArgs // { name = "fhs"; profile = "export FHS=1; export FONTCONFIG_FILE=${pkgs.fontconfig.out}/etc/fonts/fonts.conf"; runScript = "bash"; targetPkgs = pkgs: (with pkgs; [ 

hello 
cowsay 

      gtk3
      bashInteractive
      gnome.zenity
      # python2
      xorg.xrandr
      which
      perl
      xdg-utils
      iana-etc
      krb5
      gsettings-desktop-schemas
      hicolor-icon-theme # dont show a gtk warning about hicolor not being installed

      # extra
      fuse
      fuse3
      (writeShellScriptBin "sudo" "true") # suid wrappers messing with suff
      pulseaudio

      desktop-file-utils
      xorg.libXcomposite
      xorg.libXtst
      xorg.libXrandr
      xorg.libXext
      xorg.libX11
      xorg.libXfixes
      libGL

      gst_all_1.gstreamer
      gst_all_1.gst-plugins-ugly
      gst_all_1.gst-plugins-base
      libdrm
      xorg.xkeyboardconfig
      xorg.libpciaccess

      glib
      gtk2
      bzip2
      zlib
      gdk-pixbuf

      xorg.libXinerama
      xorg.libXdamage
      xorg.libXcursor
      xorg.libXrender
      xorg.libXScrnSaver
      xorg.libXxf86vm
      xorg.libXi
      xorg.libSM
      xorg.libICE
      gnome2.GConf
      freetype
      (curl.override { gnutlsSupport = true; opensslSupport = false; })
      nspr
      nss
      fontconfig
      cairo
      pango
      expat
      dbus
      cups
      libcap
      SDL2
      libusb1
      udev
      dbus-glib
      atk
      at-spi2-atk
      libudev0-shim

      xorg.libXt
      xorg.libXmu
      xorg.libxcb
      xorg.xcbutil
      xorg.xcbutilwm
      xorg.xcbutilimage
      xorg.xcbutilkeysyms
      xorg.xcbutilrenderutil
      libGLU
      libuuid
      libogg
      libvorbis
      SDL
      SDL2_image
      glew110
      openssl
      libidn
      tbb
      wayland
      mesa
      libxkbcommon

      flac
      freeglut
      libjpeg
      libpng12
      libsamplerate
      libmikmod
      libtheora
      libtiff
      pixman
      speex
      SDL_image
      SDL_ttf
      SDL_mixer
      SDL2_ttf
      SDL2_mixer
      libappindicator-gtk2
      libcaca
      libcanberra
      libgcrypt
      libvpx
      librsvg
      xorg.libXft
      libvdpau
      alsa-lib

      harfbuzz
      e2fsprogs
      libgpg-error
      keyutils.lib
      libjack2
      fribidi
      p11-kit

      gmp

      # libraries not on the upstream include list, but nevertheless expected
      # by at least one appimage
      libtool.lib # for Synfigstudio
      xorg.libxshmfence # for apple-music-electron
      at-spi2-core

]); }))' \
--command fhs -c 'hello | cowsay' 

TODO:

https://unix.stackexchange.com/questions/522822/different-methods-to-run-a-non-nixos-executable-on-nixos

Many insteresting results found in https://gist.github.com/search?p=8&q=buildFHSUserEnv, a lot of things to study:

Really cool: fhs-nix-study

https://github.com/NixOS/nixpkgs/blob/87b215d5f72cd51ea2b649e452c107c9e14f4abf/pkgs/applications/editors/android-studio/common.nix#L104-L106

TODO: make a minimal example of this:

nativeBuildInputs = [ dpkg ];
unpackCmd = "dpkg -x $curSrc .";
From: evanjs/nixos_cfg

TODOs:

podman \
run \
--interactive=true \
--tty=true \
--rm=true \
--name=tmpfs01 \
fedora:34 \
bash \
-c \
'df -h'

TODO:

podman \
run \
--interactive=true \
--tty=true \
--rm=true \
--name=tmpfs01 \
--mount type=tmpfs,tmpfs-size=512M,destination=/tmp \
fedora:34 \
bash \
-c \
'df -h'
Filesystem      Size  Used Avail Use% Mounted on
fuse-overlayfs   64G  5.6G   59G   9% /
tmpfs           512M     0  512M   0% /tmp
tmpfs            64M     0   64M   0% /dev
tmpfs           1.5G   60K  1.5G   1% /etc/hosts
shm              63M     0   63M   0% /dev/shm
cgroup          1.0M     0  1.0M   0% /sys/fs/cgroup
udev            7.4G     0  7.4G   0% /dev/tty

TODO:

nix shell --impure nixpkgs#vscode-fhs
nix  \
shell  \
--impure  \
--expr  \
'(
  with builtins.getFlake "nixpkgs";  
  with legacyPackages.${builtins.currentSystem}; 
  (
    let fhs = pkgs.buildFHSUserEnv {
      name = "fenv";
      targetPkgs = pkgs: with (builtins.getFlake "nixpkgs");
        [ 
          # bashInteractive
          # coreutils
          hello
       ];
       multiPkgs = pkgs: with (builtins.getFlake "nixpkgs");
       [
         zlib
       ];
       runScript = "bash";
    };
in pkgs.stdenv.mkDerivation {
  name = "fhs";
  nativeBuildInputs = [ fhs ]; 
  unpackPhase = ":"; 
  installPhase = "mkdir $out"; 
  phases = [ "unpackPhase" "installPhase" ];
  shellHook = "exec fenv";
}
)
)'
nix \
shell \
--ignore-environment \
--impure \
--expr \
'(
with builtins.getFlake "nixpkgs";  
with legacyPackages.${builtins.currentSystem}; 
  (
    buildFHSUserEnv { 
      name = "fhs";
      targetPkgs = pkgs: with (builtins.getFlake "nixpkgs"); [
          bashInteractive
          hello
          cowsay          
        ];
      runScript = "bash";
      profile = "export FONTCONFIG_FILE=${fontconfig.out}/etc/fonts/fonts.conf";
    }
  )
)' \
--command \
fhs \
-c \
"echo Hi! | cowsay"
nix \
shell \
--ignore-environment \
--impure \
--expr \
'(
with builtins.getFlake "nixpkgs";  
with legacyPackages.${builtins.currentSystem}; 
  (
    buildFHSUserEnv { 
      name = "fhs";
      targetPkgs = pkgs: with (builtins.getFlake "nixpkgs"); [
          pkgsStatic.nix
        ];
      runScript = "bash";
    }
  )
)' \
--command \
fhs \
-c \
"nix flake --version"
nix \
shell \
--ignore-environment \
--impure \
--expr \
'(
with builtins.getFlake "nixpkgs";  
with legacyPackages.${builtins.currentSystem}; 
  (
  let fhs = pkgs.buildFHSUserEnv {
  name = "fenv";
  targetPkgs = pkgs: with (builtins.getFlake "nixpkgs");
    [ 
       bashInteractive
       coreutils
    ];
  multiPkgs = pkgs: with (builtins.getFlake "nixpkgs");
    [
       zlib
    ];
  runScript = "bash";
  profile = ''
    export USE_CCACHE "abc"
  '';
};
in pkgs.stdenv.mkDerivation {
  name = "android-env-shell";
  nativeBuildInputs = [ fhs ];
  shellHook = "exec fenv";
}
)
)'
@PedroRegisPOAR
Copy link
Contributor Author

PedroRegisPOAR commented Jul 2, 2022

Broken, hello is not beeing added to $PATH, why?

nix \
shell \
--impure \
--expr \
'(
  with builtins.getFlake "nixpkgs";  
  with legacyPackages.${builtins.currentSystem}; 
  (
    let fhs = pkgs.buildFHSUserEnv {
      name = "fenv";
      targetPkgs = pkgs: with (builtins.getFlake "nixpkgs");
        [ 
          # bashInteractive
          # coreutils
          hello
       ];
    multiPkgs = pkgs: with (builtins.getFlake "nixpkgs");
      [
        zlib
      ];
  runScript = "bash";
};
in pkgs.stdenv.mkDerivation {
  name = "android-env-shell";
  nativeBuildInputs = [ fhs ]; 
  unpackPhase = ":"; 
  installPhase = "mkdir $out"; 
  phases = [ "unpackPhase" "installPhase" ];
  shellHook = "exec fenv";
}
)
)'

TODO:

{ buildFHSUserEnv
, writeShellScriptBin
, ... }:
let
  fhs = buildFHSUserEnv {
    name = "appimage-env";

    # Most of the packages were taken from the Steam chroot
    targetPkgs = pkgs: with pkgs; [
      gtk3
      bashInteractive
      gnome.zenity
      python2
      xorg.xrandr
      which
      perl
      xdg-utils
      iana-etc
      krb5
      gsettings-desktop-schemas
      hicolor-icon-theme # dont show a gtk warning about hicolor not being installed
    ];

    # list of libraries expected in an appimage environment:
    # https://github.com/AppImage/pkg2appimage/blob/master/excludelist
    multiPkgs = pkgs: with pkgs; [
      # extra
      fuse
      fuse3
      (writeShellScriptBin "sudo" "true") # suid wrappers messing with suff
      pulseaudio

      desktop-file-utils
      xorg.libXcomposite
      xorg.libXtst
      xorg.libXrandr
      xorg.libXext
      xorg.libX11
      xorg.libXfixes
      libGL

      gst_all_1.gstreamer
      gst_all_1.gst-plugins-ugly
      gst_all_1.gst-plugins-base
      libdrm
      xorg.xkeyboardconfig
      xorg.libpciaccess

      glib
      gtk2
      bzip2
      zlib
      gdk-pixbuf

      xorg.libXinerama
      xorg.libXdamage
      xorg.libXcursor
      xorg.libXrender
      xorg.libXScrnSaver
      xorg.libXxf86vm
      xorg.libXi
      xorg.libSM
      xorg.libICE
      gnome2.GConf
      freetype
      (curl.override { gnutlsSupport = true; opensslSupport = false; })
      nspr
      nss
      fontconfig
      cairo
      pango
      expat
      dbus
      cups
      libcap
      SDL2
      libusb1
      udev
      dbus-glib
      atk
      at-spi2-atk
      libudev0-shim

      xorg.libXt
      xorg.libXmu
      xorg.libxcb
      xorg.xcbutil
      xorg.xcbutilwm
      xorg.xcbutilimage
      xorg.xcbutilkeysyms
      xorg.xcbutilrenderutil
      libGLU
      libuuid
      libogg
      libvorbis
      SDL
      SDL2_image
      glew110
      openssl
      libidn
      tbb
      wayland
      mesa
      libxkbcommon

      flac
      freeglut
      libjpeg
      libpng12
      libsamplerate
      libmikmod
      libtheora
      libtiff
      pixman
      speex
      SDL_image
      SDL_ttf
      SDL_mixer
      SDL2_ttf
      SDL2_mixer
      libappindicator-gtk2
      libcaca
      libcanberra
      libgcrypt
      libvpx
      librsvg
      xorg.libXft
      libvdpau
      alsa-lib

      harfbuzz
      e2fsprogs
      libgpg-error
      keyutils.lib
      libjack2
      fribidi
      p11-kit

      gmp

      # libraries not on the upstream include list, but nevertheless expected
      # by at least one appimage
      libtool.lib # for Synfigstudio
      xorg.libxshmfence # for apple-music-electron
      at-spi2-core
    ];

    runScript = ''

    PATH=$(echo "$PATH" | sed 's;/run/wrappers/bin:;;g')

    "$@"
    '';
  };
in writeShellScriptBin "appimage-wrap" ''
PATH=$PATH:${fhs}/bin
APPIMAGE="$1";shift
ENV_NAME="$(basename "$APPIMAGE")"
ENVDIR="/tmp/appimage-wrap/$ENV_NAME"
mkdir -p "$ENVDIR"
if [ -z "$(ls -A $ENVDIR)" ]; then
  echo "Mounting appimage"
  sudo mount "$APPIMAGE" "$ENVDIR" -o "offset=$(appimage-env "$APPIMAGE" --appimage-offset | head -n 1)"
fi
appimage-env "$ENVDIR/AppRun" "$@"
''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant