Initial commit

This commit is contained in:
Gytis Ivaskevicius 2021-03-13 15:39:03 +02:00
commit f28c31b661
4 changed files with 203 additions and 0 deletions

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Gytis Ivaskevicius
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,91 @@
{
description = "A highly awesome system configuration.";
inputs = {
nixpkgs.url = github:nixos/nixpkgs/release-20.09;
unstable.url = github:nixos/nixpkgs/nixos-unstable;
nur.url = github:nix-community/NUR;
utils.url = "/home/gytis/Projects/flake-utils-plus";
home-manager = {
url = github:nix-community/home-manager/master;
inputs.nixpkgs.follows = "nixpkgs";
};
neovim = {
url = github:neovim/neovim?dir=contrib;
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs@{ self, nixpkgs, unstable, nur, utils, home-manager, neovim }:
let
pkgs = self.pkgs.nixpkgs;
in
utils.lib.systemFlake {
inherit self inputs utils;
defaultSystem = "xyz"; # Specifies default `pkgs.<name>.system` defaults to "x86_64-linux"
pkgs.nixpkgs = {
#overlays = []; # TODO:
#patches = []; # TODO:
system = "xyz"; # Overwrites `defaultSystem`
input = nixpkgs; # Sources to import
config = { # Overwrites `pkgsConfig`
allowUnfree = false;
};
};
# Unstable packages
pkgs.unstable.input = unstable;
pkgsConfig = { # Default configuration values for `pkgs.<name>.config = {...}`
allowBroken = true;
allowUnfree = true;
};
nixosProfiles = { # Profiles, gets parsed into `nixosConfigurations`
Morty = { # System hostname
nixpkgs = self.pkgs.unstable; # Defaults to `self.pkgs.nixpkgs`
extraArgs = { # Globally available argumets
abc = 123;
};
modules = [ # Host specific configuration. Same as `sharedModules`
(import ./configurations/Morty.host.nix)
];
};
};
sharedOverlays = [ # Overlays, gets applied to all `pkgs.<name>.input`
self.overlays # Overlay imported from `./overlays`
nur.overlay # Nix User Repository overlay
(final: prev: { # Overlay function
neovim-nightly = neovim.defaultPackage.${pkgs.system};
})
];
sharedModules = [ # Shared modules/configurations between `nixProfiles`
home-manager.nixosModules.home-manager
(import ./modules)
{
nix = utils.lib.nixDefaultsFromInputs inputs; # Sets sane `nix.nixPath` `nix.registry` `nix.extraOptions`. Please refer to implementation for more details.
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
}
];
# All other values gets passed down to the flake
overlay = import ./overlays;
abc = 132;
# etc
};
}

26
flake.nix Normal file
View File

@ -0,0 +1,26 @@
{
description = "Pure Nix flake utility functions";
outputs = { self }: {
lib =
let
mapAttrsToList = f: attrs:
map (name: f name attrs.${name}) (builtins.attrNames attrs);
in
rec {
systemFlake = import ./systemFlake.nix { };
nixPathFromInputs = inputs: mapAttrsToList (name: _: "${name}=${inputs.${name}}") inputs;
nixRegistryFromInputs = inputs: builtins.mapAttrs (name: v: { flake = v; }) inputs;
nixDefaultsFromInputs = inputs: {
extraOptions = "experimental-features = nix-command flakes";
nixPath = nixPathFromInputs inputs;
registry = nixRegistryFromInputs inputs;
};
};
};
}

65
systemFlake.nix Normal file
View File

@ -0,0 +1,65 @@
{}:
{ self
, inputs
, defaultSystem ? "x86_64-linux"
, nixosProfiles ? { }
, pkgs ? { }
, pkgsConfig ? { }
, sharedModules ? [ ]
, sharedOverlays ? [ ]
, extraArgs ? { inherit inputs; }
, ...
}@args:
let
otherArguments = builtins.removeAttrs args [
"defaultSystem"
"extraArgs"
"inputs"
"nixosProfiles"
"pkgs"
"pkgsConfig"
"self"
"sharedModules"
"sharedOverlays"
];
in
otherArguments //
{
pkgs = builtins.mapAttrs
(name: value: import value.input {
system = (if (value ? system) then value.system else defaultSystem);
overlays = sharedOverlays;
config = pkgsConfig // (if (value ? config) then value.config else { });
})
pkgs;
nixosConfigurations = builtins.mapAttrs
(name: value:
let
selectedNixpkgs = if (value ? nixpkgs) then value.nixpkgs else self.pkgs.nixpkgs;
in
inputs.nixpkgs.lib.nixosSystem (
with selectedNixpkgs.lib;
{
system = selectedNixpkgs.system;
modules = [
{
networking.hostName = name;
nixpkgs = rec { pkgs = selectedNixpkgs; config = pkgs.config; };
system.configurationRevision = mkIf (self ? rev) self.rev;
nix.package = mkDefault selectedNixpkgs.nixFlakes;
}
]
++ sharedModules
++ (optionals (value ? modules) value.modules);
extraArgs = extraArgs // optionalAttrs (value ? extraArgs) value.extraArgs;
}
))
nixosProfiles;
}