about summary refs log tree commit diff
path: root/release.nix
blob: bd40919455ced7dbf1f3507a7bbb05179216c112 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
{ vuizvuiSrc ? null
, nixpkgsSrc ? <nixpkgs>
, supportedSystems ? [ "i686-linux" "x86_64-linux" ]
}:

let
  nixpkgsRevCount = nixpkgsSrc.revCount or 12345;
  nixpkgsShortRev = nixpkgsSrc.shortRev or "abcdefg";
  nixpkgsVersion = "pre${toString nixpkgsRevCount}.${nixpkgsShortRev}-vuizvui";

  nixpkgs = nixpkgsSrc;

  vuizvuiRevCount = vuizvuiSrc.revCount or 12345;
  vuizvuiShortRev = vuizvuiSrc.shortRev or "abcdefg";
  vuizvuiVersion = "pre${toString vuizvuiRevCount}.${vuizvuiShortRev}";

  # version of the nixos-unstable channel to get programs.sqlite from.
  # Use pkgs.sternenseemann.vuizvui-update-programs-sqlite to update.
  programsSqliteVersion = "22.11pre411613.7e52b35fe98";
  programsSqliteSha256 = "1ylj2vc6j6yf2234q932nrgp7kc6spqcgp6g9xcmakmh73rx836x";
  programsSqlite = pkgsUpstream.fetchurl {
    name = "programs.sqlite-${programsSqliteVersion}";
    url = "https://releases.nixos.org/nixos/unstable/nixos-${programsSqliteVersion}/nixexprs.tar.xz";
    sha256 = programsSqliteSha256;
    downloadToTemp = true;
    postFetch = ''
      tar -xOJf $downloadedFile nixos-${programsSqliteVersion}/programs.sqlite > "$out"
    '';
  };

  vuizvui = let
    patchedVuizvui = (import nixpkgs {}).stdenv.mkDerivation {
      name = "vuizvui-${vuizvuiVersion}";
      inherit nixpkgsVersion;
      src = vuizvuiSrc;
      phases = [ "unpackPhase" "installPhase" ];
      installPhase = ''
        cp -r --no-preserve=ownership "${nixpkgs}/" nixpkgs
        chmod -R u+w nixpkgs
        # since we fetch nixpkgsSrc using git, we don't get programs.sqlite
        # for programs.command-not-found which is normally included in the
        # channel. Building this ourselves is not desireable as it requires
        # to build and index the whole of nixpkgs. Therefore we just inject
        # it from a nixos channel (which possibly is a different version).
        cp --no-preserve=ownership "${programsSqlite}" nixpkgs/programs.sqlite
        echo -n "$nixpkgsVersion" > nixpkgs/.version-suffix
        echo "echo '$nixpkgsVersion'" \
          > nixpkgs/nixos/modules/installer/tools/get-version-suffix
        echo -n ${nixpkgs.rev or nixpkgsShortRev} > nixpkgs/.git-revision
        echo './nixpkgs' > nixpkgs-path.nix
        cp -r . "$out"
      '';
    };
  in if vuizvuiSrc == null then ./. else patchedVuizvui;

  system = "x86_64-linux";
  pkgsUpstream = import nixpkgs { inherit system; };
  root = import vuizvui { inherit system; };

  mpath = if vuizvuiSrc == null then ./machines else "${vuizvui}/machines";

  allMachines = with pkgsUpstream.lib; let
    wrapPkgs = machine: machine.__withPkgsPath nixpkgs;
    condition = m: !(m ? __withPkgsPath);
  in mapAttrsRecursiveCond condition (const wrapPkgs) (import mpath);

  allTests = with import ./lib; getVuizvuiTests ({
    inherit system nixpkgs;
    excludeVuizvuiGames = true;
  } // pkgsUpstream.lib.optionalAttrs (vuizvuiSrc != null) {
    vuizvuiTests = "${vuizvui}/tests";
  });

  pkgs = with pkgsUpstream.lib; let
    noGames = flip removeAttrs [ "games" ];
    releaseLib = import "${nixpkgs}/pkgs/top-level/release-lib.nix" {
      inherit supportedSystems;
      packageSet = attrs: noGames (import vuizvui attrs).pkgs;
      nixpkgsArgs.config = {
        allowUnfree = false;
        inHydra = true;
        allowBroken = true;
      };
    };

    packagePlatforms = mapAttrs (name: value: let
      brokenOr = if value.meta.broken or false then const [] else id;
      platforms = value.meta.hydraPlatforms or (value.meta.platforms or []);
      isRecursive = value.recurseForDerivations or false
                 || value.recurseForRelease or false;
      result = if isDerivation value then brokenOr platforms
               else if isRecursive then packagePlatforms value
               else [];
      tried = builtins.tryEval result;
    in if tried.success then tried.value else []);

  in with releaseLib; mapTestOn (packagePlatforms releaseLib.pkgs);

in with pkgsUpstream.lib; with builtins; {

  machines = let
    # We need to expose all the real builds within vuizvui.lazyPackages to make
    # sure they don't get garbage collected on the Hydra instance.
    wrapLazy = machine: pkgsUpstream.runCommandLocal machine.build.name {
      fakeRuntimeDeps = machine.eval.config.vuizvui.lazyPackages;
      product = machine.build;
    } ''
      mkdir -p "$out/nix-support"
      echo "$product" > "$out/nix-support/fake-runtime-dependencies"
      for i in $fakeRuntimeDeps; do
        echo "$i" >> "$out/nix-support/fake-runtime-dependencies"
      done
    '';
  in mapAttrsRecursiveCond (m: !(m ? eval)) (const wrapLazy) allMachines;

  isoImages = let
    buildIso = attrs: let
      name = attrs.iso.config.networking.hostName;
      cond = attrs.iso.config.vuizvui.createISO;
    in if !cond then {} else pkgsUpstream.runCommandLocal "vuizvui-iso-${name}" {
      meta.description = "Live CD/USB stick of ${name}";
      iso = attrs.iso.config.system.build.isoImage;
      passthru.config = attrs.iso.config;
    } ''
      mkdir -p "$out/nix-support"
      echo "file iso" $iso/iso/*.iso* \
        >> "$out/nix-support/hydra-build-products"
    '';
  in mapAttrsRecursiveCond (m: !(m ? iso)) (const buildIso) allMachines;

  tests = let
    machineList = collect (m: m ? eval) allMachines;
    activatedTests = unique (concatMap (machine:
      machine.eval.config.vuizvui.requiresTests
    ) machineList);
    mkTest = path: setAttrByPath path (getAttrFromPath path allTests);
  in fold recursiveUpdate {} (map mkTest activatedTests) // {
    inherit (allTests) vuizvui;
  };

  inherit pkgs;

  channels = let
    mkChannel = attrs: root.pkgs.mkChannel (rec {
      name = "vuizvui-channel-${attrs.name or "generic"}-${vuizvuiVersion}";
      src = vuizvui;
      patchPhase = ''
        touch .update-on-nixos-rebuild
      '';
    } // removeAttrs attrs [ "name" ]);

    gatherTests = active: map (path: getAttrFromPath path allTests) active;

  in {
    generic = mkChannel {
      constituents = concatMap (collect isDerivation) [
        allTests.vuizvui pkgs
      ];
    };

    machines = mapAttrsRecursiveCond (m: !(m ? eval)) (path: attrs: mkChannel {
      name = "machine-${last path}";
      constituents = singleton attrs.eval.config.system.build.toplevel
                  ++ gatherTests attrs.eval.config.vuizvui.requiresTests;
    }) allMachines;
  };

  manual = let
    modules = import "${nixpkgs}/nixos/lib/eval-config.nix" {
      modules = import "${vuizvui}/modules/module-list.nix";
      check = false;
      inherit system;
    };

    patchedDocbookXSL = overrideDerivation pkgsUpstream.docbook_xsl_ns (drv: {
      # Don't chunk off <preface/>
      postPatch = (drv.postPatch or "") + ''
        sed -i -e '
          /<xsl:when.*preface/d
          /<xsl:for-each/s!|//d:preface \+!!g
          /<xsl:variable/s!|[a-z]\+::d:preface\[1\] \+!!g
        ' xhtml/chunk-common.xsl

        sed -i -e '
          /<xsl:when.*preface/,/<\/xsl:when>/d
          /<xsl:template/s!|d:preface!!g
        ' xhtml/chunk-code.xsl
      '';
    });

    isVuizvui = opt: head (splitString "." opt.name) == "vuizvui";
    filterDoc = filter (opt: isVuizvui opt && opt.visible && !opt.internal);
    optionsXML = toXML (filterDoc (optionAttrSetToDocList modules.options));
    optionsFile = toFile "options.xml" (unsafeDiscardStringContext optionsXML);

    mkXsltFlags = flags: let
      mkParam = flag: valFun: opt: val: [ "--${flag}" opt (valFun val) ];
      mkStrParam = mkParam "stringparam" id;
      mkBoolParam = mkParam "param" (b: if b then "1" else "0");
      mkFlag = path: value: let
        opt = concatStringsSep "." path;
      in if isString value then mkStrParam opt value
         else if isBool value then mkBoolParam opt value
         else throw "Invalid value for '${opt}': ${toString value}";
      result = collect isList (mapAttrsRecursive mkFlag flags);
    in concatMapStringsSep " " escapeShellArg (concatLists result);

    xsltFlags = mkXsltFlags {
      section.autolabel = true;
      section.label.includes.component.label = true;
      html.stylesheet = "style.css overrides.css highlightjs/mono-blue.css";
      html.script = "highlightjs/highlight.pack.js highlightjs/loader.js";
      xref."with".number.and.title = true;
      admon.style = "";
    };

    xsltPath = "${nixpkgs}/nixos/lib/make-options-doc";

  in pkgsUpstream.stdenv.mkDerivation {
    name = "vuizvui-options";

    nativeBuildInputs = singleton pkgsUpstream.libxslt;

    buildCommand = ''
      cp -r "${./doc}" doc
      chmod -R +w doc
      xsltproc -o intermediate.xml \
        "${xsltPath}/options-to-docbook.xsl" \
        ${optionsFile}
      xsltproc -o doc/options-db.xml \
        "${xsltPath}/postprocess-option-descriptions.xsl" \
        intermediate.xml

      dest="$out/share/doc/vuizvui"
      mkdir -p "$dest"

      xsltproc -o "$dest/" ${xsltFlags} -nonet -xinclude \
        ${patchedDocbookXSL}/xml/xsl/docbook/xhtml/chunk.xsl \
        doc/index.xml

      cp "${nixpkgs}/doc/style.css" "$dest/style.css"
      cp "${nixpkgs}/doc/overrides.css" "$dest/overrides.css"
      cp -r ${pkgsUpstream.documentation-highlighter} "$dest/highlightjs"

      mkdir -p "$out/nix-support"
      echo "doc manual $dest" > "$out/nix-support/hydra-build-products"
    '';
  };
}