nix,steveej-t480s-work: introduce pure versioning

This commit is contained in:
steveej 2018-12-17 13:10:06 +01:00
parent 17c8ccb8c2
commit c5c4b160a1
12 changed files with 55 additions and 13 deletions

View file

@ -1,14 +1,19 @@
_usage: _usage:
just -l just -l
_get_nix_path versionsPath:
echo $(set -x; nix-build --no-link --show-trace {{invocation_directory()}}/nix/default.nix -A channelSources --argstr versionsPath {{versionsPath}} --argstr rebuildarg "dummy")
_device recipe dir +moreargs="": _device recipe dir +moreargs="":
#!/usr/bin/env bash #!/usr/bin/env bash
set -ex set -ex
source $(just -v _get_nix_path {{invocation_directory()}}/{{dir}}/versions.nix)
$(set -x; nix-build --no-link --show-trace $(dirname {{dir}})/default.nix -A recipes.{{recipe}} --argstr dir {{dir}} {{moreargs}}) $(set -x; nix-build --no-link --show-trace $(dirname {{dir}})/default.nix -A recipes.{{recipe}} --argstr dir {{dir}} {{moreargs}})
_render_templates: _render_templates:
#!/usr/bin/env bash #!/usr/bin/env bash
set -ex set -ex
source $(just -v _get_nix_path {{invocation_directory()}}/nix/variables/versions.nix)
nix/scripts/pre-eval-fixed.sh nix/home-manager/profiles/dotfiles/vcsh{.tmpl,}.nix nix/scripts/pre-eval-fixed.sh nix/home-manager/profiles/dotfiles/vcsh{.tmpl,}.nix
_rebuild-device dir rebuildarg="dry-activate" +moreargs="": _render_templates _rebuild-device dir rebuildarg="dry-activate" +moreargs="": _render_templates

25
nix/default.nix Normal file
View file

@ -0,0 +1,25 @@
{ versionsPath }:
{
channelSources =
let
# channelVersions = (import ((builtins.getEnv "PWD")+"/${dir}/versions.nix"));
channelVersions = (import versionsPath);
mkChannelSource = channel: builtins.fetchGit {
# Descriptive name to make the store path easier to identify
url = "https://github.com/NixOS/nixpkgs-channels/";
# Commit hash for nixos-unstable as of 2018-09-12
# `git ls-remote https://github.com/nixos/nixpkgs-channels nixos-unstable`
rev = (builtins.getAttr channel channelVersions);
name = "nixpkgs-channels-${channel}";
};
nix_path = builtins.foldl' (sum: elem: sum +":" + builtins.concatStringsSep "=" elem) "" [
[ "nixpkgs" (mkChannelSource "channelsNixosStable") ]
[ "nixos" (mkChannelSource "channelsNixosStable") ]
[ "channels-nixos-stable" (mkChannelSource "channelsNixosStable") ]
[ "channels-nixos-unstable" (mkChannelSource "channelsNixosUnstable") ]
];
in (import (mkChannelSource "channelsNixosStable") {}).writeText "channels.rc" ''
export NIX_PATH=${nix_path}
'';
}

View file

@ -4,7 +4,7 @@
let let
# gitpkgs = import /home/steveej/src/github/NixOS/nixpkgs {}; # gitpkgs = import /home/steveej/src/github/NixOS/nixpkgs {};
unstablepkgs = import <nixos-unstable> { config = config.nixpkgs.config; }; unstablepkgs = import <channels-nixos-unstable> { config = config.nixpkgs.config; };
in { in {
imports = [ imports = [

View file

@ -3,7 +3,8 @@
... }: ... }:
let let
unstablepkgs = import <nixos-unstable> { config = config.nixpkgs.config; }; unstablepkgs = import <channels-nixos-unstable> { config = config.nixpkgs.config; };
in { in {
imports = [ imports = [
../profiles/common.nix ../profiles/common.nix
@ -52,9 +53,6 @@ in {
}; };
}; };
# gitpkgs = import /home/steveej/src/github/NixOS/nixpkgs {};
# unstablepkgs = import <nixos-unstable> { config = { allowUnfree = true; }; };
home.sessionVariables = { home.sessionVariables = {
}; };

View file

@ -6,14 +6,16 @@
let let
in { in {
home.file.".nix-channels".text = '' home.file.".nix-channels".text = ''
https://nixos.org/channels/nixos-18.09 nixos
https://nixos.org/channels/nixos-unstable nixos-unstable
''; '';
home.activation.removeExistingNixChannels = config.lib.dag.entryBefore ["checkLinkTargets"] '' home.activation.removeExistingNixChannels = config.lib.dag.entryBefore ["checkLinkTargets"] ''
$DRY_RUN_CMD ${pkgs.writeScript "activation-script" '' $DRY_RUN_CMD ${pkgs.writeScript "activation-script" ''
set -ex set -ex
if test -f $HOME/.nix-channels; then if test -f $HOME/.nix-channels; then
echo Uninstalling available channels...
while read url channel; do
nix-channel --remove $channel
done < $HOME/.nix-channel
echo Moving existing file away... echo Moving existing file away...
touch $HOME/.nix-channels.dummy touch $HOME/.nix-channels.dummy
mv --backup=numbered $HOME/.nix-channels.dummy $HOME/.nix-channels mv --backup=numbered $HOME/.nix-channels.dummy $HOME/.nix-channels

View file

@ -3,7 +3,7 @@
}: }:
let let
unstablepkgs = import <nixos-unstable> {}; unstablepkgs = import <channels-nixos-unstable> {};
in { in {
home.sessionVariables = { home.sessionVariables = {

View file

@ -1,4 +1,4 @@
{ pkgs ? import <nixpkgs> {} { pkgs ? import <channels-nixos-stable> {}
, ownLib ? import ../lib/default.nix { } , ownLib ? import ../lib/default.nix { }
, dir , dir
, rebuildarg , rebuildarg

View file

@ -5,7 +5,7 @@
}: }:
let let
unstablepkgs = import <nixos-unstable> { config = config.nixpkgs; }; unstablepkgs = import <channels-nixos-unstable> { config = config.nixpkgs; };
in { in {
# The NixOS release to be compatible with for stateful data such as databases. # The NixOS release to be compatible with for stateful data such as databases.

View file

@ -0,0 +1,4 @@
{
channelsNixosStable = "7e88992a8c7b2de0bcb89182d8686b27bd93e46a";
channelsNixosUnstable = "44b02b52ea6a49674f124f50009299f192ed78bb";
}

View file

@ -1,5 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -xe
INFILE="${1:?Please set arg1 to INFILE}" INFILE="${1:?Please set arg1 to INFILE}"
OUTFILE="${2:?Please set arg2 to OUTFILE}" OUTFILE="${2:?Please set arg2 to OUTFILE}"
hash=$(nix-build ${INFILE} --arg pkgs 'import <nixpkgs> {}' --arg config 'null' 2>&1 | grep -oE '[0-9a-z]{52}' | head -n1) hash=$(nix-build ${INFILE} --arg pkgs 'import <channels-nixos-stable> {}' --arg config 'null' 2>&1 | grep -oE '[0-9a-z]{52}' | head -n1)
sed -E "s/0{52}/${hash}/" ${INFILE} > ${OUTFILE} sed -E "s/0{52}/${hash}/" ${INFILE} > ${OUTFILE}

View file

@ -0,0 +1,4 @@
{
channelsNixosStable = "7e88992a8c7b2de0bcb89182d8686b27bd93e46a";
channelsNixosUnstable = "44b02b52ea6a49674f124f50009299f192ed78bb";
}

View file

@ -1,12 +1,15 @@
with import <nixpkgs> {}; { ... }:
let let
channels-nixos-stable-path = (builtins.fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/7e88992a8c7b2de0bcb89182d8686b27bd93e46a.tar.gz);
channels-nixos-stable = import channels-nixos-stable-path {};
in in
with channels-nixos-stable;
stdenv.mkDerivation { stdenv.mkDerivation {
name = "infra-env"; name = "infra-env";
buildInputs = [ buildInputs = [
(with import <nixpkgs/nixos> { configuration = {}; }; with config.system.build; [ nixos-generate-config nixos-install nixos-enter manual.manpages ]) (with import (channels-nixos-stable-path+"/nixos") { configuration = {}; }; with config.system.build; [ nixos-generate-config nixos-install nixos-enter manual.manpages ])
(pkgs.callPackage ./nix/pkgs/just.nix {}) (pkgs.callPackage ./nix/pkgs/just.nix {})
git-crypt git-crypt
vcsh vcsh