From 8b85483c50ae6f9b6a5be120332d2b35bad75ab8 Mon Sep 17 00:00:00 2001 From: Tyson Whitehead Date: Fri, 19 Jan 2018 01:35:21 -0500 Subject: [PATCH] Add release code for building channel (drop nixpkgs submodule) Decided it would be best if hydra just provided the latest stable nixpkgs for us to use. This way there is no need for an udpate script that polutes our logs with update submodule commits. --- .gitmodules | 3 -- .version | 1 + default.nix | 68 ++++++++++++++++++++++++++++++----- nixpkgs | 1 - release.nix | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 160 insertions(+), 13 deletions(-) delete mode 100644 .gitmodules create mode 100644 .version delete mode 160000 nixpkgs create mode 100644 release.nix diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 3333dc8..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "nixpkgs"] - path = nixpkgs - url = https://github.com/NixOS/nixpkgs-channels.git diff --git a/.version b/.version new file mode 100644 index 0000000..2fdad9f --- /dev/null +++ b/.version @@ -0,0 +1 @@ +17.09 diff --git a/default.nix b/default.nix index b702b6c..bd1eeca 100644 --- a/default.nix +++ b/default.nix @@ -13,21 +13,21 @@ let # at a given level (the leading number) the search is stopped and they are used. If multiple overlays are found # at a given level then an error is generated. # - # 1: (i.e., nixpkgs-overlays.nix or nixpkgs-overlays/default.nix in NIX_PATH) - # 2: ~/.config/nixpkgs/overlays.nix - # 2: ~/.config/nixpkgs/overlays + # 1. (i.e., nixpkgs-overlays.nix or nixpkgs-overlays/default.nix in NIX_PATH) + # 2. ~/.config/nixpkgs/overlays.nix + # 2. ~/.config/nixpkgs/overlays # # This code is lifted directly from nixpkgs/pkgs/top-level/impure.nix to ensure consistency. # overlaysDefault = let - # isDir path - Is path a directory (requires access). - isDir = path: pathExists (path + "/."); - # try expression default - Replace expression with default on exception. try = x: def: let res = tryEval x; in if res.success then res.value else def; + # isDir path - Is path a directory (requires access). + isDir = path: pathExists (path + "/."); + # overlaysRetrieve path - Retrieve a list of the overlay functions from path. # path is file - import the file itself (should give a list of overlay functions) # path is directory - list of imports of all the *.nix files in the directory (each should give an overlay function) @@ -53,6 +53,7 @@ let homeOverlaysDir = homeDir + "/.config/nixpkgs/overlays"; in + if pathOverlays != "" && pathExists pathOverlays then overlaysRetrieve pathOverlays else if pathExists homeOverlaysFile && pathExists homeOverlaysDir then throw '' @@ -82,7 +83,7 @@ let let # knot - Feed final and up to and over us overlay results into overlay # - # This matche what is done in nixpkgs (see pkgs/top-level/stage.nix). + # This matches what is done in nixpkgs (see pkgs/top-level/stage.nix). # knot = path: self: super: let res = import path res self; in res; @@ -92,8 +93,57 @@ let ./pkgs/all-packages.nix ]; + # nixpkgs - The underlying nixpkg to use. + # + # Get a usable nixpkgs, that is, one with a version that matches ours, or die. + # + nixpkgs = + let + + # first check list - Return first element of list that passes check list otherwise aborts. + # + first = check: list: + if list == [] + then builtins.throw '' + Unable to locate a suitable nixpkgs directory. + Most likely you want to git clone one into the top of the repo as 'upstream'. + '' + else if check ( builtins.head list ) + then builtins.head list + else first check ( builtins.tail list ); + + # okay path - Check if path exist and match our version number and otherwise print a warning. + # + # Version numbers are taken from ./version files. + # + okay = + let + version = builtins.readFile ./.version; + in + path: + ( builtins.pathExists (path + /.version) + && ( builtins.readFile (path + /.version) == version + || builtins.trace '' + Skipping ${path} as not version ${version}. + '' false ) ); + + # paths - Paths to search for nixpkgs. + # + paths = [ + ./upstream # 1. build channel or git cloned one directly associated with us takes priority + # 2. if the channel is a version of ourselves the real one will be in a subdirectory + # 3. otherwise maybe the channel is a nixpkgs proper + ]; + + in + + first okay paths; + in { overlays ? overlaysDefault - , ... } @ args: - import ./nixpkgs (args // { overlays = overlaysAlways ++ overlays; }) + , upstream ? nixpkgs + , ... } @ args: + + import upstream ( builtins.removeAttrs args [ "upstream" ] + // { overlays = overlaysAlways ++ overlays; } ) diff --git a/nixpkgs b/nixpkgs deleted file mode 160000 index 360089b..0000000 --- a/nixpkgs +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 360089b3521af0c69a5167870c80851dedf19d76 diff --git a/release.nix b/release.nix new file mode 100644 index 0000000..7fb07f2 --- /dev/null +++ b/release.nix @@ -0,0 +1,100 @@ +{ nixpkgs # Checked out nixpkgs git repe + ? { outPath = ./upstream; + revCount = 56789; + shortRev = "gfedcba"; + } +, ccpkgs # Checked out ccpkgs git repo + ? { outPath = ./.; + revCount = 56789; + shortRev = "gfedcba"; + } +, stableBranch ? false +, supportedSystems ? [ "x86_64-linx" ] }: + + +# Free up the nixpkgs and ccpkgs name for binding to final product. +# +let + # nixpkgsGit - git checkout of nixpkgs + # ccpkgsGit - git checkout of ccpkgs + # + nixpkgsGit = nixpkgs; + ccpkgsGit = ccpkgs; + +# Tarball hydra release product for the ccpkgs channel. +# +# 1. Generate an unpacked channel for the associated nixpkgs in the store. +# 2. Symlink this into the top-level directory as upstream (nixpkgs is used). +# 3. Stick in the standard version files. +# 4. Let releaseTools.sourceTarball handle the details of exposing it as a hydra product. +# +in let + + # pkgs - Packages sucked in from the given ccpkgs git version. + # + pkgs = import ccpkgsGit { upstream = nixpkgsGit; }; + + # version - Version number of nixpkgs (and hence ccpkgs too) + # versionSuffix - Version suffix based on git commnit + # + # Code lifted from nixos/release.nix. + # + version = pkgs.lib.fileContents ./.version; + versionSuffix = + (if stableBranch then "." else "beta") + "${toString (nixpkgsGit.revCount - 114283)}.${nixpkgsGit.shortRev}"; + + # nixpkgs - The store path containing the unpacked nixpkgs channel. + # + # 1. Generate a channel tarball from the git repo via the nixos/release.nix expression for hydra. + # 2. Unpack this into the store using the nix/unpack-channel.nix expression used by nix-channel. + # + nixpkgs = + let + # version - Version of checked out nixpkgs + # + version = pkgs.lib.fileContents (nixpkgsGit + /.version); + + # channel - Store path containing the channel release tarballs. + # + # The nixos.channel attribute from nixos/release.nix builds the nixpkgs channel tarballs. + # + channel = + ( import (nixpkgsGit + /nixos/release.nix) { + nixpkgs = nixpkgsGit; + inherit stableBranch supportedSystems; + } ).channel; + + # nixpkgs - The store path containing the unpacked nixpkgs channel. + # + # The nix provided nix/unpack-channel.nix function extracts the nixpkgs from the channel, + # + nixpkgs = + ( import rec { + name = "nixos"; + channelName = "${name}-${version}"; + src = channel + /tarballs + "/${name}-${version}${versionSuffix}.tar.xz"; + binaryCacheURL = https://cache.nixos.org; + } ); + in + nixpkgs; + + # Tweak the nixos make-channel code to include the upstream channel. + # + # 1. Replace the git repo nixpkgs with a copy of the unpacked nixpkgs channel. + # + channel = + ( import (nixpkgsGit + /nixos/lib/make-channel.nix) { + inherit pkgs version versionSuffix; + nixpkgs = ccpkgsGit; + } ).overrideAttrs ( original: { + name = "ccpkgs-channel"; + distPhase = + '' + rm -fr upstream + cp -rd ${nixpkgs}/nixos-${version} upstream + '' + original.distPhase; + } ); + +in + + { inherit channel; }