Override scripts in nix derivations

感情迁移 提交于 2019-12-11 08:53:18

问题


Is there a way to override scripts and/or configs in an existing derivation without having to recompile the whole package?

I'd like to create a new version of gnome-session with modified $out/share/gnome-session/sessions/gnome.session modified. Using overridePackage I can change the preFixup phase, but this causes the whole gnome-session package to be recompiled.


回答1:


A simple solution to problem is creating a new derivation without any sources. The trick is to create links to every file and directory in the base derivation, except for any file(s) in need of modification. These files are handled explicitly according to needs.

The snippet below shows how to create a new gnome-session with xmonad instead of gnome-shell.

{ nixpkgs ? import <nixpkgs> {} }:
let
  inherit (nixpkgs) pkgs;  
in
  pkgs.stdenv.mkDerivation {
    name = "gnome-session";
    builder = pkgs.writeText "builder.sh" ''
      # source standard environment
      . $stdenv/setup

      # shorthands
      refpkg=${pkgs.gnome3.gnome_session}
      file=share/gnome-session/sessions/gnome.session

      # create output dirs for new derivation
      mkdir -p $out/share
      mkdir -p $out/share/gnome-session/sessions

      # link unchanged files from the original gnome-session 
      ln -sf $refpkg/bin $out
      ln -sf $refpkg/libexec $out
      find $refpkg/share -maxdepth 1 \
        -not -name gnome-session -exec ln -sf {} $out/share \;

     # change gnome-shell to xmonad
      sed 's/org.gnome.Shell/xmonad/' $refpkg/$file > $out/$file
    '';
     # make sure gnome-session is installed before deriving it!
    buildInputs = [ pkgs.gnome3.gnome_session ];
  }


来源:https://stackoverflow.com/questions/41465738/override-scripts-in-nix-derivations

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!