Created
June 1, 2019 19:38
-
-
Save bb010g/57fedcda41b583c04745e477fed0dd22 to your computer and use it in GitHub Desktop.
update Nix tarball pins (e.g. Nixpkgs) from (n)vim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let nixpkgs = import ./nixpkgs.nix; in | |
import "${nixpkgs.nixpkgs}/nixos" { | |
configuration = { | |
imports = [ | |
./configuration.nix | |
]; | |
}; | |
system = "x86_64-linux"; | |
} | |
# vim:et:sw=2:tw=78 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let nixpkgs = import ./nix/nixpkgs.nix; in | |
{ pkgs ? nixpkgs.pkgs-unstable }: | |
pkgs.mkShell { | |
name = "example-env"; | |
src = pkgs.nix-gitignore.gitignoreSource [ | |
"*.nix" | |
".git" | |
".gitignore" | |
] ./.; | |
buildInputs = [ | |
pkgs.cargo-edit | |
pkgs.cargo-tree | |
(pkgs.nur.repos.mozilla.rustChannelOf { | |
channel = "nightly"; | |
date = "2019-06-01"; | |
}).rust | |
]; | |
} | |
# vim:et:sw=2:tw=78 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! NixPrefetchUrl(url) | |
echom a:url | |
let l:prefetch_raw = systemlist( | |
\ "nix-prefetch-url --type sha256 ".shellescape(a:url)." 2>/dev/null") | |
let l:prefetch = join(l:prefetch_raw, "\n") | |
echom l:prefetch | |
return l:prefetch | |
endfunction | |
function! NixUpdateTarball() | |
let [_, l:command; _] = matchlist(getline(line(".") + 1), | |
\ '\v^\s*#\s*:!\s*(.*)$') | |
let l:url = trim(system(l:command)) | |
let [_, l:pat; _] = matchlist(getline(line(".") + 2), | |
\ '\v^\s*#\s*(.*)$') | |
let [_, l:sub; _] = matchlist(getline(line(".") + 3), | |
\ '\v^\s*#\s*(.*)$') | |
let l:fetch_url = substitute(l:url, l:pat, l:sub, '') | |
let l:prefetch = NixPrefetchUrl(l:fetch_url) | |
let l:save_winview = winsaveview() | |
s/# .*/\="# ".trim(system("date -u '+%F %R'"))/ | |
+5s@\v^(\s*)url \= ".*";\n\1sha256 \= ".*";@\=submatch(1).'url = "'.l:fetch_url."\";\r".submatch(1).'sha256 = "'.l:prefetch.'";'@ | |
call winrestview(l:save_winview) | |
endfunction | |
function! NixPrefetchGitHub(owner, repo, rev) | |
echom a:owner a:repo a:rev | |
let l:prefetch_raw = systemlist( | |
\ "nix-prefetch-github " . a:owner . " " . a:repo . " --rev " . a:rev) | |
echom join(l:prefetch_raw, "\n") | |
return json_decode(l:prefetch_raw) | |
endfunction | |
function! NixUpdateChannel() | |
let l:matchline = getline(line(".") + 1) | |
let [_, l:channel, l:checkowner, l:checkrepo, l:checkrev; _] = | |
\ matchlist(l:matchline, | |
\ '\v^\s*(.*) \= builtins\.fetchTarball \{ # (.*)/(.{-})%(#(.*))?$') | |
if l:checkrev == "" | |
let l:checkrev = l:channel | |
endif | |
let l:prefetch = NixPrefetchGitHub(l:checkowner, l:checkrepo, l:checkrev) | |
let l:save_winview = winsaveview() | |
s/# .*/\="# ".trim(system("date -u '+%F %R'"))/ | |
+2s@\v^(\s*)url \= "https://github.com/(.*)/(.*)/archive/.*\.tar\.gz";\n\1sha256 \= ".*";@\=submatch(1).'url = "https://github.com/'.submatch(2).'/'.submatch(3).'/archive/'.l:prefetch.rev.".tar.gz\";\r".submatch(1).'sha256 = "'.l:prefetch.sha256.'";'@ | |
call winrestview(l:save_winview) | |
endfunction | |
" vim:et:sw=2:tw=78 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for vim commands listed: | |
# :so nix-update.vim | |
rec { | |
nixpkgs = nixpkgs; | |
pkgs = instantiate nixpkgs; | |
nixpkgs-stable = nixos-19_03; | |
pkgs-stable = instantiate nixpkgs-stable; | |
nixpkgs-unstable = nixos-unstable; | |
pkgs-unstable = instantiate nixpkgs-unstable; | |
instantiate = nixpkgs: import nixpkgs nixpkgsOpts; | |
nixpkgsOpts = { config = nixConfig; }; | |
nixConfig = { | |
allowUnfree = true; | |
packageOverrides = pkgs: { | |
nur = import nur { inherit pkgs; }; | |
}; | |
}; | |
# :call NixUpdateChannel() | |
# 2019-06-01 18:26 | |
nixos-19_03 = builtins.fetchTarball { # NixOS/nixpkgs-channels#nixos-19.03 | |
url = "https://github.com/NixOS/nixpkgs/archive/55df3fe5f3fcb24237475671160f3114fba82d15.tar.gz"; | |
sha256 = "06digim3nc1xjyahr5v4k33pfmvl2aypx5653rbcx3zsjyis200q"; | |
}; | |
# 2019-06-01 18:25 | |
nixos-unstable = builtins.fetchTarball { # NixOS/nixpkgs-channels | |
url = "https://github.com/NixOS/nixpkgs/archive/b3dd39ca0e9a8da121154e59fea86143232c0ab7.tar.gz"; | |
sha256 = "09n1ag253sk1jk1ci6xh64hdp031yzs4x5ja2h89wfwhpk01kmz3"; | |
}; | |
# 2019-06-01 18:24 | |
nur = builtins.fetchTarball { # nix-community/NUR#master | |
url = "https://github.com/nix-community/NUR/archive/d1cda131b01fac4ad6dd46eb40f9f03e265ccf83.tar.gz"; | |
sha256 = "173c2zchk3b30qpjq3n2bdvhc66b2sg67xl7wky848zb9vh1277x"; | |
}; | |
# :call NixUpdateTarball() | |
# 2019-06-01 18:56 | |
# :!curl -w "%{url_effective}\n" -I -L -s -S 'https://cachix.org/api/v1/install' -o /dev/null | |
# \v^https://codeload.github.com/(.*)/(.*)/legacy.tar.gz/(.*)$ | |
# https://github.com/\1/\2/archive/\3.tar.gz | |
cachix = builtins.fetchTarball { | |
url = "https://github.com/NixOS/nixpkgs/archive/d45ba336b28661b16e6c8bb027bb68ba4e62c1c6.tar.gz"; | |
sha256 = "05knm7gsdjzy6w1xr7hskixvii95sra9vi49sx91ixym3a8rxw5g"; | |
}; | |
} | |
# vim:et:sw=2:tw=78 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment