From 280fdeeab0700eb98faa813ee133c1f96ac29db7 Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Wed, 8 Jul 2020 16:42:03 +0200 Subject: [PATCH] Don't use nix-channels --- build.sh | 10 ++++++ configurations/nix-store.nix | 7 +---- imports/home-manager/default.nix | 7 +++++ imports/home-manager/metadata.nix | 9 ++++++ imports/nixpkgs/default.nix | 7 +++++ imports/nixpkgs/metadata.nix | 9 ++++++ lib.nix | 33 ++++++++++++++++++++ machines/kholinar/configuration.nix | 40 ++++++++++++++++++++++++ machines/kholinar/default.nix | 47 +++++------------------------ machines/oldtown/configuration.nix | 33 ++++++++++++++++++++ machines/oldtown/default.nix | 40 +++++------------------- machines/oldtown/hardware.nix | 4 +-- overlays/default.nix | 1 - profiles/common.nix | 8 +++-- shells/nix.nix | 1 + update-imports.sh | 46 ++++++++++++++++++++++++++++ update.sh | 9 ++++++ 17 files changed, 229 insertions(+), 82 deletions(-) create mode 100755 build.sh create mode 100644 imports/home-manager/default.nix create mode 100644 imports/home-manager/metadata.nix create mode 100644 imports/nixpkgs/default.nix create mode 100644 imports/nixpkgs/metadata.nix create mode 100644 lib.nix create mode 100644 machines/kholinar/configuration.nix create mode 100644 machines/oldtown/configuration.nix create mode 100755 update-imports.sh create mode 100755 update.sh diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..7209e050 --- /dev/null +++ b/build.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -euo pipefail +set -x + +nix-build \ + --no-out-link \ + --pure \ + "${@}" + +exit 0 diff --git a/configurations/nix-store.nix b/configurations/nix-store.nix index b90b5368..01e7d461 100644 --- a/configurations/nix-store.nix +++ b/configurations/nix-store.nix @@ -13,14 +13,9 @@ }; }; - system.autoUpgrade = { - allowReboot = false; - enable = true; - dates = "hourly"; - }; + nixpkgs.config = import ./nix-store/config.nix; home-manager.users.charlotte = { ... }: { - nixpkgs.config = import ./nix-store/config.nix; xdg.configFile."nixpkgs/config.nix".source = ./nix-store/config.nix; }; } diff --git a/imports/home-manager/default.nix b/imports/home-manager/default.nix new file mode 100644 index 00000000..84c7076e --- /dev/null +++ b/imports/home-manager/default.nix @@ -0,0 +1,7 @@ +let + metadata = import ./metadata.nix; +in +builtins.fetchTarball { + url = "https://github.com/rycee/home-manager/archive/${metadata.rev}.tar.gz"; + sha256 = metadata.sha256; +} diff --git a/imports/home-manager/metadata.nix b/imports/home-manager/metadata.nix new file mode 100644 index 00000000..79faef01 --- /dev/null +++ b/imports/home-manager/metadata.nix @@ -0,0 +1,9 @@ +{ + url = "https://github.com/rycee/home-manager/archive/master.tar.gz"; + repo_git = "https://github.com/rycee/home-manager"; + branch = "master"; + rev = "5f189acce44dc39ea4055bfd8064adaf90d7fb5a"; + sha256 = "0ibmvg3k9m9yzh8ln3jlh47nrvgg81iy8gpl112wjimlp6gagxw6"; + revdate = "2020-07-04 12:21:02 +0200"; + skip = false; +} diff --git a/imports/nixpkgs/default.nix b/imports/nixpkgs/default.nix new file mode 100644 index 00000000..b373223d --- /dev/null +++ b/imports/nixpkgs/default.nix @@ -0,0 +1,7 @@ +let + metadata = import ./metadata.nix; +in +builtins.fetchTarball { + url = "https://github.com/charvp/nixpkgs/archive/${metadata.rev}.tar.gz"; + sha256 = metadata.sha256; +} diff --git a/imports/nixpkgs/metadata.nix b/imports/nixpkgs/metadata.nix new file mode 100644 index 00000000..55d0aa9d --- /dev/null +++ b/imports/nixpkgs/metadata.nix @@ -0,0 +1,9 @@ +{ + url = "https://github.com/charvp/nixpkgs/archive/master.tar.gz"; + repo_git = "https://github.com/charvp/nixpkgs"; + branch = "master"; + rev = "c3bce2b5aa52fdfe607bcd74031cc80678a379c1"; + sha256 = "16fhd1cklc5ygp35a6jy2v5xjvzrb892mqjabf1hj125hfx3zymn"; + revdate = "2020-07-08 09:11:37 +0200"; + skip = false; +} diff --git a/lib.nix b/lib.nix new file mode 100644 index 00000000..eb7b7e1a --- /dev/null +++ b/lib.nix @@ -0,0 +1,33 @@ +{ + findImport = name: + let + localpath = ./.. + "/${name}"; + importpath = ./imports + "/${name}"; + in + if builtins.pathExists localpath then + localpath + else if builtins.pathExists importpath then + (import importpath) + else (abort "couldn't find import ${name}"); + + mkSystem = { nixpkgs, system ? "x86_64-linux", rev ? "git", extraModules ? [ ], ... }: + let + pkgs = import (nixpkgs) { + inherit (machine.config.nixpkgs) config overlays; + }; + nixPath = pkgs.runCommand "nix-path" + { } '' + mkdir -p $out + ln -s "${nixpkgs}" $out/nixpkgs + ''; + machine = import "${nixpkgs}/nixos/lib/eval-config.nix" { + inherit system; + modules = [ + ({ ... }: { + nix.nixPath = [ "${nixPath}" ]; + }) + ] ++ extraModules; + }; + in + machine; +} diff --git a/machines/kholinar/configuration.nix b/machines/kholinar/configuration.nix new file mode 100644 index 00000000..0ba8bda9 --- /dev/null +++ b/machines/kholinar/configuration.nix @@ -0,0 +1,40 @@ +{ pkgs, lib, ... }: + +{ + imports = [ + ./hardware.nix + ./secret.nix + ../../configurations/eid.nix + ../../profiles/bluetooth.nix + ../../profiles/common.nix + ../../profiles/graphical.nix + ]; + + networking = { + hostId = "3cc1a4b2"; + hostName = "kholinar"; + }; + + time.timeZone = "Europe/Brussels"; + + # This value determines the NixOS release from which the default + # settings for stateful data, like file locations and database versions + # on your system were taken. It‘s perfectly fine and recommended to leave + # this value at the release version of the first install of this system. + # Before changing this value read the documentation for this option + # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). + system.stateVersion = "20.09"; + + home-manager.users.charlotte = { ... }: { + home.stateVersion = "20.09"; + }; + + # Machine-specific settings + custom = { + git.email = "charlotte@vanpetegem.me"; + zfs = { + enable = true; + encrypted = true; + }; + }; +} diff --git a/machines/kholinar/default.nix b/machines/kholinar/default.nix index 0ba8bda9..c1d166fd 100644 --- a/machines/kholinar/default.nix +++ b/machines/kholinar/default.nix @@ -1,40 +1,9 @@ -{ pkgs, lib, ... }: - -{ - imports = [ - ./hardware.nix - ./secret.nix - ../../configurations/eid.nix - ../../profiles/bluetooth.nix - ../../profiles/common.nix - ../../profiles/graphical.nix - ]; - - networking = { - hostId = "3cc1a4b2"; - hostName = "kholinar"; +let + lib = import ../../lib.nix; + system = lib.mkSystem { + nixpkgs = (lib.findImport "nixpkgs"); + extraModules = [ ./configuration.nix ]; + system = "x86_64-linux"; }; - - time.timeZone = "Europe/Brussels"; - - # This value determines the NixOS release from which the default - # settings for stateful data, like file locations and database versions - # on your system were taken. It‘s perfectly fine and recommended to leave - # this value at the release version of the first install of this system. - # Before changing this value read the documentation for this option - # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). - system.stateVersion = "20.09"; - - home-manager.users.charlotte = { ... }: { - home.stateVersion = "20.09"; - }; - - # Machine-specific settings - custom = { - git.email = "charlotte@vanpetegem.me"; - zfs = { - enable = true; - encrypted = true; - }; - }; -} +in +system.config.system.build.toplevel diff --git a/machines/oldtown/configuration.nix b/machines/oldtown/configuration.nix new file mode 100644 index 00000000..514df2e5 --- /dev/null +++ b/machines/oldtown/configuration.nix @@ -0,0 +1,33 @@ +{ config, pkgs, ... }: + +{ + imports = [ + ./hardware.nix + ./secret.nix + ../../configurations/eid.nix + ../../profiles/bluetooth.nix + ../../profiles/common.nix + ../../profiles/graphical.nix + ]; + + networking.hostName = "oldtown"; + + time.timeZone = "Europe/Brussels"; + + # This value determines the NixOS release from which the default + # settings for stateful data, like file locations and database versions + # on your system were taken. It‘s perfectly fine and recommended to leave + # this value at the release version of the first install of this system. + # Before changing this value read the documentation for this option + # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). + system.stateVersion = "20.03"; + + home-manager.users.charlotte = { ... }: { + home.stateVersion = "20.03"; + }; + + # Machine-specific application settings + custom = { + git.email = "charlotte.vanpetegem@ugent.be"; + }; +} diff --git a/machines/oldtown/default.nix b/machines/oldtown/default.nix index 514df2e5..c1d166fd 100644 --- a/machines/oldtown/default.nix +++ b/machines/oldtown/default.nix @@ -1,33 +1,9 @@ -{ config, pkgs, ... }: - -{ - imports = [ - ./hardware.nix - ./secret.nix - ../../configurations/eid.nix - ../../profiles/bluetooth.nix - ../../profiles/common.nix - ../../profiles/graphical.nix - ]; - - networking.hostName = "oldtown"; - - time.timeZone = "Europe/Brussels"; - - # This value determines the NixOS release from which the default - # settings for stateful data, like file locations and database versions - # on your system were taken. It‘s perfectly fine and recommended to leave - # this value at the release version of the first install of this system. - # Before changing this value read the documentation for this option - # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). - system.stateVersion = "20.03"; - - home-manager.users.charlotte = { ... }: { - home.stateVersion = "20.03"; +let + lib = import ../../lib.nix; + system = lib.mkSystem { + nixpkgs = (lib.findImport "nixpkgs"); + extraModules = [ ./configuration.nix ]; + system = "x86_64-linux"; }; - - # Machine-specific application settings - custom = { - git.email = "charlotte.vanpetegem@ugent.be"; - }; -} +in +system.config.system.build.toplevel diff --git a/machines/oldtown/hardware.nix b/machines/oldtown/hardware.nix index 05c3a5a7..31999a5d 100644 --- a/machines/oldtown/hardware.nix +++ b/machines/oldtown/hardware.nix @@ -1,7 +1,7 @@ -{ config, lib, pkgs, ... }: +{ config, lib, pkgs, modulesPath, ... }: { - imports = [ ]; + imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; boot = { loader = { diff --git a/overlays/default.nix b/overlays/default.nix index a7278ba8..a2913a30 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -14,6 +14,5 @@ in home-manager.users.charlotte = { pkgs, lib, ... }: { xdg.configFile = lib.attrsets.mapAttrs' (name: value: { name = "nixpkgs/overlays/${name}"; value = { source = value; }; }) set; - nixpkgs.overlays = overlays; }; } diff --git a/profiles/common.nix b/profiles/common.nix index 6b41e1c1..c38c7c1f 100644 --- a/profiles/common.nix +++ b/profiles/common.nix @@ -1,8 +1,11 @@ { pkgs, ... }: - +let + findImport = (import ../lib.nix).findImport; + home-manager = findImport "home-manager"; +in { imports = [ - + "${home-manager}/nixos" ../modules/zfs.nix ../overlays/default.nix ../configurations/direnv.nix @@ -18,6 +21,7 @@ ../configurations/zsh.nix ]; + home-manager.useGlobalPkgs = true; home-manager.users.charlotte = { pkgs, ... }: { home.packages = with pkgs; [ hledger diff --git a/shells/nix.nix b/shells/nix.nix index 55f12782..6f62297d 100644 --- a/shells/nix.nix +++ b/shells/nix.nix @@ -3,6 +3,7 @@ let in pkgs.mkShell { buildInputs = with pkgs; [ + jq nixpkgs-fmt ]; } diff --git a/update-imports.sh b/update-imports.sh new file mode 100755 index 00000000..0be6d6bb --- /dev/null +++ b/update-imports.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +set -euo pipefail +set -x + +export NIX_PATH="nixpkgs=https://github.com/nixos/nixpkgs/archive/nixos-unstable.tar.gz" + +function update() { + pkg="${1}" + + metadata="${pkg}/metadata.nix" + pkgname="$(basename "${pkg}")" + + branch="$(nix-instantiate "${metadata}" --eval --json -A branch | jq -r .)" + rev="$(nix-instantiate "${metadata}" --eval --json -A rev | jq -r .)" + date="$(nix-instantiate "${metadata}" --eval --json -A revdate | jq -r .)" + sha256="$(nix-instantiate "${metadata}" --eval --json -A sha256 | jq -r .)" + url="$(nix-instantiate "${metadata}" --eval --json -A url | jq -r .)" + skip="$(nix-instantiate "${metadata}" --eval --json -A skip || echo "false" | jq -r .)" + + newdate="${date}" + if [[ "${skip}" != "true" ]]; then + repo="$(nix-instantiate "${metadata}" --eval --json -A repo_git | jq -r .)" + newrev="$(git ls-remote "${repo}" "${branch}" | awk '{ print $1}')" + + if [[ "${rev}" != "${newrev}" ]]; then + # Update RevDate + d="$(mktemp -d)" + git clone -b "${branch}" --single-branch --depth=1 "${repo}" "${d}" + newdate="$(cd "${d}"; git log --format=%ci --max-count=1)" + rm -rf "${d}" + + # Update Sha256 + newsha256="$(nix-prefetch-url --unpack "${url}")" + + # TODO: do this with nix instead of sed? + sed -i "s/${rev}/${newrev}/" "${metadata}" + sed -i "s/${date}/${newdate}/" "${metadata}" + sed -i "s/${sha256}/${newsha256}/" "${metadata}" + fi + fi +} + +for p in imports/*; do + update "${p}" +done diff --git a/update.sh b/update.sh new file mode 100755 index 00000000..161b0f36 --- /dev/null +++ b/update.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -euo pipefail +set -x + +./update-imports.sh + +result="$(./build.sh "./machines/$(hostname)")" + +sudo bash -c "nix-env --set --profile /nix/var/nix/profiles/system/ ${result} && ${result}/bin/switch-to-configuration switch"