diff --git a/configurations/direnv.nix b/configurations/direnv.nix index 34f6df6d..2fc3cea4 100644 --- a/configurations/direnv.nix +++ b/configurations/direnv.nix @@ -5,21 +5,22 @@ { path = ".local/share/direnv"; type = "cache"; } ]; - nix.extraOptions = '' - keep-outputs = true - keep-derivations = true - ''; - home-manager.users.charlotte = { ... }: { programs.direnv = { enable = true; - enableNixDirenvIntegration = true; enableZshIntegration = true; config = { global = { strict_env = true; }; }; + stdlib = '' + use_flake() { + watch_file flake.nix + watch_file flake.lock + eval "$(nix --experimental-features 'nix-commnand flakes' print-dev-env --profile "$(direnv_layout_dir)/flake-profile")" + } + ''; }; }; } diff --git a/configurations/nix-store.nix b/configurations/nix-store.nix index 4129ba56..bb8162c2 100644 --- a/configurations/nix-store.nix +++ b/configurations/nix-store.nix @@ -1,7 +1,11 @@ -{ ... }: +{ pkgs, ... }: { nix = { + extraOptions = '' + experimental-features = nix-command flakes + ''; + package = pkgs.nixFlakes; gc = { automatic = true; dates = "hourly"; diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..39d6e656 --- /dev/null +++ b/flake.lock @@ -0,0 +1,67 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1595332686, + "narHash": "sha256-GpzwLOx6fvtsAnjPqG0ob5GXR0e4eWThwgWedo3qeNc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f99f5970824e210e84f9a766e2ea52d4af770182", + "type": "github" + }, + "original": { + "owner": "numtide", + "ref": "master", + "repo": "flake-utils", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1594886249, + "narHash": "sha256-Z2REbQYsYBrdWc6Dz9MmtSReaanIMoJmmnUXNeQHaJY=", + "owner": "ehmry", + "repo": "home-manager", + "rev": "24f437c263207e22147f50e59c879078a58b17ba", + "type": "github" + }, + "original": { + "owner": "ehmry", + "ref": "flake", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1595363904, + "narHash": "sha256-p53BaxRE1FPqdOqVtj3e8dtygME6JzNtJPXYFGb9EPQ=", + "ref": "master", + "rev": "4da6ffdfb1ee6aaf93c379507dab543091a5536c", + "revCount": 235509, + "type": "git", + "url": "file:///data/home/charlotte/repos/nixpkgs" + }, + "original": { + "owner": "charvp", + "ref": "master", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "home-manager": "home-manager", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..9e95f0db --- /dev/null +++ b/flake.nix @@ -0,0 +1,45 @@ +{ + description = "Nixos configuration flake"; + + inputs = { + nixpkgs = { url = "github:charvp/nixpkgs/master"; }; + home-manager = { + url = "github:ehmry/home-manager/flake"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + flake-utils = { url = "github:numtide/flake-utils/master"; }; + }; + + outputs = { self, nixpkgs, home-manager, flake-utils }: + let + pkgsFor = system: import nixpkgs { + inherit system; + config = { allowUnfree = true; }; + }; + mkSystem = system: hostname: nixpkgs.lib.nixosSystem { + inherit system; + modules = [ + home-manager.nixosModules.home-manager + (./. + "/machines/${hostname}") + ]; + }; + in + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = pkgsFor system; + in + { + devShell = pkgs.mkShell { + buildInputs = with nixpkgs.legacyPackages.${system}; [ + jq + nixUnstable + nixpkgs-fmt + ]; + }; + }) // { + nixosConfigurations = { + kharbranth = mkSystem "x86_64-linux" "kharbranth"; + kholinar = mkSystem "x86_64-linux" "kholinar"; + }; + }; +} diff --git a/imports/home-manager/default.nix b/imports/home-manager/default.nix deleted file mode 100644 index 84c7076e..00000000 --- a/imports/home-manager/default.nix +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index a7e5aeb5..00000000 --- a/imports/home-manager/metadata.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ - url = "https://github.com/rycee/home-manager/archive/master.tar.gz"; - repo_git = "https://github.com/rycee/home-manager"; - branch = "master"; - rev = "8ad55800216760291e253150a7ecc831c2956229"; - sha256 = "0nif0a2pv5wgyjhfqd8jmlc055y0604xmqfnnr2hfrzz0blpl4ww"; - revdate = "2020-07-21 01:10:54 +0200"; - skip = false; -} diff --git a/imports/nixpkgs/default.nix b/imports/nixpkgs/default.nix deleted file mode 100644 index b373223d..00000000 --- a/imports/nixpkgs/default.nix +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 126a4f7f..00000000 --- a/imports/nixpkgs/metadata.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ - url = "https://github.com/charvp/nixpkgs/archive/master.tar.gz"; - repo_git = "https://github.com/charvp/nixpkgs"; - branch = "master"; - rev = "1cab31c02385445cd86b2930201f02708fe504d9"; - sha256 = "1c2wm4wyrswi61bfrb7yyv2025xg31shs7h1l0662vkjmd58vjaf"; - revdate = "2020-07-21 09:11:54 +0200"; - skip = false; -} diff --git a/lib.nix b/lib.nix deleted file mode 100644 index caf85085..00000000 --- a/lib.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ - 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 - machine = import "${nixpkgs}/nixos/lib/eval-config.nix" { - inherit system; - modules = [ - ({ ... }: { - nix.nixPath = [ "nixpkgs=${nixpkgs}" ]; - }) - ] ++ extraModules; - }; - in - machine; -} diff --git a/machines/kharbranth/configuration.nix b/machines/kharbranth/configuration.nix deleted file mode 100644 index 1a49270e..00000000 --- a/machines/kharbranth/configuration.nix +++ /dev/null @@ -1,40 +0,0 @@ -{ config, pkgs, ... }: - -{ - imports = [ - ./hardware.nix - ./secret.nix - ../../configurations/eid.nix - ../../profiles/bluetooth.nix - ../../profiles/common.nix - ../../profiles/graphical.nix - ]; - - networking = { - hostId = "e718389d"; - hostName = "kharbranth"; - }; - - 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 application settings - custom = { - git.email = "charlotte.vanpetegem@ugent.be"; - zfs = { - enable = true; - encrypted = true; - }; - }; -} diff --git a/machines/kharbranth/default.nix b/machines/kharbranth/default.nix index c1d166fd..1a49270e 100644 --- a/machines/kharbranth/default.nix +++ b/machines/kharbranth/default.nix @@ -1,9 +1,40 @@ -let - lib = import ../../lib.nix; - system = lib.mkSystem { - nixpkgs = (lib.findImport "nixpkgs"); - extraModules = [ ./configuration.nix ]; - system = "x86_64-linux"; +{ config, pkgs, ... }: + +{ + imports = [ + ./hardware.nix + ./secret.nix + ../../configurations/eid.nix + ../../profiles/bluetooth.nix + ../../profiles/common.nix + ../../profiles/graphical.nix + ]; + + networking = { + hostId = "e718389d"; + hostName = "kharbranth"; }; -in -system.config.system.build.toplevel + + 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 application settings + custom = { + git.email = "charlotte.vanpetegem@ugent.be"; + zfs = { + enable = true; + encrypted = true; + }; + }; +} diff --git a/machines/kholinar/configuration.nix b/machines/kholinar/configuration.nix deleted file mode 100644 index 0ba8bda9..00000000 --- a/machines/kholinar/configuration.nix +++ /dev/null @@ -1,40 +0,0 @@ -{ 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 c1d166fd..0ba8bda9 100644 --- a/machines/kholinar/default.nix +++ b/machines/kholinar/default.nix @@ -1,9 +1,40 @@ -let - lib = import ../../lib.nix; - system = lib.mkSystem { - nixpkgs = (lib.findImport "nixpkgs"); - extraModules = [ ./configuration.nix ]; - system = "x86_64-linux"; +{ pkgs, lib, ... }: + +{ + imports = [ + ./hardware.nix + ./secret.nix + ../../configurations/eid.nix + ../../profiles/bluetooth.nix + ../../profiles/common.nix + ../../profiles/graphical.nix + ]; + + networking = { + hostId = "3cc1a4b2"; + hostName = "kholinar"; }; -in -system.config.system.build.toplevel + + 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/profiles/common.nix b/profiles/common.nix index 71d05f2f..fe2aad11 100644 --- a/profiles/common.nix +++ b/profiles/common.nix @@ -1,11 +1,7 @@ { pkgs, ... }: -let - findImport = (import ../lib.nix).findImport; - home-manager = findImport "home-manager"; -in + { imports = [ - "${home-manager}/nixos" ../modules/zfs.nix ../configurations/direnv.nix ../configurations/git.nix diff --git a/shells/nix.nix b/shells/nix.nix index 6f62297d..330df0ab 100644 --- a/shells/nix.nix +++ b/shells/nix.nix @@ -1,9 +1,3 @@ -let - pkgs = import { }; -in -pkgs.mkShell { - buildInputs = with pkgs; [ - jq - nixpkgs-fmt - ]; -} +(import (fetchTarball https://github.com/edolstra/flake-compat/archive/master.tar.gz) { + src = ./.; +}).shellNix diff --git a/update-imports.sh b/update-imports.sh deleted file mode 100755 index 0be6d6bb..00000000 --- a/update-imports.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/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