From 5e0ca31d0220e2a1f1d95ec8974f162cda487d06 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 1 Aug 2020 22:08:41 -0600 Subject: [PATCH] flake: rename flake inputs and add overrides Now you can add packages to the list in pkgs/override.nix and they will be pulled in from nixpkgs master instead of the default NixOS flake when installed. --- flake.lock | 64 +++++++++++++++++++++++------------------------ flake.nix | 29 +++++++++++++-------- hosts/default.nix | 56 +++++++++++++++++++++++++---------------- pkgs/override.nix | 15 +++++++++++ 4 files changed, 100 insertions(+), 64 deletions(-) create mode 100644 pkgs/override.nix diff --git a/flake.lock b/flake.lock index 784d0d0..45b4342 100644 --- a/flake.lock +++ b/flake.lock @@ -19,6 +19,36 @@ "type": "github" } }, + "master": { + "locked": { + "lastModified": 1596337980, + "narHash": "sha256-LyE4haB7x2SBb1AyFJwqtGQitdaBFyK2ov4eH9Agono=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "111221b93ad46bb7119686f0a89a7bf1d3ad5bd7", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "master", + "type": "indirect" + } + }, + "nixos": { + "locked": { + "lastModified": 1596329181, + "narHash": "sha256-q6NSFQnFbpey/RP2LFfYW9Vcpt6CYKO8Q//6TuNBuYM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7dc4385dc7b5b2c0dbfecd774cebbc87ac05c061", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "release-20.03", + "type": "indirect" + } + }, "nixpkgs": { "locked": { "lastModified": 1591748508, @@ -33,41 +63,11 @@ "type": "indirect" } }, - "nixpkgs_2": { - "locked": { - "lastModified": 1596030432, - "narHash": "sha256-Q5LNY71SXjEjhyzZ+cInbGu0reezV4LlXbRPe3jk7gk=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "326767fd7309831974e6d7533593725897010c49", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "release-20.03", - "type": "indirect" - } - }, "root": { "inputs": { "home": "home", - "nixpkgs": "nixpkgs_2", - "unstable": "unstable" - } - }, - "unstable": { - "locked": { - "lastModified": 1596085265, - "narHash": "sha256-GvvEdlmQHmt9S/yrInyJ/unOSlcTHjHoOC4LcOvzATM=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "4701e11216560f85e7b2ecf215e592ff9a46c41b", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "master", - "type": "indirect" + "master": "master", + "nixos": "nixos" } } }, diff --git a/flake.nix b/flake.nix index e55bd69..5d897b5 100644 --- a/flake.nix +++ b/flake.nix @@ -1,14 +1,17 @@ { description = "A highly structured configuration database."; - inputs.nixpkgs.url = "nixpkgs/release-20.03"; - inputs.unstable.url = "nixpkgs/master"; - inputs.home.url = "github:rycee/home-manager/bqv-flakes"; + inputs = + { + master.url = "nixpkgs/master"; + nixos.url = "nixpkgs/release-20.03"; + home.url = "github:rycee/home-manager/bqv-flakes"; + }; - outputs = inputs@{ self, home, nixpkgs, unstable }: + outputs = inputs@{ self, home, nixos, master }: let inherit (builtins) attrNames attrValues readDir; - inherit (nixpkgs) lib; + inherit (nixos) lib; inherit (lib) removeSuffix recursiveUpdate; inherit (utils) pathsToImportedAttrs; @@ -23,19 +26,23 @@ config = { allowUnfree = true; }; }; - pkgs = pkgImport nixpkgs; - unstablePkgs = pkgImport unstable; + pkgset = { + osPkgs = pkgImport nixos; + pkgs = pkgImport master; + }; in + with pkgset; { nixosConfigurations = import ./hosts (recursiveUpdate inputs { - inherit system pkgs - unstablePkgs utils; + inherit lib pkgset system utils; } ); - devShell."${system}" = import ./shell.nix { inherit pkgs; }; + devShell."${system}" = import ./shell.nix { + inherit pkgs; + }; overlay = import ./pkgs; @@ -47,7 +54,7 @@ in pathsToImportedAttrs overlayPaths; - packages."${system}" = self.overlay pkgs pkgs; + packages."${system}" = (self.overlay osPkgs osPkgs); nixosModules = let diff --git a/hosts/default.nix b/hosts/default.nix index 8f95f8e..7bca609 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -1,8 +1,17 @@ -{ home, nixpkgs, unstable, unstablePkgs, self, pkgs, system, utils, ... }: +{ home +, lib +, nixos +, master +, pkgset +, self +, system +, utils +, ... +}: let - inherit (nixpkgs) lib; inherit (utils) recImport; inherit (builtins) attrValues removeAttrs; + inherit (pkgset) osPkgs pkgs; config = hostName: lib.nixosSystem { @@ -16,31 +25,36 @@ let global = { networking.hostName = hostName; - nix.nixPath = [ - "nixpkgs=${nixpkgs}" - "nixos-config=/etc/nixos/configuration.nix" - "nixpkgs-overlays=/etc/nixos/overlays" - ]; + nix.nixPath = let path = toString ../.; in + [ + "nixpkgs=${master}" + "nixos=${nixos}" + "nixos-config=${path}/configuration.nix" + "nixpkgs-overlays=${path}/overlays" + ]; - nixpkgs = { inherit pkgs; }; + nixpkgs = { pkgs = osPkgs; }; nix.registry = { - nixpkgs.flake = nixpkgs; + nixos.flake = nixos; nixflk.flake = self; - master.flake = unstable; + nixpkgs.flake = master; }; }; - unstables = { - systemd.package = unstablePkgs.systemd; - nixpkgs.overlays = [ - (final: prev: - with unstablePkgs; { - inherit starship element-desktop discord signal-desktop mpv - protonvpn-cli-ng dhall nixpkgs-fmt; - } - ) - ]; + overrides = { + # use latest systemd + systemd.package = pkgs.systemd; + + nixpkgs.overlays = + let + override = import ../pkgs/override.nix pkgs; + + overlay = pkg: final: prev: { + inherit pkg; + }; + in + map overlay override; }; local = import "${toString ./.}/${hostName}.nix"; @@ -50,7 +64,7 @@ let attrValues (removeAttrs self.nixosModules [ "profiles" ]); in - flakeModules ++ [ core global local home-manager unstables ]; + flakeModules ++ [ core global local home-manager overrides ]; }; diff --git a/pkgs/override.nix b/pkgs/override.nix new file mode 100644 index 0000000..7f668d4 --- /dev/null +++ b/pkgs/override.nix @@ -0,0 +1,15 @@ +# Packages in this list are imported by hosts/default.nix, and are pulled from +# nixpkgs master instead of the default nixos release. This doesn't actually +# install them, just creates an overlay to pull them from master if they are +# installed by the user elsewhere in the configuration. +pkgs: +with pkgs; +[ + starship + element-desktop + discord + signal-desktop + mpv + dhall + nixpkgs-fmt +]