1
Fork 0

feat: initial config

This commit is contained in:
Matei Adriel 2020-04-08 19:36:58 +03:00
commit df5ce78519
16 changed files with 412 additions and 0 deletions

18
default.nix Normal file
View file

@ -0,0 +1,18 @@
{ ... }:
let sources = import ./nix/sources.nix;
in {
imports = [ "${sources.home-manager}/nixos" ./modules ];
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
# Enable the OpenSSH daemon.
services.openssh.enable = true;
# Enable sound.
sound.enable = true;
hardware.pulseaudio.enable = true;
system.stateVersion = "19.09";
}

View file

@ -0,0 +1 @@
{ ... }: { imports = [ ./misc.nix ./locale.nix ./git ]; }

View file

@ -0,0 +1,39 @@
# Most of these are copied from: https://github.com/Brettm12345/nixos-config/blob/1400c71bce/modules/applications/git/aliases.nix
let
git = text: ''"!git ${text}"'';
f = text: ''"!f(){ ${text} };f"'';
in {
# Unstage all changes
unstage = "reset HEAD --";
# Ammend to the last commit
amend = "commit --amend -C HEAD";
# List branches sorted by last modified
b = git
"for-each-ref --sort='-authordate' --format='%(authordate)%09%(objectname:short)%09%(refname)' refs/heads | sed -e 's-refs/heads/--'";
# Test merge for conflicts before merging
mergetest = f ''
git merge --no-commit --no-ff "$1"; git merge --abort; echo "Merge aborted";'';
# Get description of current repo
description = git
''config --get "branch.$(git rev-parse --abbrev-ref HEAD).description"'';
# Show authors
authors = ''
"!f() { git log --no-merges --pretty='format:%<(26)%an <%ae>' --author "$*" | sort | uniq# }# f"'';
a = "add";
cm = "commit --message";
caa = "commit --ammend";
cl = "clone";
co = "checkout";
col = "checkout @{-1}";
cob = "checkout -b";
st = "stash";
pop = "stash pop";
t = "tag";
}

View file

@ -0,0 +1,20 @@
{ pkgs, ... }: {
home-manager.users.adrielus = {
home.packages = with pkgs.gitAndTools; [ hub ];
programs.git = {
enable = true;
userName = "Matei Adriel";
userEmail = "rafaeladriel11@gmail.com";
aliases = import ./aliases.nix;
extraConfig = {
github.user = "Mateiadrielrafael";
hub.protocol = "ssh";
rebase.autoStash = true;
};
};
};
}

View file

@ -0,0 +1,9 @@
{ ... }: {
i18n = {
consoleFont = "Lat2-Terminus16";
consoleKeyMap = "us";
defaultLocale = "en_US.UTF-8";
};
time.timeZone = "Europe/Bucharest";
}

View file

@ -0,0 +1,11 @@
{ pkgs, ... }: {
environment.systemPackages = with pkgs; [
# Tool to allow hashing passwords from the cmd
mkpasswd
vscodium
google-chrome
discord
git
];
}

10
modules/default.nix Normal file
View file

@ -0,0 +1,10 @@
{ ... }: {
imports = [
./dev
./applications
./network.nix
./xserver.nix
./users.nix
./overlay.nix
];
}

1
modules/dev/default.nix Normal file
View file

@ -0,0 +1 @@
{ ... }: { imports = [ ./nix.nix ]; }

3
modules/dev/nix.nix Normal file
View file

@ -0,0 +1,3 @@
{ pkgs, ... }: {
environment.systemPackages = with pkgs; [ nixfmt niv cached-nix-shell ];
}

13
modules/network.nix Normal file
View file

@ -0,0 +1,13 @@
{ ... }: {
networking = {
networkmanager.enable = true;
hostName = "nixos";
# The global useDHCP flag is deprecated, therefore explicitly set to false here.
# Per-interface useDHCP will be mandatory in the future, so this generated config
# replicates the default behaviour.
useDHCP = false;
interfaces.enp1s0.useDHCP = true;
interfaces.wlp0s20f3.useDHCP = true;
};
}

28
modules/overlay.nix Normal file
View file

@ -0,0 +1,28 @@
{ ... }:
let imports = import ../nix/sources.nix;
in {
nixpkgs.overlays = [
(self: super:
with self; rec {
inherit imports;
cached-nix-shell = callPackage imports.cached-nix-shell { };
inherit (import imports.niv { }) niv;
inherit (import imports.all-hies { }) all-hies;
})
];
# allow packages with unfree licenses
nixpkgs.config.allowUnfree = true;
nix = {
trustedUsers = [ "root" "adrielus" "@wheel" ];
autoOptimiseStore = true;
gc.automatic = true;
optimise.automatic = true;
binaryCaches = [ "https://cache.nixos.org" "https://all-hies.cachix.org" ];
binaryCachePublicKeys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"all-hies.cachix.org-1:JjrzAOEUsD9ZMt8fdFbzo3jNAyEWlPAwdVuHw4RD43k="
];
};
}

11
modules/users.nix Normal file
View file

@ -0,0 +1,11 @@
{ ... }: {
users = {
mutableUsers = false;
users.adrielus = {
isNormalUser = true;
extraGroups = [ "wheel" "networkmanager" ];
hashedPassword =
"$6$5NX9cuUbX$yjiBbroplRLanLfJ5wNjjsd9rSvN81BCNEnuF2DUgfMa/TPYdl5PUYcWF52VxNbisDPsR2Q5EhgNrgALatpT3/";
};
};
}

23
modules/xserver.nix Normal file
View file

@ -0,0 +1,23 @@
{ ... }: {
services.xserver = {
# Enable the X11 windowing system.
enable = true;
layout = "us";
xkbOptions = "eurosign:e";
# Enable the KDE Desktop Environment.
displayManager.sddm.enable = true;
desktopManager.plasma5.enable = true;
libinput = {
# Enable touchpad support.
enable = true;
naturalScrolling = true;
accelSpeed = "2.5";
# who thought letting this be true by default was a good idea
tappingDragLock = false;
};
};
}

86
nix/sources.json Normal file
View file

@ -0,0 +1,86 @@
{
"NUR": {
"branch": "master",
"description": "Nix User Repository: User contributed nix packages [maintainer=@Mic92]",
"homepage": "",
"owner": "nix-community",
"repo": "NUR",
"rev": "d28e8f7d40e2683d57589f8ffa7568bdf89d316f",
"sha256": "0pfafab0bfs4zcld41awamwz6wn3snw1p9h2aid6pgxkbrm9r5sx",
"type": "tarball",
"url": "https://github.com/nix-community/NUR/archive/d28e8f7d40e2683d57589f8ffa7568bdf89d316f.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"all-hies": {
"branch": "master",
"description": "Cached Haskell IDE Engine Nix builds for all GHC versions",
"homepage": "",
"owner": "Infinisil",
"repo": "all-hies",
"rev": "4b6aab017cdf96a90641dc287437685675d598da",
"sha256": "0ap12mbzk97zmxk42fk8vqacyvpxk29r2wrnjqpx4m2w9g7gfdya",
"type": "tarball",
"url": "https://github.com/Infinisil/all-hies/archive/4b6aab017cdf96a90641dc287437685675d598da.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"cached-nix-shell": {
"branch": "master",
"description": "Instant startup time for nix-shell",
"homepage": "",
"owner": "xzfc",
"repo": "cached-nix-shell",
"rev": "94e4eb97aa84e1e9c4ecb5ebe2b08b9da22df2a2",
"sha256": "0pzwknpc4qrh9pv5z0xvldql2dkj9ddksvaci86a4f8cnd86p2l6",
"type": "tarball",
"url": "https://github.com/xzfc/cached-nix-shell/archive/94e4eb97aa84e1e9c4ecb5ebe2b08b9da22df2a2.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"easy-purescript-nix": {
"branch": "master",
"description": "Easy PureScript (and other tools) with Nix",
"homepage": "",
"owner": "justinwoo",
"repo": "easy-purescript-nix",
"rev": "aa3e608608232f4a009b5c132ae763fdabfb4aba",
"sha256": "0y6jikncxs9l2zgngbd1775f1zy5s1hdc5rhkyzsyaalcl5cajk8",
"type": "tarball",
"url": "https://github.com/justinwoo/easy-purescript-nix/archive/aa3e608608232f4a009b5c132ae763fdabfb4aba.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"home-manager": {
"branch": "release-19.09",
"description": "Manage a user environment using Nix",
"homepage": "https://rycee.gitlab.io/home-manager/",
"owner": "rycee",
"repo": "home-manager",
"rev": "0d1ca254d0f213a118459c5be8ae465018132f74",
"sha256": "0sw8lw825gg04h6js42bvackgydi5m0xsjvnb5gxlqv45qw8rxjq",
"type": "tarball",
"url": "https://github.com/rycee/home-manager/archive/0d1ca254d0f213a118459c5be8ae465018132f74.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"niv": {
"branch": "master",
"description": "Easy dependency management for Nix projects",
"homepage": "https://github.com/nmattia/niv",
"owner": "nmattia",
"repo": "niv",
"rev": "f73bf8d584148677b01859677a63191c31911eae",
"sha256": "0jlmrx633jvqrqlyhlzpvdrnim128gc81q5psz2lpp2af8p8q9qs",
"type": "tarball",
"url": "https://github.com/nmattia/niv/archive/f73bf8d584148677b01859677a63191c31911eae.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs": {
"branch": "nixos-19.09",
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
"homepage": "https://github.com/NixOS/nixpkgs",
"owner": "NixOS",
"repo": "nixpkgs-channels",
"rev": "e10c65cdb35b6a66491e47e5a85f5d456b4f4eea",
"sha256": "19csb2s3wyav83zcw9dw488zk2fnz6wcxxz8q6hy43dbph86hxwm",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs-channels/archive/e10c65cdb35b6a66491e47e5a85f5d456b4f4eea.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}

138
nix/sources.nix Normal file
View file

@ -0,0 +1,138 @@
# This file has been generated by Niv.
let
#
# The fetchers. fetch_<type> fetches specs of type <type>.
#
fetch_file = pkgs: spec:
if spec.builtin or true then
builtins_fetchurl { inherit (spec) url sha256; }
else
pkgs.fetchurl { inherit (spec) url sha256; };
fetch_tarball = pkgs: name: spec:
let
ok = str: ! builtins.isNull (builtins.match "[a-zA-Z0-9+-._?=]" str);
# sanitize the name, though nix will still fail if name starts with period
name' = stringAsChars (x: if ! ok x then "-" else x) "${name}-src";
in
if spec.builtin or true then
builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
else
pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
fetch_git = spec:
builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; };
fetch_local = spec: spec.path;
fetch_builtin-tarball = name: throw
''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`.
$ niv modify ${name} -a type=tarball -a builtin=true'';
fetch_builtin-url = name: throw
''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`.
$ niv modify ${name} -a type=file -a builtin=true'';
#
# Various helpers
#
# The set of packages used when specs are fetched using non-builtins.
mkPkgs = sources:
let
sourcesNixpkgs =
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {};
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
in
if builtins.hasAttr "nixpkgs" sources
then sourcesNixpkgs
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
import <nixpkgs> {}
else
abort
''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json.
'';
# The actual fetching function.
fetch = pkgs: name: spec:
if ! builtins.hasAttr "type" spec then
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
else if spec.type == "file" then fetch_file pkgs spec
else if spec.type == "tarball" then fetch_tarball pkgs name spec
else if spec.type == "git" then fetch_git spec
else if spec.type == "local" then fetch_local spec
else if spec.type == "builtin-tarball" then fetch_builtin-tarball name
else if spec.type == "builtin-url" then fetch_builtin-url name
else
abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
# Ports of functions for older nix versions
# a Nix version of mapAttrs if the built-in doesn't exist
mapAttrs = builtins.mapAttrs or (
f: set: with builtins;
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
);
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1);
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
concatStrings = builtins.concatStringsSep "";
# fetchTarball version that is compatible between all the versions of Nix
builtins_fetchTarball = { url, name, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchTarball;
in
if lessThan nixVersion "1.12" then
fetchTarball { inherit name url; }
else
fetchTarball attrs;
# fetchurl version that is compatible between all the versions of Nix
builtins_fetchurl = { url, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchurl;
in
if lessThan nixVersion "1.12" then
fetchurl { inherit url; }
else
fetchurl attrs;
# Create the final "sources" from the config
mkSources = config:
mapAttrs (
name: spec:
if builtins.hasAttr "outPath" spec
then abort
"The values in sources.json should not have an 'outPath' attribute"
else
spec // { outPath = fetch config.pkgs name spec; }
) config.sources;
# The "config" used by the fetchers
mkConfig =
{ sourcesFile ? ./sources.json
, sources ? builtins.fromJSON (builtins.readFile sourcesFile)
, pkgs ? mkPkgs sources
}: rec {
# The sources, i.e. the attribute set of spec name to spec
inherit sources;
# The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
inherit pkgs;
};
in
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }

1
options.nix Normal file
View file

@ -0,0 +1 @@
{ ... }: { imports = [ <home-manager/nixos> ]; }