mirror of
https://codeberg.org/leana8959/.files.git
synced 2026-02-01 22:49:41 +00:00
Compare commits
No commits in common. "acf4bba56dffcf839a5bb39188dbe6d0cad47efb" and "d5e4545bb2dcb99f84c181385d3934ed711dc9df" have entirely different histories.
acf4bba56d
...
d5e4545bb2
8 changed files with 42 additions and 145 deletions
34
Justfile
Normal file
34
Justfile
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
# Note:
|
||||||
|
# add `--option substitute false` and or `--no-net` to the command so it builds properly offline
|
||||||
|
os host action:
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
nixpkgs=$(nix-instantiate --eval -E "let sources = import ./npins; in sources.nixpkgs.outPath" | jq -r .)
|
||||||
|
nixos-rebuild {{ action }} \
|
||||||
|
-I nixpkgs=${nixpkgs} \
|
||||||
|
-I nixos-config=./nix/configurations/{{ host }}.nix \
|
||||||
|
--no-reexec \
|
||||||
|
--file ./default.nix \
|
||||||
|
--attr "nixosConfigurations.{{ host }}"
|
||||||
|
|
||||||
|
install host:
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
nixpkgs=$(nix-instantiate --eval -E "let sources = import ./npins; in sources.nixpkgs.outPath" | jq -r .)
|
||||||
|
nixos-install \
|
||||||
|
-I nixpkgs=${nixpkgs} \
|
||||||
|
-I nixos-config=./nix/configurations/{{ host }}.nix \
|
||||||
|
--file ./default.nix \
|
||||||
|
--attr "nixosConfigurations.{{ host }}"
|
||||||
|
|
||||||
|
# Retain four weeks of generations so I don't fuck up
|
||||||
|
clean-os:
|
||||||
|
nix-env --delete-generations 28d -p /nix/var/nix/profiles/system
|
||||||
|
|
||||||
|
clean-hm:
|
||||||
|
nix-env --delete-generations 28d -p ~/.local/state/nix/profiles/home-manager
|
||||||
|
|
||||||
|
update:
|
||||||
|
npins update
|
||||||
|
|
@ -56,7 +56,6 @@ in
|
||||||
|
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
pkgs.disko
|
pkgs.disko
|
||||||
pkgs.manage
|
|
||||||
pkgs.git
|
pkgs.git
|
||||||
pkgs.pastebinit # for sharing cli output & debugging
|
pkgs.pastebinit # for sharing cli output & debugging
|
||||||
pkgs.hdparm # to ATA secure wipe disks
|
pkgs.hdparm # to ATA secure wipe disks
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
haskellPackages,
|
|
||||||
haskell,
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
inherit (haskell.lib.compose) justStaticExecutables;
|
|
||||||
|
|
||||||
drv = haskellPackages.callCabal2nix "manage" ./src { };
|
|
||||||
in
|
|
||||||
justStaticExecutables drv
|
|
||||||
1
nix/packages/by-name/manage/src/.gitignore
vendored
1
nix/packages/by-name/manage/src/.gitignore
vendored
|
|
@ -1 +0,0 @@
|
||||||
dist-newstyle/
|
|
||||||
|
|
@ -1,104 +0,0 @@
|
||||||
#!/usr/bin/env runhaskell
|
|
||||||
{-# LANGUAGE LambdaCase #-}
|
|
||||||
{-# LANGUAGE ViewPatterns #-}
|
|
||||||
|
|
||||||
import Control.Monad
|
|
||||||
import System.Environment
|
|
||||||
import System.Exit
|
|
||||||
import System.IO
|
|
||||||
import System.Process
|
|
||||||
|
|
||||||
-- Note: to type check this code
|
|
||||||
-- `ghc manage.hs -Werror=all -fno-code'
|
|
||||||
|
|
||||||
main :: IO ()
|
|
||||||
main = do
|
|
||||||
let showHelpOr args elseDo =
|
|
||||||
if "--help" `elem` args then putStr help
|
|
||||||
else elseDo
|
|
||||||
|
|
||||||
getArgs >>= \case
|
|
||||||
( "os" : host : action
|
|
||||||
: (partitionArgs -> (manageArgs, extraArgs))
|
|
||||||
) ->
|
|
||||||
manageArgs `showHelpOr` do
|
|
||||||
nixpkgs <- readNixpkgsPath
|
|
||||||
void $ readProcessFriendly "nixos-rebuild" (action : nixosRebuildArgs nixpkgs host <> extraArgs)
|
|
||||||
|
|
||||||
( "install" : host
|
|
||||||
: (partitionArgs -> (manageArgs, extraArgs))
|
|
||||||
) ->
|
|
||||||
manageArgs `showHelpOr` do
|
|
||||||
nixpkgs <- readNixpkgsPath
|
|
||||||
void $ readProcessFriendly "nixos-install" (nixosInstallArgs nixpkgs host <> extraArgs)
|
|
||||||
|
|
||||||
_ -> putStr help >> exitFailure
|
|
||||||
|
|
||||||
newtype StorePath = StorePath { unStorePath :: String }
|
|
||||||
|
|
||||||
defaultNixosCmdArgs :: StorePath -> String -> [String]
|
|
||||||
defaultNixosCmdArgs (unStorePath -> nixpkgsPath) hostname =
|
|
||||||
[ "-I", "nixpkgs=" <> nixpkgsPath
|
|
||||||
, "-I", "nixos-config=./nix/configurations/" <> hostname <> ".nix"
|
|
||||||
, "--file", "./default.nix"
|
|
||||||
, "--attr", "nixosConfigurations." <> hostname
|
|
||||||
]
|
|
||||||
|
|
||||||
nixosInstallArgs :: StorePath -> String -> [String]
|
|
||||||
nixosInstallArgs = defaultNixosCmdArgs
|
|
||||||
|
|
||||||
nixosRebuildArgs :: StorePath -> String -> [String]
|
|
||||||
nixosRebuildArgs =
|
|
||||||
defaultNixosCmdArgs
|
|
||||||
-- This is not a nixos-install flag
|
|
||||||
<> (\_ _ -> ["--no-reexec"])
|
|
||||||
|
|
||||||
help :: String
|
|
||||||
help =
|
|
||||||
unlines
|
|
||||||
[ "Manage.hs"
|
|
||||||
, ""
|
|
||||||
, "Manage.hs is a thin wrapper to make nixos-{install,rebuild} easier to use."
|
|
||||||
, "Black lives matter. Trans rights are human rights. No nazi bullsh*t."
|
|
||||||
, ""
|
|
||||||
, "Available commands:"
|
|
||||||
, indent "os <hostname> <action>:" <> indent "run perhost action with nixos-rebuild"
|
|
||||||
, indent "install <hostname>:" <> indent "run perhost action with nixos-install"
|
|
||||||
, indent "--help:" <> indent "show this help menu"
|
|
||||||
]
|
|
||||||
where indent = ("\t" <>)
|
|
||||||
|
|
||||||
partitionArgs :: [String] -> ([String], [String])
|
|
||||||
partitionArgs = finalize . span (/= "--")
|
|
||||||
where finalize (xs, ys) = (xs, drop 1 ys)
|
|
||||||
|
|
||||||
quote :: String -> String
|
|
||||||
quote x = "\"" <> x <> "\""
|
|
||||||
|
|
||||||
-- https://stackoverflow.com/a/70162369
|
|
||||||
blueForeground :: String -> String
|
|
||||||
blueForeground x = "\ESC[34m" <> x <> "\ESC[0m"
|
|
||||||
|
|
||||||
readProcessFriendly :: String -> [String] -> IO String
|
|
||||||
readProcessFriendly cmdName args = do
|
|
||||||
hPutStrLn stderr
|
|
||||||
$ "Executing: " <> (quote . blueForeground) (showCommandForUser cmdName args)
|
|
||||||
(_, _, _, pid) <- createProcess
|
|
||||||
( proc cmdName args
|
|
||||||
) { std_in = UseHandle stdin
|
|
||||||
, std_out = UseHandle stdout
|
|
||||||
, std_err = UseHandle stderr
|
|
||||||
}
|
|
||||||
_ <- waitForProcess pid
|
|
||||||
pure ""
|
|
||||||
|
|
||||||
readNixpkgsPath :: IO StorePath
|
|
||||||
readNixpkgsPath =
|
|
||||||
StorePath . clean <$> readProcessFriendly
|
|
||||||
"nix-instantiate"
|
|
||||||
[ "--eval"
|
|
||||||
, "-E"
|
|
||||||
, "let sources = import ./npins; in sources.nixpkgs.outPath"
|
|
||||||
]
|
|
||||||
where
|
|
||||||
clean = filter (\c -> c /= '\n' && c /= '"')
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
cabal-version: 3.0
|
|
||||||
name: manage
|
|
||||||
version: 0.1.0.0
|
|
||||||
description: NixOS Helper
|
|
||||||
author: Léana 江
|
|
||||||
maintainer: leana.jiang+git@icloud.com
|
|
||||||
build-type: Simple
|
|
||||||
|
|
||||||
common common
|
|
||||||
ghc-options:
|
|
||||||
-Wall -Wcompat -Widentities -Wincomplete-record-updates
|
|
||||||
-Wincomplete-patterns -Wincomplete-uni-patterns
|
|
||||||
-Wredundant-constraints -Werror=missing-fields
|
|
||||||
build-depends: base
|
|
||||||
default-language: Haskell2010
|
|
||||||
|
|
||||||
executable manage
|
|
||||||
import: common
|
|
||||||
main-is: ./Main.hs
|
|
||||||
build-depends:
|
|
||||||
process
|
|
||||||
|
|
@ -182,11 +182,11 @@
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs"
|
"repo": "nixpkgs"
|
||||||
},
|
},
|
||||||
"branch": "nixos-25.11",
|
"branch": "nixos-25.11-small",
|
||||||
"submodules": false,
|
"submodules": false,
|
||||||
"revision": "fa83fd837f3098e3e678e6cf017b2b36102c7211",
|
"revision": "6c1fc6e4c93c084d0ae654ee85dc16cfe53b12b0",
|
||||||
"url": "https://github.com/nixos/nixpkgs/archive/fa83fd837f3098e3e678e6cf017b2b36102c7211.tar.gz",
|
"url": "https://github.com/nixos/nixpkgs/archive/6c1fc6e4c93c084d0ae654ee85dc16cfe53b12b0.tar.gz",
|
||||||
"hash": "sha256-e7VO/kGLgRMbWtpBqdWl0uFg8Y2XWFMdz0uUJvlML8o="
|
"hash": "sha256-3tAkeUYt7WBVgNfaXDW6HnrrGSuZooZ8nIAnbmKsY2A="
|
||||||
},
|
},
|
||||||
"npins": {
|
"npins": {
|
||||||
"type": "GitRelease",
|
"type": "GitRelease",
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ in
|
||||||
overlays = map import [
|
overlays = map import [
|
||||||
./nix/overlays/disko.nix
|
./nix/overlays/disko.nix
|
||||||
./nix/overlays/npins.nix
|
./nix/overlays/npins.nix
|
||||||
./nix/packages/overlay.nix
|
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
withGHC ? false,
|
withGHC ? false,
|
||||||
|
|
@ -18,10 +17,11 @@ pkgs.mkShell {
|
||||||
packages =
|
packages =
|
||||||
with pkgs;
|
with pkgs;
|
||||||
[
|
[
|
||||||
npins # from npins repo
|
just
|
||||||
disko # from disko flake
|
jq
|
||||||
manage
|
npins
|
||||||
nixos-anywhere # comes from nixpkgs
|
nixos-anywhere # comes from nixpkgs
|
||||||
|
disko # comes from disko flake
|
||||||
]
|
]
|
||||||
++ lib.optionals withGHC [
|
++ lib.optionals withGHC [
|
||||||
(haskellPackages.ghcWithPackages (self: [
|
(haskellPackages.ghcWithPackages (self: [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue